5

I'm trying to run the following code from tutorial that I found on jupyter notebook:

from time import sleep

from binance import ThreadedWebsocketManager

btc_price = {'error':False}

def btc_trade_history(msg):

    if (msg['e'] != 'error'):

        print(msg['c'])

        btc_price['last'] = msg['c']

        btc_price['bid'] = msg['b']

        btc_price['last'] = msg['a']

        btc_price['error'] = False

    else:

        btc_price['error'] = True

bsm = ThreadedWebsocketManager()

bsm.start()

bsm.start_symbol_ticker_socket(callback=btc_trade_history, symbol='BTCUSDT')

here is the link to the tutorial itself: https://algotrading101.com/learn/binance-python-api-guide/

I guess, since the tutorial was written, something was changed in binance API, so I get the following error:

CANCEL read_loop Task exception was never retrieved future: <Task finished name='Task-14' coro=<ThreadedApiManager.start_listener() done, defined at C:\Users\myusername\Anaconda3\lib\site-packages\binance\threaded_stream.py:42> exception=RuntimeError("Task <Task pending name='Task-20' coro=<Queue.get() running at C:\Users\myusername\Anaconda3\lib\asyncio\queues.py:163> cb=[_release_waiter(()]>)() at C:\Users\myusername\Anaconda3\lib\asyncio\tasks.py:429]> got Future attached to a different loop")>

Please, explain what's going wrong and how do I fix it?

  • 2
    I am running through the same issue, did you manage to find a solution for it? – Ahmed May 16 '22 at 21:00
  • Have you tried to provide `api_key` and `api_secret` in `ThreadedWebsocketManager(api_key=..., api_secret=...)` according to the source code? https://github.com/sammchardy/python-binance/blob/master/binance/streams.py#L1177 – Fomalhaut Jun 01 '22 at 13:55

2 Answers2

4

Use the version 1.0.15 instead of 1.0.16

Emre
  • 77
  • 1
  • 3
1

There is a discussion on this issue.

Unfortunately, the library python-binance rarely receives updates. It seems that we should not expect a solution to the problem in the near future.

Kuznetsov-M
  • 346
  • 7
  • 18