python-binance
python-binance copied to clipboard
get_historical_klines return wrong OHLC data for highs and lows
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):
- Python version: 3.11
- Virtual Env: virtualenv
- OS: Mac OS Ventura 13.4
- python-binance v1.0.17
Logs or Additional context Add any other context about the problem here.
The plot of this data is as follows:
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.
Hi @halfelf, timezone UTC+3
Is problem still appearing after testnet=False?