Ethereum: Binance Multit Red Sockets – Functions not called Concrete *
The multit -binance red plugs that provide providing market data on the real -taken of the Binance API in Paralale, allowing efficient and concurrent access to the data. However, this can lead to problems if managed correctly.
Concurrence considerations
When they are multirrés plugs, it is the most important thing to ensure that all threads are properly synchronized for synchronous and other phrases related to concurrence. A communication is Ishple threads to call functions simultaneously without adequate synchronization, leads to unexpected behavior or euros.
In the code to provide, the problems of not those of those there are:
Assyncio.gather ()
: The `This case.
with a loop
: CallAnalyze (res)with a loop can be multiply the threads by calling the same functionality restriction, which can be behavior and time.
Recommended solution
To be these problems, we recommend to Wesing a more robust approach than the syntax and synchronization mechanics provided and the Binance API.
Python
Import Assyncio
ASYNC FORFALE (S):
#
Adatante now process_nalysis (res)
Async Def which () ::
Clien = Assynclient (binnance_url = "https:/binnance.com/api/v3/market"))
Tasks = []
For the symbol, combine in symbol_pair:
task = asyncio.create_task (analyze (res = par))
tasks. APEND (TASK)
Results = Waiting Ayncio.gather (*Tasks)
Processes
Process_Results (results)
Async Def which () ::
Define peers symbols to analyze
symbol_pair = [("aapl", "usd"), ("btcusdt", "btcusdt")]]]]
Performing analysis and processing is not
Waiting Asyncio.
Execute the function
Asyncio.run (where ())
Re
Explanation
In its fragment of revised code:
, we create analysis of' Asyncio.gather
. The bedrooms Analyze
function and par.asyncio.create_tash
tool is a new iteration of tasks in the loop. This allows us to administer the concurrence correctly.process_results
, which will be built in this fragment.The syntality, well -being that is properly and concurrent synchronized.