binance: parse .expiry separate from .venue

Apparently they're being massive cucks and changing their futes pair
schema again now adding a `NEXT_QUARTER` contract type which we weren't
handling at all. The good news is falling back to an old symcache file
would have prevented this from crashing.

Add a new `FutesPair.expiry: str` field so that `.bs_fqme` can simply
call it during the summary FQME-ification output rendering..
ib_py311_fixes
Tyler Goodlet 2023-09-22 14:48:50 -04:00
parent 0ba75df877
commit e9887cb611
1 changed files with 50 additions and 9 deletions

View File

@ -194,6 +194,37 @@ class FutesPair(Pair):
def quoteAssetPrecision(self) -> int: def quoteAssetPrecision(self) -> int:
return self.quotePrecision return self.quotePrecision
@property
def expiry(self) -> str:
symbol: str = self.symbol
contype: str = self.contractType
match contype:
case (
'CURRENT_QUARTER'
| 'NEXT_QUARTER' # su madre binance..
):
pair, _, expiry = symbol.partition('_')
assert pair == self.pair # sanity
return f'{expiry}'
case 'PERPETUAL':
return 'PERP'
case '':
subtype: list[str] = self.underlyingSubType
if not subtype:
if self.status == 'PENDING_TRADING':
return 'PENDING'
match subtype:
case ['DEFI']:
return 'PERP'
# XXX: yeah no clue then..
raise ValueError(
f'Bad .expiry token match: {contype} for {symbol}'
)
@property @property
def venue(self) -> str: def venue(self) -> str:
symbol: str = self.symbol symbol: str = self.symbol
@ -202,36 +233,46 @@ class FutesPair(Pair):
match ctype: match ctype:
case 'PERPETUAL': case 'PERPETUAL':
return f'{margin}M.PERP' return f'{margin}M'
case 'CURRENT_QUARTER': case (
'CURRENT_QUARTER'
| 'NEXT_QUARTER' # su madre binance..
):
_, _, expiry = symbol.partition('_') _, _, expiry = symbol.partition('_')
return f'{margin}M.{expiry}' return f'{margin}M'
case '': case '':
subtype: list[str] = self.underlyingSubType subtype: list[str] = self.underlyingSubType
if not subtype: if not subtype:
if self.status == 'PENDING_TRADING': if self.status == 'PENDING_TRADING':
return f'{margin}M.PENDING' return f'{margin}M'
match subtype: match subtype:
case ['DEFI']: case ['DEFI']:
return f'{subtype[0]}.PERP' return f'{subtype[0]}'
# XXX: yeah no clue then.. # XXX: yeah no clue then..
return 'WTF.PWNED.BBQ' raise ValueError(
f'Bad .venue token match: {ctype}'
)
@property @property
def bs_fqme(self) -> str: def bs_fqme(self) -> str:
symbol: str = self.symbol symbol: str = self.symbol
ctype: str = self.contractType ctype: str = self.contractType
venue: str = self.venue venue: str = self.venue
pair: str = self.pair
match ctype: match ctype:
case 'CURRENT_QUARTER': case (
symbol, _, expiry = symbol.partition('_') 'CURRENT_QUARTER'
| 'NEXT_QUARTER' # su madre binance..
):
pair, _, expiry = symbol.partition('_')
assert pair == self.pair
return f'{symbol}.{venue}' return f'{pair}.{venue}.{self.expiry}'
@property @property
def bs_src_asset(self) -> str: def bs_src_asset(self) -> str: