Kucoin / kucoin-python-sdk

MIT License
40 stars 11 forks source link

Change at websockets for python 3.10 #70

Open facetoface10101980 opened 2 years ago

facetoface10101980 commented 2 years ago

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)

progressivehed commented 2 years ago

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)