From 3c84ac326ab959389a1196ff6bf383bf546ada08 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 10 Jul 2023 11:00:07 -0400 Subject: [PATCH] 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. --- piker/brokers/binance/venues.py | 51 ++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/piker/brokers/binance/venues.py b/piker/brokers/binance/venues.py index fe822dd0..08e1f050 100644 --- a/piker/brokers/binance/venues.py +++ b/piker/brokers/binance/venues.py @@ -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] = {