Enhance Keyboard interrupt handling for dl-trades (stores data it already downloaded).

This commit is contained in:
Matthias
2023-08-20 11:57:59 +02:00
parent 4fefae6f07
commit b71a44f27c
+15 -3
View File
@@ -5,6 +5,7 @@ Cryptocurrency Exchanges support
import asyncio import asyncio
import inspect import inspect
import logging import logging
import signal
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from math import floor from math import floor
@@ -2253,6 +2254,7 @@ class Exchange:
from_id = t[-1][1] from_id = t[-1][1]
trades.extend(t[:-1]) trades.extend(t[:-1])
while True: while True:
try:
t = await self._async_fetch_trades(pair, t = await self._async_fetch_trades(pair,
params={self._trades_pagination_arg: from_id}) params={self._trades_pagination_arg: from_id})
if t: if t:
@@ -2268,6 +2270,9 @@ class Exchange:
from_id = t[-1][1] from_id = t[-1][1]
else: else:
break break
except asyncio.CancelledError:
logger.debug("Async operation Interrupted, breaking trades DL loop.")
break
return (pair, trades) return (pair, trades)
@@ -2286,6 +2291,7 @@ class Exchange:
# DEFAULT_TRADES_COLUMNS: 0 -> timestamp # DEFAULT_TRADES_COLUMNS: 0 -> timestamp
# DEFAULT_TRADES_COLUMNS: 1 -> id # DEFAULT_TRADES_COLUMNS: 1 -> id
while True: while True:
try:
t = await self._async_fetch_trades(pair, since=since) t = await self._async_fetch_trades(pair, since=since)
if t: if t:
since = t[-1][0] since = t[-1][0]
@@ -2297,6 +2303,9 @@ class Exchange:
break break
else: else:
break break
except asyncio.CancelledError:
logger.debug("Async operation Interrupted, breaking trades DL loop.")
break
return (pair, trades) return (pair, trades)
@@ -2344,9 +2353,12 @@ class Exchange:
raise OperationalException("This exchange does not support downloading Trades.") raise OperationalException("This exchange does not support downloading Trades.")
with self._loop_lock: with self._loop_lock:
return self.loop.run_until_complete( task = asyncio.ensure_future(self._async_get_trade_history(
self._async_get_trade_history(pair=pair, since=since, pair=pair, since=since, until=until, from_id=from_id))
until=until, from_id=from_id))
for sig in [signal.SIGINT, signal.SIGTERM]:
self.loop.add_signal_handler(sig, task.cancel)
return self.loop.run_until_complete(task)
@retrier @retrier
def _get_funding_fees_from_exchange(self, pair: str, since: Union[datetime, int]) -> float: def _get_funding_fees_from_exchange(self, pair: str, since: Union[datetime, int]) -> float: