Skip to content

Commit 0f95b2d

Browse files
authored
allow duplicate symbols for artificial scaling (#30)
* allow duplicate symbols for artificial scaling * formatting
1 parent b359c04 commit 0f95b2d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

example_publisher/publisher.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
@define
1919
class Product:
20+
generic_symbol: str
2021
symbol: str
2122
product_account: str
2223
price_account: str
@@ -81,26 +82,29 @@ async def _start_product_update_loop(self):
8182
async def _upd_products(self):
8283
log.debug("fetching product accounts from Pythd")
8384
pythd_products = {
84-
product.metadata.symbol: product
85+
product.metadata.generic_symbol: product
8586
for product in await self.pythd.all_products()
8687
}
8788
log.debug("fetched product accounts from Pythd", products=pythd_products)
8889

89-
old_products_by_symbol = {product.symbol: product for product in self.products}
90+
old_products_by_generic_symbol = {
91+
product.generic_symbol: product for product in self.products
92+
}
9093

9194
self.products = []
9295

93-
for symbol, product in pythd_products.items():
96+
for generic_symbol, product in pythd_products.items():
9497
if not product.prices:
9598
continue
9699

97100
subscription_id = None
98-
if old_product := old_products_by_symbol.get(symbol):
101+
if old_product := old_products_by_generic_symbol.get(generic_symbol):
99102
subscription_id = old_product.subscription_id
100103

101104
self.products.append(
102105
Product(
103-
symbol,
106+
generic_symbol,
107+
product.metadata.symbol,
104108
product.account,
105109
product.prices[0].account,
106110
product.prices[0].exponent,

example_publisher/pythd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Price(DataClassJsonMixin):
2424
@dataclass
2525
class Metadata(DataClassJsonMixin):
2626
symbol: str
27+
generic_symbol: str
2728

2829

2930
@dataclass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "example-publisher"
3-
version = "1.1.1"
3+
version = "1.1.2"
44
description = ""
55
authors = []
66
license = "Apache-2"

0 commit comments

Comments
 (0)