Question of the API of historical data binance with specific time and date
Yes, it is correct. Binance API provides historical data for various cryptocurrencies, including Ethereum (ETH). However, the query you want to do is a bit unconventional: you are trying to recover the price of a specific cryptocurrency at a specific moment in the past using historical data.
Is this type of question possible?
While Binance’s API of historical data allows you to access historical prices for various cryptocurrencies and time intervals (for example, daily, weekly), it does not directly support the recovery of prices in specific moments. API returns the data on prices for a set interval set, but not necessarily for a specific date or time.
How can we achieve this goal?
To interrogate the Binance API with a specific time and date, you will have to use a programming language that supports the bees of query using bees. In this case, I recommend using Python for its ease of use and large bookstores.
Here is a snippet of example to start:
`Python
Import requests
Set API Binance credentials
api_key = ‘Your_api_key’
Api_secret = ‘Your_api_secret’
Set the specific cryptocurrency and time interval (e.g. Eth-1h)
cryptocurrency = ‘eth’
time_ interval = ‘1h’
1 hour to date
Build the URL of the API request
URL = f’https: //api.binance.com/api/v3 historical candlestick/eth/{time_ interval} ‘
Set the endpoint and header of the Binance (optional)
Headers = {
‘Authorization’: f’bearer {api_key} ‘,
‘Content-Type’: ‘Application/Json’
}
Send the GET request
Answer = Requests.get (URL, heading = headers)
Check if the answer has been successful
If reply.status_code == 200:
Analyze Json data
Data = Response.json ()
Extract the price (Eth-1h) from the data
Prices = Date [‘Candles’]
For candles in prices:
If Candle [‘Symbol’] == Cryptovice and Candle [‘Time’]. Split (”) [0] == ‘1103’:
Print (F’Price of {cryptocurrency} at 1103 hours Friday 31 August 2018: $ {Candle [“Close”]} ‘)
other:
Print (f’failed to recover the data. State code: {Reply.status_code} ‘)
`
How it works
1
- We have set up our Binance API credentials, including an API key and a secret.
3
- If the answer is successful, we analyze the Json data from the response body.
5
Note that this fragment of code presupposes that the necessary addictions are arranged (e.g., libraryJson`). It may be necessary to change the Endpoint API and the headers, if necessary for the specific use case.
Additional considerations
- Make sure to correctly manage errors, such as control if the answer has been successful or correctly analyzes Json data.
- Take into consideration the implementation of errors management measures to mitigate potential problems with the API request.
- This fragment of code is only a starting point. It may be necessary to adjust it to meet the specific requirements and consequently modify the time interval or the cryptocurrency.
Leave a Reply