remove pairs from _pairs_schedules when their coroutine stops
This commit is contained in:
@@ -81,23 +81,30 @@ class ExchangeWS:
|
|||||||
logger.info(f"Removal done: new watch list ({len(self._klines_watching)})")
|
logger.info(f"Removal done: new watch list ({len(self._klines_watching)})")
|
||||||
|
|
||||||
async def _schedule_while_true(self) -> None:
|
async def _schedule_while_true(self) -> None:
|
||||||
|
# For the ones we should be watching
|
||||||
for p in self._klines_watching:
|
for p in self._klines_watching:
|
||||||
|
# Check if they're already scheduled
|
||||||
if p not in self._klines_scheduled:
|
if p not in self._klines_scheduled:
|
||||||
self._klines_scheduled.add(p)
|
self._klines_scheduled.add(p)
|
||||||
pair, timeframe, candle_type = p
|
pair, timeframe, candle_type = p
|
||||||
task = asyncio.create_task(
|
task = asyncio.create_task(
|
||||||
self._continuously_async_watch_ohlcv(pair, timeframe, candle_type))
|
self._continuously_async_watch_ohlcv(pair, timeframe, candle_type))
|
||||||
self._background_tasks.add(task)
|
self._background_tasks.add(task)
|
||||||
task.add_done_callback(partial(
|
task.add_done_callback(
|
||||||
self._continuous_stopped, pair=pair, timeframe=timeframe)
|
partial(
|
||||||
|
self._continuous_stopped,
|
||||||
|
pair=pair,
|
||||||
|
timeframe=timeframe,
|
||||||
|
candle_type=candle_type
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _continuous_stopped(self, task: asyncio.Task, pair: str, timeframe: str):
|
def _continuous_stopped(
|
||||||
|
self, task: asyncio.Task, pair: str, timeframe: str, candle_type: CandleType):
|
||||||
self._background_tasks.discard(task)
|
self._background_tasks.discard(task)
|
||||||
result = task.result()
|
result = task.result()
|
||||||
logger.info(f"{pair}, {timeframe} Task finished {result}")
|
logger.info(f"{pair}, {timeframe} Task finished {result}")
|
||||||
# self._pairs_scheduled.discard(pair, timeframe, candle_type)
|
self._pairs_scheduled.discard(pair, timeframe, candle_type)
|
||||||
|
|
||||||
async def _continuously_async_watch_ohlcv(
|
async def _continuously_async_watch_ohlcv(
|
||||||
self, pair: str, timeframe: str, candle_type: CandleType) -> None:
|
self, pair: str, timeframe: str, candle_type: CandleType) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user