From 32107d0ac3b97a9bd2d398b51c26136e7c9050e3 Mon Sep 17 00:00:00 2001 From: jaredgoldman Date: Mon, 20 Mar 2023 21:24:23 -0400 Subject: [PATCH] Strengthen retry case and add comments --- piker/brokers/kucoin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/piker/brokers/kucoin.py b/piker/brokers/kucoin.py index 65f47a40..ee7c04f7 100644 --- a/piker/brokers/kucoin.py +++ b/piker/brokers/kucoin.py @@ -343,6 +343,7 @@ class Client: url = f"/market/candles?type={type}&symbol={kucoin_sym}&startAt={start_dt}&endAt={end_dt}" bars = [] + for i in range(10): res = await self._request( @@ -350,7 +351,9 @@ class Client: url, api_v="v1", ) - if not isinstance(res, list): + + if not isinstance(res, list) or not len(bars): + # Do a gradual backoff if Kucoin is rate limiting us await trio.sleep(i + (randint(0, 1000) / 1000)) else: bars = res