sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.01k stars 2.2k forks source link

get_historical_klines limit does not work #1307

Open plm203 opened 1 year ago

plm203 commented 1 year ago

Hi, first of all thanks for the great package. I'm trying to fetch a fixed number of candles at different timeframes, i set a start date and a limit of say 1000. But it always gets me data up to the present time, for instance, today april 3rd,

ticker = 'BTCUSDT' interval=Client.KLINE_INTERVAL_4HOUR client = Client() data = client.get_historical_klines(ticker, interval, start_str='1 Jan, 2022', limit=1000)

returns 2746 candles.

I could somewhat fix the issue by changing the code of client.py, line 999 from: if len(temp_data) < limit: to if len(temp_data) == limit:

Now i can set a limit up to 1000 and have exactly that number of candles returned, but limit=1001 in the above will return again 2746 candles.

Any idea how to fix client.py so as to have the expected behavior when setting a limit. I suppose my pseudofix will not hold water in the long run. Thank you very much.

halfelf commented 1 year ago

duplicate #1250

I have a fix there. But cannot spare time to submit a sound patch or pull request.

plm203 commented 1 year ago

Thank you very much. I think i searched to avoid potential duplicate. Sorry i did not do that well enough.