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