Медиа Центр

Execution of Ethereum functions simultaneously without Binance-Connector and Websockts

In this article, we will demonstrate a Python program that runs simultaneously, using the Ethereum Blockcha and the Unicorn-Binance-Websockt-API for the transmission of real information.

Previous requirements

Ethereum: python program running functions simultaneously instead of running sequentially

*

  • Install the required booklets:

`Bash

Pip Install Binance-Connector Unicorn-Binance-Websocket-Api

  • Replaceyour_bnb_api_key, your_bnb_api_secretandyour_order_idwith you your real binance api credentials and ID.

Code*

Python

Import Assyncio

Prior Binance Connector Import Client

FROMORN_BINANCE_WEBSOCKET_API IMPORT BINANCEWEBSOCKETAPI

Configure the Ethereum client

EB = Client ()

EB.Load_Secret_Key_from_fille ('Path/To/Secret.Key')

Configure the WebsoSOCKET

WSA = Binancewebsocketapi (EB, 'Btcusdt', 'Streaming')

ASYNC DEF CRIT_ORDER ():

Create a new order with Connector

Data = {

"Side": "Buy",

"Type": "limit",

"Time_in_force": "GTC",

"Quantity": 10,

"Price": 10000.0

}

Result = Eb.plate_order (data)

print (f "order created: {result}")

Async Def get_order_status ():

Obtain the status of the user -created user data transmission

Async for message at wsa.get_messages () ::

if message ['data'] ['type'] == 'order':

Assuming an 'order' observed in the message

print (f "order id: {Message ['data'] ['ID']} - State: {'success' f Message ['data'] ['state'] == 2 else 'failed'})

Async Def Main () ::

wait create_order ()

WAITINGS YOUR_order_status ()

Asyncio.run (Main ())

Explanation*

1.

2.

  • In the 'Main, we first created an order’ create_order. There is, we are theget_order_statusfunction in Anynchronous loop.

Executing the code

Save this code as a python file (for example,eth_order.py) and run it with python eth_order.py.

Note: This is just a basic example to demonstrate the multiple functions of House Tour simultaneously. In a real scenario, you want to handle errors and exceptions more robust.

Advice*

  • Make replace the Walues ​​position marker in the code with its act with API credentials and order ID.

  • Consider implementing errors management and the exception to ensure that your program remains stable and reliable.

  • It is possible that you should modify theeted_order_status`

DECENTRALIZED STABLECOINS FUTURE DIGITAL