Remove breaking useless condition for determining if res is list of ohlc values

small_kucoin_fixes
jaredgoldman 2023-03-24 19:56:38 -04:00
parent dcbb7fa64f
commit e2e5191ded
1 changed files with 12 additions and 7 deletions

View File

@ -164,7 +164,7 @@ class Client:
config: BrokerConfig | None = get_config() config: BrokerConfig | None = get_config()
if ( if (
config and config.key_id and config.key_secret and config.key_passphrase config and float(config.key_id) and config.key_secret and config.key_passphrase
): ):
self._authenticated = True self._authenticated = True
self._key_id = config.key_id self._key_id = config.key_id
@ -343,17 +343,19 @@ class Client:
for i in range(10): for i in range(10):
res = await self._request( data = await self._request(
"GET", "GET",
url, url,
api_v="v1", api_v="v1",
) )
if not isinstance(res, list) or not len(bars): if not isinstance(data, list):
# Do a gradual backoff if Kucoin is rate limiting us # Do a gradual backoff if Kucoin is rate limiting us
await trio.sleep(i + (randint(0, 1000) / 1000)) backoff_interval = i + (randint(0, 1000) / 1000)
log.warn(f'History call failed, backing off for {backoff_interval}s')
await trio.sleep(backoff_interval)
else: else:
bars = res bars = data
break break
# Map to OHLC values to dict then to np array # Map to OHLC values to dict then to np array
@ -392,6 +394,8 @@ class Client:
def fqsn_to_kucoin_sym( def fqsn_to_kucoin_sym(
fqsn: str, fqsn: str,
pairs: dict[str, KucoinMktPair] pairs: dict[str, KucoinMktPair]
) -> str: ) -> str:
pair_data = pairs[fqsn] pair_data = pairs[fqsn]
return pair_data.baseCurrency + "-" + pair_data.quoteCurrency return pair_data.baseCurrency + "-" + pair_data.quoteCurrency
@ -401,7 +405,7 @@ def kucoin_sym_to_fqsn(sym: str) -> str:
return sym.lower().replace("-", "") return sym.lower().replace("-", "")
@acm @ acm
async def get_client() -> AsyncGenerator[Client, None]: async def get_client() -> AsyncGenerator[Client, None]:
client = Client() client = Client()
@ -410,7 +414,7 @@ async def get_client() -> AsyncGenerator[Client, None]:
yield client yield client
@tractor.context @ tractor.context
async def open_symbol_search( async def open_symbol_search(
ctx: tractor.Context, ctx: tractor.Context,
) -> None: ) -> None:
@ -581,6 +585,7 @@ async def open_history_client(
type: str = "1m", type: str = "1m",
) -> AsyncGenerator[Callable, None]: ) -> AsyncGenerator[Callable, None]:
async with open_cached_client("kucoin") as client: async with open_cached_client("kucoin") as client:
log.info("Attempting to open kucoin history client")
async def get_ohlc_history( async def get_ohlc_history(