feat: download-trades-data on binance has limited history

with from=0, we can get the initial data available.

closes #10941
This commit is contained in:
Matthias
2024-11-16 10:02:22 +01:00
parent c61a71a36e
commit d59bedf977
2 changed files with 25 additions and 1 deletions

View File

@@ -260,3 +260,19 @@ class Binance(Exchange):
return self.get_leverage_tiers() return self.get_leverage_tiers()
else: else:
return {} 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

View File

@@ -2886,6 +2886,14 @@ class Exchange:
else: else:
return trades[-1].get("timestamp") 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( async def _async_get_trade_history_id(
self, pair: str, until: int, since: int | None = None, from_id: str | None = None self, pair: str, until: int, since: int | None = None, from_id: str | None = None
) -> tuple[str, list[list]]: ) -> tuple[str, list[list]]:
@@ -2912,7 +2920,7 @@ class Exchange:
# of up to an hour. # of up to an hour.
# e.g. Binance returns the "last 1000" candles within a 1h time interval # e.g. Binance returns the "last 1000" candles within a 1h time interval
# - so we will miss the first trades. # - 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]) trades.extend(t[x])
while True: while True:
try: try: