Ethereum: exact prices of the API Binance interface from historical data
As a developer using Python, you probably know the importance of giving Ethereum an accurate and current historical price. In this article, we examine how to determine the exact prices of API Binance in Python.
preliminary requirements
- API Binance key
- Catalog that can support asynchronous data collection (such as "requests", "Aiohttp")
- Python environment by installing the necessary libraries
Method 1: Use of the "request" and reimbursement
Using the "demands" catalog, we submit an HTTP request for API Binance. We create a withdrawal function that we start when the new data point comes from API.
`Python
Import requests
From Datatime Datetime data
Def Get_API_PRICE (Start_DATE_ST, End_DATE_ST):
![Ethereum: How do I get Binance API prices in Python at a precise time?](https://shopxperience.in/wp-content/uploads/2025/02/225da675.png)
Set the API Binance and URL of the API
Api_key = "your_api_key"
Api_url = f " {end_date_st} & limit = 100" "
Although true:
to try:
Answer = Requests.GET (API_URL, Headers = {"X-UPI-KEY": API_KEY})
Data = response.json ()
For the data element ["result"]:
If the "time marker" in element and int (ITEM ["time marker"])> = Start_date_ST:
Return of swimming (flight ["price"])
Except for demands.
Print (f "error: {e}")
Method 2: With the help of "Aiohttp" and loop
If you prefer a more asynchronous approach, you can use the data of the AIOHTTP catalog with API.
`Python
Import aiohttp
Async def is_api_price (start_date_str, end_date_str):
ASync with aiohttp.clousssion () as a session:
Api_url = f " {end_date_st} & limit = 100" "
Start_date = datetime.stratime (start_date_str, "%y-%m-%d")
end_date = datatime.stratime (end_date_str, "%y-%m-%d")
During start_date <= end_date:
to try:
Answer = waiting for session.get (API_URL)
Data = wait for response.json ()
For the data element ["result"]:
If the "time marker" in element and int (item ["stamp"]))> = start_date:
Return of swimming (flight ["price"])
Except for aiohttp.cloussponseserrr as E:
Print (f "error: {e}")
Start_date_st = "2022-01-01"
end_date_st = "2022-12-31"
Get_API_PRICE (Start_DATE_ST, End_DATE_ST)
Tips and variants
- Remember to mention "own_api_key" for the actual key of API Binance.
- You can set the "Limit" parameter in both examples to download more or less data points.
- Consider adding errors in cases where the request of the API is not said or refunds an incorrect answer.
- If you want to carry out further processing at the prices received, you can change the withdrawal functions.