Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError, trying to use binance.websockets

Hi I thought this would be pretty straightforwards but I can't figure it out.

It can't find binance.websockets for whatever reason even though it can find binance.client which should be part of the same package?

import config
import os

from binance.client import Client
from twisted.internet import reactor
from binance.websockets import BinanceSocketManager

Running this import code gives this error

Traceback (most recent call last):
  File "/home/lucho/Documents/cryptoAPIs/binance/importconfig.py", line 6, in <module>
    from binance.websockets import BinanceSocketManager
ModuleNotFoundError: No module named 'binance.websockets

To get the library I installed with pip3

pip3 install python-binance

pip3 install binance-api

like image 201
Lucho Avatar asked May 02 '21 09:05

Lucho


People also ask

Does Binance use Websockets?

The Binance Websocket interface provides access to public data streams (such as all public streams like trade, kline, ticker, depth, bookTicker, forceOrder, compositeIndex and blockheight and also all private user data streams) and private user data streams (e.g. account information).


Video Answer


3 Answers

The BinanceSocketManager is no longer in the websockets file. Change your import to this:

from binance.streams import BinanceSocketManager

This will fix the issue

like image 200
Archangel Avatar answered Oct 22 '22 16:10

Archangel


use this " pip install python-binance==0.7.9 "

like image 35
Piyush Avatar answered Oct 22 '22 17:10

Piyush


If you look into the breaking changes on version 1.0.1 they mention they changes Websockets, so that is probably what you are hitting.

I would just reinstall the latest version "pip install python-binance" and use the up to date examples on their repo: https://github.com/sammchardy/python-binance

like image 2
Gyancarlo Garcia Avatar answered Oct 22 '22 17:10

Gyancarlo Garcia