CRYPTOCURRENCY

Ethereum: Multiple websocket streams with asyncio in Python

Ethereum and Websockets: Creation of the ceiling in real time with Assinsio

==================================================================== =================================== = ================================= ======================================== =============================== ============================================

Like Python, you, verifiable, the importance of the data of the ceiling in real time in such applications, such as the financial Torgovli platform. Odin from the lightning of this Chebsckets, a protocol for the establishment of a bidirectional connection between customers and servers on the Internet.

In this state, we were not satisfied with how to use the Asyncio (Vyodovo Python asynchronous library), to connect some sweat websockets with Ethereum with Python.

What is this donkey?

——

Asyncio reaches the verse of Python 3.4+ and provides the Suprazhka of the Vicori, coats and operational parallelism. It allows you to write a single parallel code with a syntax/wait asynchronous, which entertains an efficiency and resize the Astropic Code.

Connection to Binance Websckets

———-

To connect to the websckets Binance, we will use the “pass” of the bookshop with the websocket client. We also use the Aspen for the restoration of several legs.

`Python

It matters aspings

Import aiohttp

Async Def Get_webscket_data (Api_Key):

URL = F " signed"

Params = {

"Key": Api_key,

"Simvol": "btcusdt",

"Event_type": "New_order",

"Predel": 1

}

Async with aiohttp.clientione () as a session:

Async with session.post (URL, Json = Params) in the caste:

Data = WAW WART Repose.json ()

return the data

Async Def Main ():

Api_Keys = ["Api_key_1", "Api_key_2", "Api_key_3"]

Tasks = [Get_Websocket_data (Api_key) for aPi_Key B Api_kes]

Ottuts = Wait asyncio.gather (*tasks)

Package (Odvets)

If __name__ == "__Main__":

Asyncio.run (main ())

In this score, we delay the function ofGET_WEBSCKET_DATA, which sets the inviting subscription to Binance with the API API key. We useAsyncio.gather ‘for the use of different tasks one.

We are the list of the API Klavis and transmit its functions GET_WEBSOCKET_DATA 'with the use of Async for' loop. Each assignment is understood by Independent that allows us to penetrate different legs.

Primer output

--------

The deduction will be the object of Json, the traditional market data of the websocket binance bees.

[

{'' Symbol ':' Btcusdt ',' Last_price ': 0.0001},

{'Symbol': 'Btcusdt', 'Bid': 0.001, 'Ask': 0.002},

...

"

Potus data in real time

--------

In order to indicate individuals for requests for the County Clawish API, we can use the Asyncio One Cellets and subscribe to some websockets, using the operational operation.

Python

It matters aspings

Async Def Main ():

Api_Keys = ["Api_key_1", "Api_key_2"]

Ethereum: Multiple websocket streams with asyncio in Python

Sign Rhinic data

Async with aiohttp.clientione () as a session:

Async for the story in Session.get (" Answer:

If 'ok' in response.json ():

Data = WAW WART Repose.json ()

For api_key, sobility in zip (api_keys, ['market', 'order', 'trading']):

To be trapped

PRINT (F "Renal data: {Event}")

Imperial orders and boring measures

If coat ['Type'] == 'New_order':

Pack ("revocated new order")

Start the basic function

Asyncio.run (main ())

`

In this score, we sign some websockets and a “for” cil. We are understanding each other in evident India, the liver.

Ethereum Tradingview Volume

Leave a Reply

Your email address will not be published. Required fields are marked *