python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

Error running sample websocket code

Open k128 opened this issue 2 years ago • 12 comments

Describe the bug When I run (part of) the example ThreadedWebsocketManagerCode, I get an error.

To Reproduce Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

from binance import ThreadedWebsocketManager symbol = 'BNBBTC' twm = ThreadedWebsocketManager() twm.start() streams = ['bnbbtc@miniTicker', 'bnbbtc@bookTicker'] def handle_socket_message(msg): ... print(f"message type: {msg['e']}") ... print(msg) ... twm.start_multiplex_socket(callback=handle_socket_message, streams=streams) 'streams=bnbbtc@miniTicker/bnbbtc@bookTicker' Task exception was never retrieved future: <Task finished name='Task-5' coro=<ThreadedApiManager.start_listener() done, defined at C:\Program Files\Python39\lib\site-packages\binance\threaded_stream.py:42> exception=KeyError('e')> Traceback (most recent call last): File "C:\Program Files\Python39\lib\site-packages\binance\threaded_stream.py", line 52, in start_listener callback(msg) File "", line 2, in handle_socket_message KeyError: 'e'

Environment (please complete the following information):

  • Python version: 3.9.2
  • Virtual Env: command prompt
  • OS: Windows 10
  • python-binance version: 1.0.15

k128 avatar Nov 13 '21 05:11 k128

I have the same problem. I think it's because of python removed a parameter for async Queue method.

The problem is already fixed in websockets==10.0+.

But you cannot simply install the new version of websockets python-binance 1.0.15 requires websockets==9.1

rever96 avatar Nov 15 '21 10:11 rever96

But you cannot simply install the new version of websockets python-binance 1.0.15 requires websockets==9.1

So, python-binance needs to be updated to use websockets 10+?

k128 avatar Nov 15 '21 14:11 k128

yes, they have to update it. I read they didn't because of a bad comunication with AWS using websockets 10.0, but they fixed it in 10.1 So... i think python-binance could update to websockets 10.1

rever96 avatar Nov 16 '21 08:11 rever96

This has not been fixed as of February 2022.

luciolle avatar Feb 15 '22 13:02 luciolle

same problem here , upgraded to websockets 10.1 and still not working.. was anyone able to fix it , or AVOID IT ?

PabloBorda avatar Apr 08 '22 22:04 PabloBorda

Same problem: python-binance==1.0.16 && websockets==10.3

pouyaGit avatar May 19 '22 19:05 pouyaGit

Any update on this issue?

guy-landry avatar May 21 '22 13:05 guy-landry

Any update on this issue?

No updates as I'm following. You can try ccxt untill the issue is resolved.

pouyaGit avatar May 21 '22 18:05 pouyaGit

Is there any workaround, like using BinanceSocketManager ?

Tigzy avatar May 31 '22 07:05 Tigzy

Any solution yet

obi-somu avatar Aug 31 '22 01:08 obi-somu

Use a lower version, v15 preferably

obi-somu avatar Sep 11 '22 19:09 obi-somu

As far as I know python 3.9, 3.10 + it's not that compatible with python 15 and 16. For me it's working with python 3.8 environment and binance-python==1.0.15 and websocket 9.1

SorinDn avatar Feb 20 '23 21:02 SorinDn