Open huncholane opened 1 year ago
Also if you do or do not correct it to msg.get you get the following:
Traceback (most recent call last): File "/home/paul.webster/Work/Trading/activebook/wsreader/kucoin-websocket.py", line 28, inloop.run_until_complete(main()) File "/home/paul.webster/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/home/paul.webster/Work/Trading/activebook/wsreader/kucoin-websocket.py", line 23, in main await asyncio.sleep(60, loop=loop) TypeError: sleep() got an unexpected keyword argument 'loop'
Purely non modified example code(except msg.get):
import asyncio from kucoin_futures.client import WsToken from kucoin_futures.ws_client import KucoinFuturesWsClient async def main(): async def deal_msg(msg): if msg.get('topic') == '/contractMarket/level2:XBTUSDM': print(f'Get XBTUSDM Ticker:{msg["data"]}') elif msg.get('topic') == '/contractMarket/level3:XBTUSDTM': print(f'Get XBTUSDTM level3:{msg["data"]}') # is public # client = WsToken() # is private client = WsToken(key='', secret='', passphrase='', is_sandbox=False, url='') # is sandbox # client = WsToken(is_sandbox=True) ws_client = await KucoinFuturesWsClient.create(loop, client, deal_msg, private=False) await ws_client.subscribe('/contractMarket/level2:XBTUSDM') await ws_client.subscribe('/contractMarket/level3:XBTUSDM') while True: await asyncio.sleep(60, loop=loop) if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(main())
Corrected by changing:
await asyncio.sleep(60, loop=loop)
to:
await asyncio.sleep(60, loop)
The sample needs to change from msg['topic'] to msg.get('topic'). It creates an error that causes the websockets to stop working.