`binance.get_mkt_info()`: bleh, right `@lru_cache` dun work for async..
parent
4b7ac1d895
commit
83f1922f6e
|
@ -23,7 +23,7 @@ Binance backend
|
||||||
"""
|
"""
|
||||||
from contextlib import asynccontextmanager as acm
|
from contextlib import asynccontextmanager as acm
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import lru_cache
|
# from functools import lru_cache
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Union, Optional,
|
Any, Union, Optional,
|
||||||
|
@ -335,7 +335,7 @@ class Client:
|
||||||
@acm
|
@acm
|
||||||
async def get_client() -> Client:
|
async def get_client() -> Client:
|
||||||
client = Client()
|
client = Client()
|
||||||
log.info(f'Caching exchange infos..')
|
log.info('Caching exchange infos..')
|
||||||
await client.exch_info()
|
await client.exch_info()
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
@ -371,7 +371,13 @@ async def stream_messages(
|
||||||
timeouts += 1
|
timeouts += 1
|
||||||
if timeouts > 2:
|
if timeouts > 2:
|
||||||
log.error("binance feed seems down and slow af? rebooting...")
|
log.error("binance feed seems down and slow af? rebooting...")
|
||||||
await ws._connect()
|
try:
|
||||||
|
await ws._connect()
|
||||||
|
except BaseException as err:
|
||||||
|
assert err
|
||||||
|
# Wut in the f#@$% is going on here.
|
||||||
|
with trio.CancelScope(shield=True):
|
||||||
|
await tractor.breakpoint()
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -476,12 +482,20 @@ async def open_history_client(
|
||||||
yield get_ohlc, {'erlangs': 3, 'rate': 3}
|
yield get_ohlc, {'erlangs': 3, 'rate': 3}
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
# TODO: bleh, didn't we have an async version of
|
||||||
|
# this at some point?
|
||||||
|
# @lru_cache
|
||||||
async def get_mkt_info(
|
async def get_mkt_info(
|
||||||
fqme: str,
|
fqme: str,
|
||||||
|
|
||||||
|
_cache: dict[str, MktPair] = {}
|
||||||
|
|
||||||
) -> tuple[MktPair, Pair]:
|
) -> tuple[MktPair, Pair]:
|
||||||
|
|
||||||
|
both = _cache.get(fqme)
|
||||||
|
if both:
|
||||||
|
return both
|
||||||
|
|
||||||
async with open_cached_client('binance') as client:
|
async with open_cached_client('binance') as client:
|
||||||
|
|
||||||
pair: Pair = await client.exch_info(fqme.upper())
|
pair: Pair = await client.exch_info(fqme.upper())
|
||||||
|
@ -501,7 +515,9 @@ async def get_mkt_info(
|
||||||
bs_mktid=pair.symbol,
|
bs_mktid=pair.symbol,
|
||||||
broker='binance',
|
broker='binance',
|
||||||
)
|
)
|
||||||
return mkt, pair
|
both = mkt, pair
|
||||||
|
_cache[fqme] = both
|
||||||
|
return both
|
||||||
|
|
||||||
|
|
||||||
async def stream_quotes(
|
async def stream_quotes(
|
||||||
|
|
Loading…
Reference in New Issue