Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow duplicate symbols for artificial scaling #30

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 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,29 @@ 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
Loading