I will help you write an article on how to recover current Kines of 00: 00UTC so far for all available tickers without loop through each ticket.
When recovering the current binance kines using an approach for a search
Binance provides a powerful bees that allows you to recover the data in a single application. In this article, we will explore how to use this API to recover current kines for all tickers available from 00: 00utc so far.
PREVIOUS REQUIREMENTS
- It has an API Binance account and has established a new application (if it has not yet done so).
- Be sure to have installed the `
requested 'in your Python environment. Otherwise, you can install it with PIP:
Bash
PIP installation requests
The code
We will use the "requests" of the bookstore to send an API application to Binance. We will create a single function that recovers current kines for all available tickers.
Python
Import requests
From the importation of Datetime Datetime, Timelta
Def get_binance_klines () ::
URL = "
Set the key to bees and secret (if you have one).
API_Key = 'Your_api_Key_here'
API_SECret = 'Your_api_secret_here'
Headers = {
'Type of content': 'application/json',
'X-API-KEY': Api_Key,
'X-API-SECRET': API_SECRET
}
Obtain the date and time of the time in UTC.
Now_utc = datetime.utcfromimestamp (0)
Define the tickers for which to recover kines. You can add or delete tickers as necessary.
Tickers = ['btcusdt', 'ethusdt']
replace with the desired tickers
Initializes an empty list to store kines data
Kines_data = []
While ora_utc
Attempt:
Send a binance application with our header and the API key
ANSWER = REQUESTS.get (URL, headed = headers)
Check if the answer has been successful
If you respond.status_code == 200:
Data = answer.json ()
Tour each Kline (5 seconds of data)
For the range (0, Len (data), 10):
Kline = {
'Timestamp': Datetime.utcfromimestamp (date [i] ['t']),
'Open': float (data [i] ['or']),
'High': float (date [i] ['h']),
'Low': float (data [i] ['l']),
'Close': float (date [i] ['c']),
'Volume': int (date [i] ['v'])
}
Add Kline's data to our list
kines_data.append (kline)
Sleep for 5 seconds before recovering the following set of kines
Or_utc += Timelta (second = 5)
other:
Raise the exception (F "API request not deleted with the State Code {Answer.status_code}")
Except the exception as E:
Print (f "A mistake occurred: {e}")
Return kines_data
Using the function
To use our function, call it simply in your Python script. Replaceyour_api_Key_hereis su_api_secret_here' with the real binance credentials.
Python
Kines = get_binance_klines ()
Print (kines)
`
This will print all the KLINS available for specified tickers. The number of kines returned is limited by the speed limits of the API, so be sure to administer any error that may occur during the application process.
Note : Be sure to verify the Binance API documentation to obtain the most up -to -date information on rates, limits and use guidelines before integrating your bees into the project.