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.
account_tests
Tyler Goodlet 2023-07-15 17:37:56 -04:00
parent d794afcb5c
commit a5821ae9b1
3 changed files with 24 additions and 2 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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