sammchardy / python-binance

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

get historical klines up until last complete kline (rather than current incomplete kline) #1259

Open some-crab opened 1 year ago

some-crab commented 1 year ago

I grab the historical klines from python-binance without specifying end_str, and it seems the last kline is incomplete. This might be unsurprising when looking at the docs because it says it gets until NOW (so going to be within the active kline), but I believe that this behaviour is a bit strange as a default.

For example, let's say we grab klines now, at time 1 - call it klines 1. We then wait another interval step and grab klines at time 2, call it klines 2. The final row of klines 1 is different than the exact same timestamp in klines 2. I think because the kline is still in progress.

I manually correct for this with just dropping that final kline, but is there a reliable way to get just up to latest COMPLETE kline by using end_str?

halfelf commented 1 year ago

Try get_klines(), futures_klines() and futures_coin_klines(), which should be true to original binance APIs.

As I understand, historical_klines methods are used to fetch huge amount of klines to overcome the limit param in orginal APIs, and sadly not written very well in some corner cases.