Open NikitaGordia opened 1 year ago
Among all the mess of issue board, this is a real bug that I can confirm.
A fix should be:
https://github.com/sammchardy/python-binance/blame/master/binance/client.py#L7504
async def _historical_klines(self, symbol, interval, start_str=None, end_str=None, limit=1000,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT):
# init our list
output_data = []
# convert interval to useful value in seconds
timeframe = interval_to_milliseconds(interval)
# establish first available start timestamp
start_ts = convert_ts_str(start_str)
if start_ts is not None:
first_valid_ts = await self._get_earliest_valid_timestamp(symbol, interval, klines_type)
start_ts = max(start_ts, first_valid_ts)
# if an end time was passed convert it
end_ts = convert_ts_str(end_str) #### LOOK HERE!!! <----- FIXME: either ALWAYS set end_ts
if end_ts and start_ts and end_ts <= start_ts:
return output_data
idx = 0
while True:
# fetch the klines from start_ts up to max 500 entries or the end_ts if set
temp_data = await self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=limit,
startTime=start_ts,
endTime=end_ts
)
# append this loops data to our output data
if temp_data:
output_data += temp_data #### LOOK HERE!!! <--- FIXME: OR, check len(output_data) to break the loop
# handle the case where exactly the limit amount of data was returned last loop
# or check if we received less than the required limit and exit the loop
if not len(temp_data) or len(temp_data) < limit:
# exit the while loop
break
# set our start timestamp using the last value in the array
# and increment next call by our timeframe
start_ts = temp_data[-1][0] + timeframe
# exit loop if we reached end_ts before reaching <limit> klines
if end_ts and start_ts >= end_ts:
break
# sleep after every 3rd call to be kind to the API
idx += 1
if idx % 3 == 0:
await asyncio.sleep(1)
I'll see what I can do to open a pull request, no promise though.
Describe the bug
To Reproduce Code snippet to reproduce the behavior:
RESULT: 27, datetime.timedelta(seconds=17, microseconds=590134) VS
RESULT: 1, datetime.timedelta(microseconds=510833)
Expected behavior
limit should limit response
Logs or Additional context The problem with timing diminishes when you increase the limit, but limit still doesn't work