Skip to content

Commit

Permalink
allow duplicate symbols for artificial scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazabbas committed Aug 6, 2024
1 parent b359c04 commit de9ac17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions example_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@define
class Product:
generic_symbol: str
symbol: str
product_account: str
price_account: str
Expand Down Expand Up @@ -81,26 +82,27 @@ async def _start_product_update_loop(self):
async def _upd_products(self):
log.debug("fetching product accounts from Pythd")
pythd_products = {
product.metadata.symbol: product
product.metadata.generic_symbol: product
for product in await self.pythd.all_products()
}
log.debug("fetched product accounts from Pythd", products=pythd_products)

old_products_by_symbol = {product.symbol: product for product in self.products}
old_products_by_generic_symbol = {product.generic_symbol: product for product in self.products}

self.products = []

for symbol, product in pythd_products.items():
for generic_symbol, product in pythd_products.items():
if not product.prices:
continue

subscription_id = None
if old_product := old_products_by_symbol.get(symbol):
if old_product := old_products_by_generic_symbol.get(generic_symbol):
subscription_id = old_product.subscription_id

self.products.append(
Product(
symbol,
generic_symbol,
product.metadata.symbol,
product.account,
product.prices[0].account,
product.prices[0].exponent,
Expand Down
1 change: 1 addition & 0 deletions example_publisher/pythd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Price(DataClassJsonMixin):
@dataclass
class Metadata(DataClassJsonMixin):
symbol: str
generic_symbol: str


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "example-publisher"
version = "1.1.1"
version = "1.1.2"
description = ""
authors = []
license = "Apache-2"
Expand Down

0 comments on commit de9ac17

Please sign in to comment.