Ethereum Features simultaneously with Binance Connecter and WebSockets
In this article, we will show you how to create a Python program that performs multiple features simultaneously using Binance-Connector library to create orders in Ethereum in the block circle and the realization of the unicorn and Binens-Websocket-API Real Time Information for Real Time Information Real Time Information Real Time Information Real Time Information for information. flow.
Conditions required
- Install the required libraries:
`Bash
PIP Binance-Connecter Unicorn and to install larger
`
- Change
Your_bnb_Api_Key
,Your_bnb_api_secret 'and
Your_Der_idReal Binance API and order ID.
Code
Python
Imported asynit
From the import of the Binance connector
Unicorn_binance_websocket_api import binancewebsketeaki
Set Ethereum customer
EB = Customer ()
Eb.lad_secret_key_from_file (‘Road/To/Secret.key’)
Set WebSocket Connection
WSA = Binancewebsketapapi (EB, ‘BTCUSDT’, ‘Stream’)
Async Def Create_ORDER ():
Create a new order with Binance-Connecter
Data = {
“Side”: “Buy”,
“Type”: Border,
Time_in_Force: GTC,
“Quantity”: 10,
Price: 1000.0
}
Result = Wait eb.place_order (data)
Print (F “Created Order: {Result}”)
Async Definier_status ():
Get the status of an order created with the flow of user information site
Async report wsa.get_messages ():
If the message [‘data’] [‘type’] == ‘order’:
#, Assuming that the “order” object is stored in a message
Print (F “Order ID: {Message [‘Data’] [‘ID’]} – Status: {‘success’ If the message [‘ data ‘] [‘ status’] == 2 Change ‘failure’} ‘)
Async Def Main ():
Wait for trust_order ()
Wait get_order_status ()
Asyncio.run (head ())
`
Explanation
- The Binance-Connector for Create_order features will send a new order to the Ethereum district.
2.
- Then we drive a get_order_status -lying loop.
Code Start
Save this code as a Python file (eg eth_order.py
) and follow it using Python eth_order.py.
Note: This is just the main example of performing multiple functions at the same time. In the real world scenario, you are likely to deal with errors and exceptions.
hint
- Make sure to replace the local cursor values of the code with your actual Binance API and order ID.
- Consider errors and exceptions to make the possibility of implementing to ensure that your program remains stable and reliable.
- You may need to edit the Get_order_status feature to match the structure of the information returned by the Binance User Information application.