From de9ac172c44756ab7b1684f8a2fffcc601bcd6a4 Mon Sep 17 00:00:00 2001 From: Ayaz Abbas Date: Tue, 6 Aug 2024 15:50:24 +0100 Subject: [PATCH 1/2] allow duplicate symbols for artificial scaling --- example_publisher/publisher.py | 12 +++++++----- example_publisher/pythd.py | 1 + pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/example_publisher/publisher.py b/example_publisher/publisher.py index 64c2e68..1b4ceb8 100644 --- a/example_publisher/publisher.py +++ b/example_publisher/publisher.py @@ -17,6 +17,7 @@ @define class Product: + generic_symbol: str symbol: str product_account: str price_account: str @@ -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, diff --git a/example_publisher/pythd.py b/example_publisher/pythd.py index 930899b..eaaed83 100644 --- a/example_publisher/pythd.py +++ b/example_publisher/pythd.py @@ -24,6 +24,7 @@ class Price(DataClassJsonMixin): @dataclass class Metadata(DataClassJsonMixin): symbol: str + generic_symbol: str @dataclass diff --git a/pyproject.toml b/pyproject.toml index 020b722..51c1a47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "example-publisher" -version = "1.1.1" +version = "1.1.2" description = "" authors = [] license = "Apache-2" From 75704047cb9ab4d8fc51f4fad4eea6bc190bf573 Mon Sep 17 00:00:00 2001 From: Ayaz Abbas Date: Tue, 6 Aug 2024 17:58:50 +0100 Subject: [PATCH 2/2] formatting --- example_publisher/publisher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example_publisher/publisher.py b/example_publisher/publisher.py index 1b4ceb8..a0bb7f9 100644 --- a/example_publisher/publisher.py +++ b/example_publisher/publisher.py @@ -87,7 +87,9 @@ async def _upd_products(self): } log.debug("fetched product accounts from Pythd", products=pythd_products) - old_products_by_generic_symbol = {product.generic_symbol: product for product in self.products} + old_products_by_generic_symbol = { + product.generic_symbol: product for product in self.products + } self.products = []