Ethereum: How do I get Binance API prices in Python at a precise time?

Ethereum: current binance of the API with historical data

As disintegration, using Python, you, verifiable, are the importance of current and contemporary historical databases for Ethereum. In this state, we dissatisfied, how to obtain the curiosity of the binance API in Python in the defined time.

Suppliers

  • Binance —whe

  • Bibliotek, which can be surrounded by databases (for example, Aiohttp)

  • Are python with unusual libraries, established

Method 1: Use of Adsue and Oblatory function

We will use the `Avks '' library to make http-in the binance API. We are the function of the obvious call, which will be initiated by a whole, when a new data point is linked to the API.

Python

Imports

From Datetime Import -DateTime

Def Get_api_price (start_date_str, end_date_str):

Install your Binance API and URL -Adsrece key of the API score

API_KEY = "your_api_key"

API_URL = f " & LIMIT = 100"

At this time as a truth:

ask:

Answer = Requestts.get (API_URL, headers = {"x-dep-Key": API_KEY})

Data = answer.json ()

Forest The Shadow of ETH on the specified date

For the element in data ["result"]:

If "time lamp" in the element and int (item ["horodat"])> = start_date_str:

AVAIRATS Float (point ["cane"])

Crowfs.

Print (f "Oshhybka: {e}")

'

Method 2: Use ofAiohttpand Cycles

Ethereum: How do I get Binance API prices in Python at a precise time?

If you prefer a more emitted loser, we can use the Aiohttp library ”to extinguish API data.

Python

Import Aiohttp

Async Def Get_api_price (start_date_str, end_date_str):

Async with aiohttp.Clientsion () as session:

API_URL = f " & LIMIT = 100"

Start_date = DateTime.Strptime (start_date_str, "% y-% m-% d")

End_date = Datetime.Strptime (End_date_str, "% y-% M-% d")

B then the time like start_date <= end_date:

ask:

Answer = wait session.get (API_URL)

Data = Waw Wart rest.json ()

Forest The Shadow of ETH on the specified date

For the element in data ["result"]:

If "Town Tag" in the article and int (item ["horodat"])> = start_date:

Available Frapes (point ["cane"])

With the exception of AIOHTTP.ClientresponseryRor like E:

Print (f "Oshhybka: {e}")

Primmer Use:

start_date_str = "2022-01-01"

end_date_str = "2022-12-31"

Get_api_price (start_date_str, end_date_str)

'

Cries and variation

  • Receive what to changeyour_api_key` on your Binance API factual key.

  • You can configure the “limit” parameter in the two impressions that prints are more or less data.

  • Means the possibility of adding to the lights for listeners, when the API does not appear or the incorrect response is not necessary.

  • If you need to finish the Add -In -Seeding shadow, will not conquer the function of the Obeden.

bitcoin what what order

Yorum bırakın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

0551 132 80 32