Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate prices with get_klines #1379

Open
kelon33 opened this issue Dec 10, 2023 · 2 comments
Open

Inaccurate prices with get_klines #1379

kelon33 opened this issue Dec 10, 2023 · 2 comments

Comments

@kelon33
Copy link

kelon33 commented Dec 10, 2023

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)

  • Python version: 3.7
  • Virtual Env: Visual Studio Code
  • OS: Windows 10
  • python-binance version

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
Copy link

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
Copy link
Author

kelon33 commented Dec 30, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@kelon33 @phong-phuong and others