kucoin-python-sdk
kucoin-python-sdk copied to clipboard
Change at websockets for python 3.10
Hi all, i think the inital example at websockets has to be changed for Python 3.10 or there should be at least a note, so:
the following code is deprecated at works until Python 3.9: loop = asyncio.get_event_loop() loop.run_until_complete(main())
For Python 3.10 use instead: loop = asyncio.run(main())
And until Python 3.9 works: while True: await asyncio.sleep(60, loop=loop)
For Python 3.10 use instead (just remove the loop argument): while True: await asyncio.sleep(60)
Hello
I recommend to use the correct example below:
import asyncio from kucoin.client import WsToken from kucoin.ws_client import KucoinWsClient async def main(): async def deal_msg(msg): if msg['topic'] == '/spotMarket/level2Depth5:BTC-USDT': print(msg["data"]) elif msg['topic'] == '/spotMarket/level2Depth5:KCS-USDT': print(f'Get KCS 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 KucoinWsClient.create(None, client, deal_msg, private=False) # await ws_client.subscribe('/market/ticker:BTC-USDT,ETH-USDT') await ws_client.subscribe('/spotMarket/level2Depth5:BTC-USDT,KCS-USDT') while True: await asyncio.sleep(60) if name == "main": loop = asyncio.get_event_loop() loop.run_until_complete(main())
======================================= Also update your websocket module: -m pip install websocket
KuCoin Learning Center (https://t.me/kucoin_learning)
Since this issue has already been addressed and there have been no updates for a long time, we will now close it. If you need any further assistance, feel free to ask!