sammchardy / python-binance

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

Inaccurate prices with get_klines #1379

Open kelon33 opened 6 months ago

kelon33 commented 6 months ago

When using the get_klines function, the opening prices for symbols are often times inaccurate.

Code snippet to reproduce the behavior: import pandas as pd from dotenv import load_dotenv from binance.client import Client import os import datetime load_dotenv()

client = Client(api_key, api_secret, testnet=True) candles = client.get_klines(symbol='BNBUSDT', interval=Client.KLINE_INTERVAL_1HOUR) df = pd.DataFrame(candles) ts = df.iloc[-4][0]/1000 dt = datetime.datetime.fromtimestamp(ts) dt.strftime("%Y-%m-%d %H:%M:%S") open_price = [] for col in range(len(df.index)): open_price.append(df.iloc[col][1]) print(open_price[-4]) print(dt)

Expected to get accurate open price of a kline as shown on binance.

the code gives the result: 240.60000000 2023-12-10 17:00:00

While for the same time interval on binance, for the same kline, the price given is 240.3 and not 240.6. Similar inaccuracies happen with some of the other open prices.

phong-phuong commented 6 months ago

The client is using the testnet API. To avoid this, set testnet = False when creating the client. This will then pull the real market prices. client = Client(testnet=False)

kelon33 commented 6 months ago

Thank you very much for the reply. The solution is simple, but I was unaware of the difference in prices over the testNET, so it eluded me. Thank you again.

בתאריך יום ו׳, 29 בדצמ׳ 2023, 1:56, מאת phong-phuong ‏< @.***>:

The client is using the testnet API. To avoid this, set testnet = False when creating the client. This will then pull the real market prices. client = Client(testnet=False)

— Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/1379#issuecomment-1871631396, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALX46DEM7SQMJLJWG6OSEMLYLYBMTAVCNFSM6AAAAABAOYCG42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZRGYZTCMZZGY . You are receiving this because you authored the thread.Message ID: @.***>