binance.venues: add pair-type specific asset keying

Add `bs_src/dst_asset: str` properties which provide for unique keying
into futures vs. spot venues by offering a `.venue: str` property which,
for non-spot delivers normally an expiry suffix (eg. '.PERP') and for
spot just delivers the bair chain-token key.

This enables keying multiple venues with the same mkt pairs easily in
a global flat key->pair table needed as part of supporting a symcache.
account_tests
Tyler Goodlet 2023-07-10 11:00:07 -04:00
parent c9681d0aa2
commit 3c84ac326a
1 changed files with 37 additions and 14 deletions

View File

@ -1,8 +1,5 @@
# piker: trading gear for hackers
# Copyright (C)
# Guillermo Rodriguez (aka ze jefe)
# Tyler Goodlet
# (in stewardship for pikers)
# Copyright (C) Tyler Goodlet (in stewardship for pikers)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@ -65,7 +62,7 @@ MarketType = Literal[
'spot',
# 'margin',
'usdtm_futes',
# 'coin_futes',
# 'coinm_futes',
]
@ -144,6 +141,13 @@ class SpotPair(Pair, frozen=True):
def bs_fqme(self) -> str:
return f'{self.symbol}.SPOT'
@property
def bs_src_asset(self) -> str:
return f'{self.quoteAsset}'
@property
def bs_dst_asset(self) -> str:
return f'{self.baseAsset}'
class FutesPair(Pair):
@ -176,32 +180,51 @@ class FutesPair(Pair):
return self.quotePrecision
@property
def bs_fqme(self) -> str:
def venue(self) -> str:
symbol: str = self.symbol
ctype: str = self.contractType
margin: str = self.marginAsset
match ctype:
case 'PERPETUAL':
return f'{symbol}.{margin}M.PERP'
return f'{margin}M.PERP'
case 'CURRENT_QUARTER':
pair, _, expiry = symbol.partition('_')
return f'{pair}.{margin}M.{expiry}'
_, _, expiry = symbol.partition('_')
return f'{margin}M.{expiry}'
case '':
subtype: list[str] = self.underlyingSubType
if not subtype:
if self.status == 'PENDING_TRADING':
return f'{symbol}.{margin}M.PENDING'
return f'{margin}M.PENDING'
match subtype[0]:
case 'DEFI':
return f'{symbol}.{subtype}.PERP'
match subtype:
case ['DEFI']:
return f'{subtype[0]}.PERP'
# XXX: yeah no clue then..
return f'{symbol}.WTF.PWNED.BBQ'
return 'WTF.PWNED.BBQ'
@property
def bs_fqme(self) -> str:
symbol: str = self.symbol
ctype: str = self.contractType
venue: str = self.venue
match ctype:
case 'CURRENT_QUARTER':
symbol, _, expiry = symbol.partition('_')
return f'{symbol}.{venue}'
@property
def bs_src_asset(self) -> str:
return f'{self.quoteAsset}'
@property
def bs_dst_asset(self) -> str:
return f'{self.baseAsset}.{self.venue}'
PAIRTYPES: dict[MarketType, Pair] = {