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

unable to reconnect when using feature/asyncio branch of websocket.py #526

Open
CyrilleBoullier opened this issue May 28, 2020 · 2 comments

Comments

@CyrilleBoullier
Copy link

CyrilleBoullier commented May 28, 2020

Hello,

I'm using the branch feature/asyncio and it works well.

However, due to binance deconneciton of the websocket, I sometime recieved following messages:

  • ERROR code = 1006 (connection closed abnormally [internal]), no reason
  • websockets.protocol DEBUG client ! timed out waiting for pong

and it seems that the API does not reconnect correctly.

I tried to reproduce it using following snippet:

import asyncio

from binance import AsyncClient, BinanceSocketManager

import logging
from logs_management import logToConsole
logToConsole(logging.INFO)

loop = None

async def main():
global loop

# initialise the client
client = await AsyncClient.create()

# initialise socket manager
bsm = BinanceSocketManager(client, loop)

# setup async callback handler for socket messages
async def handle_evt(msg):
    pair = msg['s']
    print(f'{pair} : {msg}')

# create listener, can use the `ethkey` value to close the socket later
key = await bsm.start_aggtrade_socket('BTCUSDT', handle_evt)

while True:
    print("doing a sleep")
    await asyncio.sleep(20, loop=loop)

if name == "main":

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

The API tries to reconnect, I see the following line in DEBUG mode:
'websocket btcusdt@aggTrade reconnecting 4 reconnects left'

but it never manages to reconnect and the loop continues to write "doing a sleep" with nothing else.

investing in the file websocket.py, it seems that the line

'asyncio.sleep(reconnect_wait)'

never finish.

Could you please inestigate and help me to fix this issue?

Thanks a lot,
Cyrille.

Environment (please complete the following information):

  • Python version: python 3.7
  • Virtual Env: conda 3.7
  • OS: Ubuntu
  • python-binance version:
@CyrilleBoullier
Copy link
Author

Is the branch feature/asyncio still active with developments?

@oliver-zehentleitner
Copy link
Contributor

Hello!
I developed an async websocket lib for binance which reconnects automatic:
https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api
Best regards,
Oliver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants