From a5821ae9b1da3f855984df8b9e9abbb1658b129e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 15 Jul 2023 17:37:56 -0400 Subject: [PATCH] binance: spec `.ns_path: str` on pair structs Provides for fully isolated symbology caching in a flat TOML table without special case handling B) Also explicitly define `.bs_mktid: str` which is now used by the symcache to to key-index the backend specific pair set and thus provides for round-trip marshalling without special knowledge of any backend schema. --- piker/brokers/binance/__init__.py | 7 ++++++- piker/brokers/binance/broker.py | 4 +++- piker/brokers/binance/venues.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/piker/brokers/binance/__init__.py b/piker/brokers/binance/__init__.py index fb584468..da63a67c 100644 --- a/piker/brokers/binance/__init__.py +++ b/piker/brokers/binance/__init__.py @@ -33,11 +33,16 @@ from .feed import ( from .broker import ( open_trade_dialog, ) - +from .venues import ( + SpotPair, + FutesPair, +) __all__ = [ 'get_client', 'get_mkt_info', + 'SpotPair', + 'FutesPair', 'open_trade_dialog', 'open_history_client', 'open_symbol_search', diff --git a/piker/brokers/binance/broker.py b/piker/brokers/binance/broker.py index 04042f44..3bc665d6 100644 --- a/piker/brokers/binance/broker.py +++ b/piker/brokers/binance/broker.py @@ -36,7 +36,6 @@ import trio from piker.accounting import ( Asset, - # MktPair, ) from piker.brokers._util import ( get_logger, @@ -232,6 +231,9 @@ async def open_trade_dialog( account_name: str = 'usdtm' use_testnet: bool = False + # TODO: if/when we add .accounting support we need to + # do a open_symcache() call.. though maybe we can hide + # this in a new async version of open_account()? async with open_cached_client('binance') as client: subconf: dict = client.conf[venue_name] use_testnet = subconf.get('use_testnet', False) diff --git a/piker/brokers/binance/venues.py b/piker/brokers/binance/venues.py index 08e1f050..3510d6f6 100644 --- a/piker/brokers/binance/venues.py +++ b/piker/brokers/binance/venues.py @@ -84,6 +84,7 @@ def get_api_eps(venue: MarketType) -> tuple[str, str]: class Pair(Struct, frozen=True, kw_only=True): + symbol: str status: str orderTypes: list[str] @@ -117,6 +118,10 @@ class Pair(Struct, frozen=True, kw_only=True): def bs_fqme(self) -> str: return self.symbol + @property + def bs_mktid(self) -> str: + return f'{self.symbol}.{self.venue}' + class SpotPair(Pair, frozen=True): @@ -137,6 +142,13 @@ class SpotPair(Pair, frozen=True): allowedSelfTradePreventionModes: list[str] permissions: list[str] + # NOTE: see `.data._symcache.SymbologyCache.load()` for why + ns_path: str = 'piker.brokers.binance:SpotPair' + + @property + def venue(self) -> str: + return 'SPOT' + @property def bs_fqme(self) -> str: return f'{self.symbol}.SPOT' @@ -173,6 +185,9 @@ class FutesPair(Pair): underlyingSubType: list[str] # ['PoW'], underlyingType: str # 'COIN' + # NOTE: see `.data._symcache.SymbologyCache.load()` for why + ns_path: str = 'piker.brokers.binance:FutesPair' + # NOTE: for compat with spot pairs and `MktPair.src: Asset` # processing.. @property