Skip to content

Commit

Permalink
do not push empty candles list in ohlcv channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Dec 6, 2020
1 parent 29bf6b9 commit 658acec
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions octobot_trading/exchange_data/ohlcv/channel/ohlcv_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class OHLCVUpdater(ohlcv_channel.OHLCVProducer):
OHLCV_ON_ERROR_TIME = 5
OHLCV_MIN_REFRESH_TIME = 1
OHLCV_REFRESH_TIME_THRESHOLD = 1.5 # to prevent spamming at candle closing
OHLCV_REFRESH_RETRY_DELAY = 10

OHLCV_INITIALIZATION_TIMEOUT = 60
OHLCV_INITIALIZATION_RETRY_DELAY = 10
Expand Down Expand Up @@ -135,7 +136,7 @@ async def _candle_callback(self, time_frame, pair):
else:
last_candle: list = []

if last_candle:
if last_candle and len(candles) > 1:
current_candle_timestamp: float = last_candle[common_enums.PriceIndexes.IND_PRICE_TIME.value]
should_sleep_time: float = current_candle_timestamp + time_frame_sleep - time.time()

Expand All @@ -151,8 +152,11 @@ async def _candle_callback(self, time_frame, pair):

await asyncio.sleep(self._ensure_correct_sleep_time(should_sleep_time, time_frame_sleep))
else:
# TODO think about asyncio.call_at or call_later
await asyncio.sleep(time_frame_sleep)
# not enough candles: retry soon
self.logger.warning(f"Missing candles in request results for {pair} on {time_frame}, "
f"refreshing in {self.OHLCV_REFRESH_RETRY_DELAY} seconds "
f"(candles: {candles}).")
await asyncio.sleep(self.OHLCV_REFRESH_RETRY_DELAY)
else:
# candles on this time frame have not been initialized: sleep until the next candle update
await asyncio.sleep(max(0.0, time_frame_sleep - (time.time() - start_update_time)))
Expand Down

0 comments on commit 658acec

Please sign in to comment.