@@ -14,7 +14,8 @@ async def binance_api(ubwa):
1414 async def handle_socket_message (stream_id = None ):
1515 while ubwa .is_stop_request (stream_id = stream_id ) is False :
1616 data = await ubwa .get_stream_data_from_asyncio_queue (stream_id = stream_id )
17- print (f"received data:\r \n { data } \r \n " )
17+ print (f"Received data:\r \n { data } \r \n " )
18+
1819 print (f"Starting Stream:" )
1920 api_stream = ubwa .create_stream (api = True ,
2021 api_key = os .getenv ('BINANCE_API_KEY' ),
@@ -23,24 +24,58 @@ async def handle_socket_message(stream_id=None):
2324 process_asyncio_queue = handle_socket_message )
2425 print (f"Commands" )
2526 ubwa .api .spot .get_listen_key (stream_id = api_stream )
27+
2628 ubwa .api .spot .get_server_time (stream_id = api_stream )
27- ubwa .api .spot .get_account_status (stream_id = api_stream )
29+
30+ server_time = ubwa .api .spot .get_server_time (stream_id = api_stream , return_response = True )
31+ print (f"Server Time: { server_time ['result' ]['serverTime' ]} \r \n " )
32+
33+ account_status = ubwa .api .spot .get_account_status (stream_id = api_stream , return_response = True )
34+ print (f"Status of account_status request: { account_status ['status' ]} \r \n " )
35+
2836 orig_client_order_id = ubwa .api .spot .create_order (stream_id = api_stream , price = 1.0 , order_type = "LIMIT" ,
2937 quantity = 15.0 , side = "SELL" , symbol = market )
38+
3039 ubwa .api .spot .create_test_order (stream_id = api_stream , price = 1.2 , order_type = "LIMIT" ,
3140 quantity = 12.0 , side = "SELL" , symbol = market )
41+
3242 ubwa .api .spot .ping (stream_id = api_stream )
33- ubwa .api .spot .get_exchange_info (stream_id = api_stream , symbols = [market , ])
34- ubwa .api .spot .get_order_book (stream_id = api_stream , symbol = market , limit = 2 )
35- ubwa .api .spot .get_aggregate_trades (stream_id = api_stream , symbol = market )
36- ubwa .api .spot .get_historical_trades (stream_id = api_stream , symbol = market )
37- ubwa .api .spot .get_klines (stream_id = api_stream , symbol = market , interval = "1m" )
38- ubwa .api .spot .get_ui_klines (stream_id = api_stream , symbol = market , interval = "1d" )
39- ubwa .api .spot .get_recent_trades (stream_id = api_stream , symbol = market )
40- ubwa .api .spot .cancel_order (stream_id = api_stream , symbol = market , orig_client_order_id = orig_client_order_id )
43+
44+ exchange_info = ubwa .api .spot .get_exchange_info (stream_id = api_stream , symbols = [market , ], return_response = True )
45+ print (f"Status of exchange_info request: { exchange_info ['status' ]} \r \n " )
46+
47+ order_book = ubwa .api .spot .get_order_book (stream_id = api_stream , symbol = market , limit = 2 , return_response = True )
48+ print (f"Orderbook, lastUpdateId={ order_book ['result' ]['lastUpdateId' ]} : { order_book ['result' ]['asks' ]} , "
49+ f"{ order_book ['result' ]['bids' ]} \r \n " )
50+
51+ aggregate_trades = ubwa .api .spot .get_aggregate_trades (stream_id = api_stream , symbol = market , return_response = True )
52+ print (f"aggregate_trades: { aggregate_trades ['result' ][:5 ]} \r \n " )
53+
54+ historical_trades = ubwa .api .spot .get_historical_trades (stream_id = api_stream , symbol = market , return_response = True )
55+ print (f"historical_trades: { historical_trades ['result' ][:5 ]} \r \n " )
56+
57+ recent_trades = ubwa .api .spot .get_recent_trades (stream_id = api_stream , symbol = market , return_response = True )
58+ print (f"recent_trades: { recent_trades ['result' ][:5 ]} \r \n " )
59+
60+ klines = ubwa .api .spot .get_klines (stream_id = api_stream , symbol = market , interval = "1m" , return_response = True )
61+ print (f"A few klines: { klines ['result' ][:5 ]} \r \n " )
62+
63+ ui_klines = ubwa .api .spot .get_ui_klines (stream_id = api_stream , symbol = market , interval = "1d" , return_response = True )
64+ print (f"A few ui_klines: { ui_klines ['result' ][:5 ]} \r \n " )
65+
66+ replaced_client_order_id = ubwa .api .spot .cancel_and_replace_order (stream_id = api_stream , price = 1.1 ,
67+ order_type = "LIMIT" ,
68+ quantity = 15.0 , side = "SELL" , symbol = market ,
69+ cancel_orig_client_order_id = orig_client_order_id )
70+
71+ ubwa .api .spot .cancel_order (stream_id = api_stream , symbol = market , orig_client_order_id = replaced_client_order_id )
72+
4173 ubwa .api .spot .get_open_orders (stream_id = api_stream , symbol = market )
74+
4275 ubwa .api .spot .get_open_orders (stream_id = api_stream )
76+
4377 ubwa .api .spot .cancel_open_orders (stream_id = api_stream , symbol = market )
78+
4479 ubwa .api .spot .get_order (stream_id = api_stream , symbol = market , orig_client_order_id = orig_client_order_id )
4580
4681 print (f"Finished! Waiting for responses:" )
@@ -54,11 +89,13 @@ async def handle_socket_message(stream_id=None):
5489 filename = os .path .basename (__file__ ) + '.log' ,
5590 format = "{asctime} [{levelname:8}] {process} {thread} {module}: {message}" ,
5691 style = "{" )
92+
93+ # Loading os.getenv() vars from .env
5794 load_dotenv ()
5895
5996 # To use this library you need a valid UNICORN Binance Suite License:
6097 # https://shop.lucit.services
61- with BinanceWebSocketApiManager (exchange = 'binance.com' ) as ubwa_manager :
98+ with BinanceWebSocketApiManager (exchange = 'binance.com' , output_default = "dict" ) as ubwa_manager :
6299 try :
63100 asyncio .run (binance_api (ubwa_manager ))
64101 except KeyboardInterrupt :
0 commit comments