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

get_historical_klines() takes forever and gives no output #1416

Open
DSDecay opened this issue May 15, 2024 · 1 comment
Open

get_historical_klines() takes forever and gives no output #1416

DSDecay opened this issue May 15, 2024 · 1 comment
Assignees
Labels

Comments

@DSDecay
Copy link

DSDecay commented May 15, 2024

Out of the blue, get_historical_kline() seems to stop working properly:

from binance.client import Client

def get_earliest_kline(client, symbol):
start_str = 1210685792000
try:
klines = client.get_historical_klines(symbol, Client.KLINE_INTERVAL_1MINUTE, start_str)
if klines:
print("Data retrieved:", klines)
return klines[0]
else:
print("No data received for the request.")
except Exception as e:
print(f"An error occurred: {e}")
return None

earliest_kline = get_earliest_kline(client, "ETHBTC")
if earliest_kline:
print(f"Earliest kline timestamp for ETHBTC: {datetime.fromtimestamp(earliest_kline[0] / 1000)}")
else:
print("No klines found for ETHBTC since 1 Jan, 2008.")

It should have returned first available kline, due to too early startTime (which was very much intentional), but it returns nothing. It does not throw any exceptions, but instantly sends requests.

OUTPUT:
DEBUG:urllib3.connectionpool:https://api.binance.com:443 "GET /api/v3/klines?interval=1m&limit=1&startTime=1500004920000&symbol=ETHBTC HTTP/1.1" 200 141
DEBUG:urllib3.connectionpool:https://api.binance.com:443 "GET /api/v3/klines?interval=1m&limit=1&startTime=1500004980000&symbol=ETHBTC HTTP/1.1" 200 141
...infinite requests of the same type...
. . .

Meanwhile, using requests works as expected:

import requests
url = "https://api.binance.com/api/v3/klines"
params = {
'symbol': 'ETHBTC',
'interval': '1m',
'startTime': 1210685792000,
'limit': 1
}
response = requests.get(url, params=params)
print(response.json())

OUTPUT:
[[1500004800000, '0.08000000', '0.08000000', '0.08000000', '0.08000000', '0.04300000', 1500004859999, '0.00344000', 1, '0.00000000', '0.00000000', '0']]

I tested it in several environments and it's always the same behaviour, as described above. More over, few days ago get_historical_klines() worked and I used it to populate database with timestamps of earlies klines per symbol.

Does someone know something? Maybe Binance changed something on its side?

@pcriadoperez
Copy link

Hi @DSDecay , yes it's because the API does not go that far back as you can see from the request you are requesting from timestamp 1210685792000 but binance is returning from timestamp 1500004800000.
Can you try with a more recent timestamp?

I'll leave this issue open because I believe library should return in this case an error to better inform the user and not just keep you waiting indefinetly

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

No branches or pull requests

3 participants