add get_market_info
parent
b4a9b86783
commit
008e68174b
|
@ -130,6 +130,73 @@ async def open_history_client(
|
||||||
yield get_ohlc, {'erlangs': 3, 'rate': 3}
|
yield get_ohlc, {'erlangs': 3, 'rate': 3}
|
||||||
|
|
||||||
|
|
||||||
|
@async_lifo_cache()
|
||||||
|
async def get_mkt_info(
|
||||||
|
fqme: str,
|
||||||
|
|
||||||
|
) -> tuple[MktPair, Pair] | None:
|
||||||
|
|
||||||
|
# uppercase since kraken bs_mktid is always upper
|
||||||
|
if 'deribit' not in fqme.lower():
|
||||||
|
fqme += '.deribit'
|
||||||
|
|
||||||
|
mkt_mode: str = ''
|
||||||
|
broker, mkt_ep, venue, expiry = unpack_fqme(fqme)
|
||||||
|
|
||||||
|
# NOTE: we always upper case all tokens to be consistent with
|
||||||
|
# binance's symbology style for pairs, like `BTCUSDT`, but in
|
||||||
|
# theory we could also just keep things lower case; as long as
|
||||||
|
# we're consistent and the symcache matches whatever this func
|
||||||
|
# returns, always!
|
||||||
|
expiry: str = expiry.upper()
|
||||||
|
venue: str = venue.upper()
|
||||||
|
venue_lower: str = venue.lower()
|
||||||
|
|
||||||
|
mkt_mode: str = 'option'
|
||||||
|
|
||||||
|
async with open_cached_client(
|
||||||
|
'deribit',
|
||||||
|
) as client:
|
||||||
|
|
||||||
|
assets: dict[str, Asset] = await client.get_assets()
|
||||||
|
pair_str: str = mkt_ep.lower()
|
||||||
|
|
||||||
|
# switch venue-mode depending on input pattern parsing
|
||||||
|
# since we want to use a particular endpoint (set) for
|
||||||
|
# pair info lookup!
|
||||||
|
client.mkt_mode = mkt_mode
|
||||||
|
|
||||||
|
pair: Pair = await client.exch_info(
|
||||||
|
sym=pair_str,
|
||||||
|
)
|
||||||
|
dst: Asset | None = assets.get(pair.bs_dst_asset)
|
||||||
|
if (
|
||||||
|
not dst
|
||||||
|
# TODO: a known asset DNE list?
|
||||||
|
# and pair.baseAsset == 'DEFI'
|
||||||
|
):
|
||||||
|
log.warning(
|
||||||
|
f'UNKNOWN {venue} asset {pair.base_currency} from,\n'
|
||||||
|
f'{pformat(pair.to_dict())}'
|
||||||
|
)
|
||||||
|
|
||||||
|
# XXX UNKNOWN missing "asset", though no idea why?
|
||||||
|
# maybe it's only avail in the margin venue(s): /dapi/ ?
|
||||||
|
return None
|
||||||
|
|
||||||
|
mkt = MktPair(
|
||||||
|
dst=dst,
|
||||||
|
src=assets.get(pair.bs_src_asset),
|
||||||
|
price_tick=pair.price_tick,
|
||||||
|
size_tick=pair.size_tick,
|
||||||
|
bs_mktid=pair.symbol,
|
||||||
|
expiry=expiry,
|
||||||
|
venue=venue,
|
||||||
|
broker='deribit',
|
||||||
|
)
|
||||||
|
return mkt, pair
|
||||||
|
|
||||||
|
|
||||||
async def stream_quotes(
|
async def stream_quotes(
|
||||||
|
|
||||||
send_chan: trio.abc.SendChannel,
|
send_chan: trio.abc.SendChannel,
|
||||||
|
|
Loading…
Reference in New Issue