sammchardy / python-binance

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

get_historical_klines return wrong OHLC data for highs and lows #1330

Open mrxz44 opened 1 year ago

mrxz44 commented 1 year ago

Describe the bug get_historical_klines returns historical OHLC data as expected, but the data itself doesn't match with actual spot prices. In that particular case 'high' and 'low' values for some candles differ significantly from the actual.

To Reproduce

client = Client(api_key=api_key, api_secret=api_secret, testnet=True)
hist = client.get_historical_klines(symbol="BTCUSDT", interval=self.client.KLINE_INTERVAL_1MINUTE, limit=1000)

h[0] is a timestamp, h[2] is low, h[3] is high following loop shows high-low discrepancy (round(float(h[3])-float(h[2]))) in retrieved data

for h in hist:
        t = datetime.datetime.fromtimestamp(h[0]/1000)
        print(t, h[1:5], round(float(h[3])-float(h[2])))

output sample: 2023-06-07 18:17:00 ['26486.29000000', '52980.20000000', '26480.90000000', '26531.10000000'] -26499 2023-06-07 18:18:00 ['26525.84000000', '29898.26000000', '26516.73000000', '26552.90000000'] -3382 2023-06-07 18:19:00 ['26552.90000000', '29910.94000000', '26547.94000000', '26552.77000000'] -3363 2023-06-07 18:20:00 ['26550.61000000', '26843.00000000', '23146.02000000', '26535.92000000'] -3697 2023-06-07 18:21:00 ['26535.92000000', '26555.12000000', '26529.87000000', '26555.12000000'] -25 2023-06-07 18:22:00 ['26555.54000000', '29973.00000000', '23131.36000000', '26541.92000000'] -6842 2023-06-07 18:23:00 ['26541.92000000', '29958.81000000', '26524.92000000', '26531.49000000'] -3434 2023-06-07 18:24:00 ['26533.62000000', '26533.63000000', '26488.19000000', '26493.91000000'] -45

2023-06-07 18:18:00 shows high 52980.20 which is clearly not right. Correct values are for 2023-06-07 18:21:00 and 2023-06-07 18:24:00 in that sample.

Expected behavior It is expected to receive data that matches the actual historical data that can be verified on Binance Spot.

Environment (please complete the following information):

Logs or Additional context Add any other context about the problem here.

mrxz44 commented 1 year ago

The plot of this data is as follows: testsave

halfelf commented 1 year ago

Firstly, please specify timezone. I need to fill start_str param to reproduce the data.

Secondly, I notice there was testnet=True param in your sample code. Test net data could be anything.

mrxz44 commented 1 year ago

Hi @halfelf, timezone UTC+3

ap74062 commented 1 year ago

Is problem still appearing after testnet=False?