kucoin-python-sdk icon indicating copy to clipboard operation
kucoin-python-sdk copied to clipboard

Private webscoket connection never connects

Open maxbot1-bot opened this issue 3 years ago • 5 comments

hi,

im using the following bit of code async def deal_msg(msg): print (msg) ws_client = await KucoinWsClient.create(None, client, deal_msg, private=True) await ws_client.subscribe('/account/balance') while True: await asyncio.sleep(5)

The code just goes into a loop at does nothing. I am not receiving any errors stating that the topic is bad I can use the REST api just fine to see my account balance I can also use the socket connection for market data with private='False'

Thanks a lot for your help

maxbot1-bot avatar Jun 06 '21 09:06 maxbot1-bot

I'm not sure but from what I understand of the documentation the '/account/balance' stream will only shows changes of your balance. If you don't make any transaction it's normal that the streams shows nothing (Again I'm not sure about being right)

Yogalholic avatar Jun 11 '21 14:06 Yogalholic

I cant even get mine to connect when using private=True

I end up with websockets.exceptions.ConnectionClosedError: no close frame received or sent

onxb avatar Nov 14 '21 19:11 onxb

I cant even get mine to connect when using private=True

I end up with websockets.exceptions.ConnectionClosedError: no close frame received or sent

Default ping_interval is 60 seconds in await asyncio.sleep(60), reduce it to 30 seconds and it resolves the problem.

This is because the socket closes when it doesn't send or receive data in 60 seconds. So if the market you have subscribed to has no changes in 60 seconds, then there is no incoming data from server and thus the socket closes. Reducing the ping_interval solves prevents this from happening. (It's useful to note that sockets only send data when the price changes!)

keivanipchihagh avatar Aug 18 '22 05:08 keivanipchihagh

Thank you for the suggestion @keivanipchihagh . I tried it out but it seems to be giving me a different error when I try that.

This is my code:

async def main(loop):
    async def deal_msg(msg):
        if msg['topic'] == '/market/ticker:all':
            my_ticker_callback(Platform.KUCOIN, [msg])

    client = WsToken()
    ws_client = await KucoinWsClient.create(loop, client, deal_msg, private=False)
    await ws_client.subscribe('/market/ticker:all')
    while True:
        await asyncio.sleep(30)


def handler():
    while True:
        try:
            loop = asyncio.get_event_loop()
            loop.run_until_complete(main(loop))
        except Exception as e:
            logger.exception(f"Websocket failed")
            sleep(0.1)

When I use the code above, I run into this error every short while:

<Task finished name='Task-4' coro=<ConnectWebsocket._run() done, defined at ...\site-packages\kucoin\websocket\websocket.py:33> exception=ConnectionClosedError(None, None, None)> got an exception no close frame received or sent
_reconnect over.

When I change the sleep to 30, I get this every short while:

<Task finished name='Task-4' coro=<ConnectWebsocket._run() done, defined at ...\site-packages\kucoin\websocket\websocket.py:33> exception=ConnectionClosedError(None, None, None)> got an exception sent 1011 (unexpected error) keepalive ping timeout; no close frame received
_reconnect over.

Any idea how this can be solved? @maxbot1-bot did you ever get to solve this issue?

itayl2 avatar Jun 08 '23 14:06 itayl2

Thank you for the suggestion @keivanipchihagh . I tried it out but it seems to be giving me a different error when I try that.

This is my code:

async def main(loop):
    async def deal_msg(msg):
        if msg['topic'] == '/market/ticker:all':
            my_ticker_callback(Platform.KUCOIN, [msg])

    client = WsToken()
    ws_client = await KucoinWsClient.create(loop, client, deal_msg, private=False)
    await ws_client.subscribe('/market/ticker:all')
    while True:
        await asyncio.sleep(30)


def handler():
    while True:
        try:
            loop = asyncio.get_event_loop()
            loop.run_until_complete(main(loop))
        except Exception as e:
            logger.exception(f"Websocket failed")
            sleep(0.1)

When I use the code above, I run into this error every short while:

<Task finished name='Task-4' coro=<ConnectWebsocket._run() done, defined at ...\site-packages\kucoin\websocket\websocket.py:33> exception=ConnectionClosedError(None, None, None)> got an exception no close frame received or sent
_reconnect over.

When I change the sleep to 30, I get this every short while:

<Task finished name='Task-4' coro=<ConnectWebsocket._run() done, defined at ...\site-packages\kucoin\websocket\websocket.py:33> exception=ConnectionClosedError(None, None, None)> got an exception sent 1011 (unexpected error) keepalive ping timeout; no close frame received
_reconnect over.

Any idea how this can be solved? @maxbot1-bot did you ever get to solve this issue?

I have the same issue. Any suggestions?

quantokenizer avatar Dec 01 '23 22:12 quantokenizer