@@ -281,7 +281,7 @@ def __init__(self,
281
281
colorama .init ()
282
282
logger .info (f"Using `websockets_{ websockets .__version__ } `" )
283
283
self .specific_process_stream_data = {}
284
-
284
+ self . specific_process_stream_data_async = {}
285
285
if process_stream_data is None :
286
286
# no special method to process stream data provided, so we use add_to_stream_buffer:
287
287
self .process_stream_data = self .add_to_stream_buffer
@@ -470,7 +470,8 @@ def _add_stream_to_stream_list(self,
470
470
close_timeout = None ,
471
471
stream_buffer_maxlen = None ,
472
472
api = False ,
473
- process_stream_data = None ):
473
+ process_stream_data = None ,
474
+ process_stream_data_async = None ):
474
475
"""
475
476
Create a list entry for new streams
476
477
@@ -537,12 +538,21 @@ def _add_stream_to_stream_list(self,
537
538
get stored in the stream_buffer! `How to read from stream_buffer!
538
539
<https://unicorn-binance-websocket-api.docs.lucit.tech/README.html#and-4-more-lines-to-print-the-receives>`_
539
540
:type process_stream_data: function
541
+ :param process_stream_data_async: Provide a asynchronous function/method to process the received webstream data.
542
+ The function will be called instead of
543
+ `add_to_stream_buffer() <unicorn_binance_websocket_api.html#unicorn_binance_websocket_api.manager.BinanceWebSocketApiManager.add_to_stream_buffer>`_
544
+ like `process_stream_data(stream_data, stream_buffer_name)` where
545
+ `stream_data` cointains the raw_stream_data. If not provided, the raw stream_data will
546
+ get stored in the stream_buffer! `How to read from stream_buffer!
547
+ <https://unicorn-binance-websocket-api.docs.lucit.tech/README.html#and-4-more-lines-to-print-the-receives>`_
548
+ :type process_stream_data_async: function
540
549
"""
541
550
output = output or self .output_default
542
551
close_timeout = close_timeout or self .close_timeout_default
543
552
ping_interval = ping_interval or self .ping_interval_default
544
553
ping_timeout = ping_timeout or self .ping_timeout_default
545
554
self .specific_process_stream_data [stream_id ] = process_stream_data
555
+ self .specific_process_stream_data_async [stream_id ] = process_stream_data_async
546
556
self .stream_threading_lock [stream_id ] = {'full_lock' : threading .Lock (),
547
557
'receives_statistic_last_second_lock' : threading .Lock ()}
548
558
self .stream_list [stream_id ] = {'exchange' : self .exchange ,
@@ -1370,7 +1380,8 @@ def create_stream(self,
1370
1380
close_timeout = None ,
1371
1381
stream_buffer_maxlen = None ,
1372
1382
api = False ,
1373
- process_stream_data = None ):
1383
+ process_stream_data = None ,
1384
+ process_stream_data_async = None ):
1374
1385
"""
1375
1386
Create a websocket stream
1376
1387
@@ -1478,6 +1489,15 @@ def create_stream(self,
1478
1489
object instantiation! `How to read from stream_buffer!
1479
1490
<https://unicorn-binance-websocket-api.docs.lucit.tech/README.html?highlight=pop_stream_data_from_stream_buffer#and-4-more-lines-to-print-the-receives>`_
1480
1491
:type process_stream_data: function
1492
+ :param process_stream_data_async: Provide an asynchronous function/method to process the received webstream data (callback). The
1493
+ function will be called instead of
1494
+ `add_to_stream_buffer() <unicorn_binance_websocket_api.html#unicorn_binance_websocket_api.manager.BinanceWebSocketApiManager.add_to_stream_buffer>`_
1495
+ like `process_stream_data(stream_data)` where
1496
+ `stream_data` cointains the raw_stream_data. If not provided, the raw stream_data will
1497
+ get stored in the stream_buffer or provided to the global callback function provided during
1498
+ object instantiation! `How to read from stream_buffer!
1499
+ <https://unicorn-binance-websocket-api.docs.lucit.tech/README.html?highlight=pop_stream_data_from_stream_buffer#and-4-more-lines-to-print-the-receives>`_
1500
+ :type process_stream_data_async: function
1481
1501
:return: stream_id or 'False'
1482
1502
"""
1483
1503
# handle Websocket API streams: https://developers.binance.com/docs/binance-trading-api/websocket_api
@@ -1545,7 +1565,8 @@ def create_stream(self,
1545
1565
close_timeout = close_timeout ,
1546
1566
stream_buffer_maxlen = stream_buffer_maxlen ,
1547
1567
api = api ,
1548
- process_stream_data = process_stream_data )
1568
+ process_stream_data = process_stream_data ,
1569
+ process_stream_data_async = process_stream_data_async )
1549
1570
try :
1550
1571
loop = asyncio .new_event_loop ()
1551
1572
except OSError as error_msg :
0 commit comments