@@ -29,16 +29,23 @@ async def handle_socket_message(stream_id=None):
2929 ubwa .api .futures .get_server_time (stream_id = api_stream )
3030 orig_client_order_id = ubwa .api .futures .create_order (stream_id = api_stream , price = 1.0 , order_type = "LIMIT" ,
3131 quantity = 15.0 , side = "SELL" , symbol = market )
32- ubwa .api .futures .ping (stream_id = api_stream )
33- orderbook = ubwa .api .futures .get_order_book (stream_id = api_stream , symbol = market , limit = 2 , return_response = True )
32+ #ubwa.api.futures.ping(stream_id=api_stream)
33+ order_book = ubwa .api .futures .get_order_book (stream_id = api_stream , symbol = market , limit = 2 , return_response = True )
34+ print (f"Orderbook, lastUpdateId={ order_book ['result' ]['lastUpdateId' ]} : { order_book ['result' ]['asks' ]} , "
35+ f"{ order_book ['result' ]['bids' ]} \r \n " )
3436 ubwa .api .futures .cancel_order (stream_id = api_stream , symbol = market , orig_client_order_id = orig_client_order_id )
3537 ubwa .api .futures .get_order (stream_id = api_stream , symbol = market , orig_client_order_id = orig_client_order_id )
3638
3739 print (f"Finished! Waiting for responses:" )
3840 await asyncio .sleep (5 )
39-
4041 print (f"Stopping!" )
4142
43+ def process_stream_signal (signal_type = None , stream_id = None , data_record = None , error_msg = None ):
44+ # More info about `stream_signals`:
45+ # https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/wiki/%60stream_signals%60
46+ print (f"Received stream_signal for stream '{ ubwa_manager .get_stream_label (stream_id = stream_id )} ': "
47+ f"{ signal_type } - { stream_id } - { data_record } - { error_msg } " )
48+
4249if __name__ == "__main__" :
4350 logging .basicConfig (level = logging .DEBUG ,
4451 filename = os .path .basename (__file__ ) + '.log' ,
@@ -48,7 +55,9 @@ async def handle_socket_message(stream_id=None):
4855
4956 # To use this library you need a valid UNICORN Binance Suite License:
5057 # https://shop.lucit.services
51- with BinanceWebSocketApiManager (exchange = 'binance.com-futures' ) as ubwa_manager :
58+ with BinanceWebSocketApiManager (exchange = 'binance.com-futures' ,
59+ output_default = "dict" ,
60+ process_stream_signals = process_stream_signal ) as ubwa_manager :
5261 try :
5362 asyncio .run (binance_api (ubwa_manager ))
5463 except KeyboardInterrupt :
0 commit comments