Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private webscoket connection never connects #25

Open
maxbot1-bot opened this issue Jun 6, 2021 · 5 comments
Open

Private webscoket connection never connects #25

maxbot1-bot opened this issue Jun 6, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@maxbot1-bot
Copy link

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

@Yogalholic
Copy link

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)

@onxb
Copy link

onxb commented Nov 14, 2021

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

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

@keivanipchihagh
Copy link

keivanipchihagh commented Aug 18, 2022

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!)

@itayl2
Copy link

itayl2 commented Jun 8, 2023

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?

@quantokenizer
Copy link

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?

@ISAAC-XXYYZZ ISAAC-XXYYZZ self-assigned this Jul 29, 2024
@ISAAC-XXYYZZ ISAAC-XXYYZZ added the enhancement New feature or request label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants