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 inspect
import logging
import signal
from copy import deepcopy
from datetime import datetime, timedelta, timezone
from math import floor
@@ -2253,6 +2254,7 @@ class Exchange:
from_id = t[-1][1]
trades.extend(t[:-1])
while True:
try:
t = await self._async_fetch_trades(pair,
params={self._trades_pagination_arg: from_id})
if t:
@@ -2268,6 +2270,9 @@ class Exchange:
from_id = t[-1][1]
else:
break
except asyncio.CancelledError:
logger.debug("Async operation Interrupted, breaking trades DL loop.")
break
return (pair, trades)
@@ -2286,6 +2291,7 @@ class Exchange:
# DEFAULT_TRADES_COLUMNS: 0 -> timestamp
# DEFAULT_TRADES_COLUMNS: 1 -> id
while True:
try:
t = await self._async_fetch_trades(pair, since=since)
if t:
since = t[-1][0]
@@ -2297,6 +2303,9 @@ class Exchange:
break
else:
break
except asyncio.CancelledError:
logger.debug("Async operation Interrupted, breaking trades DL loop.")
break
return (pair, trades)
@@ -2344,9 +2353,12 @@ class Exchange:
raise OperationalException("This exchange does not support downloading Trades.")
with self._loop_lock:
return self.loop.run_until_complete(
self._async_get_trade_history(pair=pair, since=since,
until=until, from_id=from_id))
task = asyncio.ensure_future(self._async_get_trade_history(
pair=pair, since=since, 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
def _get_funding_fees_from_exchange(self, pair: str, since: Union[datetime, int]) -> float: