Small adjustments to get_trade_history

This commit is contained in:
Matthias 2019-08-29 13:01:44 +02:00
parent 0d592f6c55
commit 05e473642b

View File

@ -780,8 +780,8 @@ class Exchange:
raise OperationalException(f'Could not fetch trade data. Msg: {e}') from e raise OperationalException(f'Could not fetch trade data. Msg: {e}') from e
async def _async_get_trade_history_id(self, pair: str, async def _async_get_trade_history_id(self, pair: str,
until: int,
since: Optional[int] = None, since: Optional[int] = None,
until: Optional[int] = None,
from_id: Optional[str] = None) -> Tuple[str, List[Dict]]: from_id: Optional[str] = None) -> Tuple[str, List[Dict]]:
""" """
Asyncronously gets trade history using fetch_trades Asyncronously gets trade history using fetch_trades
@ -812,12 +812,12 @@ class Exchange:
if len(t): if len(t):
# Skip last id since its the key for the next call # Skip last id since its the key for the next call
trades.extend(t[:-1]) trades.extend(t[:-1])
if from_id == t[-1]['id'] or (until and t[-1]['timestamp'] > until): if from_id == t[-1]['id'] or t[-1]['timestamp'] > until:
logger.debug(f"Stopping because from_id did not change. " logger.debug(f"Stopping because from_id did not change. "
f"Reached {t[-1]['timestamp']} > {until}") f"Reached {t[-1]['timestamp']} > {until}")
# Reached the end of the defined-download period
break break
# Reached the end of the defined-download period
from_id = t[-1]['id'] from_id = t[-1]['id']
else: else:
break break
@ -845,6 +845,8 @@ class Exchange:
trades.extend(t) trades.extend(t)
# Reached the end of the defined-download period # Reached the end of the defined-download period
if until and t[-1]['timestamp'] > until: if until and t[-1]['timestamp'] > until:
logger.debug(
f"Stopping because until was reached. {t[-1]['timestamp']} > {until}")
break break
else: else:
break break
@ -862,14 +864,18 @@ class Exchange:
# TODO: Maybe don't stop the bot ... ? # TODO: Maybe don't stop the bot ... ?
raise OperationalException("This exchange does not suport downloading Trades.") raise OperationalException("This exchange does not suport downloading Trades.")
try: try:
if not until:
# Current milliseconds
until = ccxt.Exchange.milliseconds()
if self._trades_pagination == 'time': if self._trades_pagination == 'time':
return await self._async_get_trade_history_time(pair=pair, since=since, until=until) return await self._async_get_trade_history_time(
pair=pair, since=since,
until=until or ccxt.Exchange.milliseconds())
elif self._trades_pagination == 'id': elif self._trades_pagination == 'id':
return await self._async_get_trade_history_id(pair=pair, since=since, return await self._async_get_trade_history_id(
until=until, from_id=from_id) pair=pair, since=since,
until=until or ccxt.Exchange.milliseconds(), from_id=from_id
)
else:
raise OperationalException(f"Exchange {self.name} does use neither time, "
f"nor id based pagination")
except ccxt.NotSupported as e: except ccxt.NotSupported as e:
raise OperationalException( raise OperationalException(