From d59bedf9773a384a76c9186b2463bd6344dd07fc Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 16 Nov 2024 10:02:22 +0100 Subject: [PATCH] feat: download-trades-data on binance has limited history with from=0, we can get the initial data available. closes #10941 --- freqtrade/exchange/binance.py | 16 ++++++++++++++++ freqtrade/exchange/exchange.py | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index c17050ec7..20d045f69 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -260,3 +260,19 @@ class Binance(Exchange): return self.get_leverage_tiers() else: return {} + + async def _async_get_trade_history_id_startup( + self, pair: str, since: int | None + ) -> tuple[list[list], str]: + """ + override for initial call + + Binance only provides a limited set of historic trades data. + Using from_id=0, we can get the earliest available trades. + So if we don't get any data with the provided "since", we can assume to + download all available data. + """ + t, from_id = await self._async_fetch_trades(pair, since=since) + if not t: + return [], "0" + return t, from_id diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 1c1d3bf7f..6a17b07e6 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2886,6 +2886,14 @@ class Exchange: else: return trades[-1].get("timestamp") + async def _async_get_trade_history_id_startup( + self, pair: str, since: int | None + ) -> tuple[list[list], str]: + """ + override for initial trade_history_id call + """ + return await self._async_fetch_trades(pair, since=since) + async def _async_get_trade_history_id( self, pair: str, until: int, since: int | None = None, from_id: str | None = None ) -> tuple[str, list[list]]: @@ -2912,7 +2920,7 @@ class Exchange: # of up to an hour. # e.g. Binance returns the "last 1000" candles within a 1h time interval # - so we will miss the first trades. - t, from_id = await self._async_fetch_trades(pair, since=since) + t, from_id = await self._async_get_trade_history_id_startup(pair, since=since) trades.extend(t[x]) while True: try: