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
*
`Bash
Pip Install Binance-Connector Unicorn-Binance-Websocket-Api
,
your_bnb_api_secretand
your_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.
. There is, we are the
get_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*