Hi!
I have been playing around with python futures SDK and have got it to work good for calling their restapi, no real issues there. But for my trading i need the user data stream subscription and therefore the sub-client provided by the SDK.
The issue here is that no matter what i do i get the same error. I used the example in the documentation and get this error :
Exception in thread Thread-1:
Traceback (most recent call last):
File “C:\Users\smlma\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 950, in _bootstrap_inner
self.run()
File “C:\Users\smlma\PycharmProjects\BinanceApi\venv\lib\site-packages\binance_futures-1.1.0-py3.9.egg\binance_f\impl\websocketwatchdog.py”, line 42, in run
File “C:\Users\smlma\PycharmProjects\BinanceApi\venv\lib\site-packages\apscheduler-3.7.0-py3.9.egg\apscheduler\schedulers\blocking.py”, line 20, in start
super(BlockingScheduler, self).start(*args, **kwargs)
File “C:\Users\smlma\PycharmProjects\BinanceApi\venv\lib\site-packages\apscheduler-3.7.0-py3.9.egg\apscheduler\schedulers\base.py”, line 150, in start
self.add_executor(self._create_default_executor(), ‘default’)
File “C:\Users\smlma\PycharmProjects\BinanceApi\venv\lib\site-packages\apscheduler-3.7.0-py3.9.egg\apscheduler\schedulers\base.py”, line 763, in create_default_executor
return ThreadPoolExecutor()
File “C:\Users\smlma\PycharmProjects\BinanceApi\venv\lib\site-packages\apscheduler-3.7.0-py3.9.egg\apscheduler\executors\pool.py”, line 50, in init
pool = concurrent.futures.ThreadPoolExecutor(int(max_workers))
File "C:\Users\smlma\AppData\Local\Programs\Python\Python39\lib\concurrent\futures_init.py", line 49, in getattr
from .thread import ThreadPoolExecutor as te
File “C:\Users\smlma\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\thread.py”, line 37, in
threading._register_atexit(_python_exit)
File “C:\Users\smlma\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 1370, in _register_atexit
raise RuntimeError(“can’t register atexit after shutdown”)
RuntimeError: can’t register atexit after shutdown
I have tried to tweak this myself and the same error appears every time. I am by no means an expert in python programming and i am having trouble finding any decent info about this Threading error.
Are there anyone who have experienced the same error or something similar with the sub-client who are willing to share his thoughts about this one?
Nothing else in my setup ( api_keys etc) is the issue as i have doublechecked everything times and times.
Thanks!
Edit:
the code i am trying to use is any of the example codes provided in the docs, for example
import logging
from binance_f import SubscriptionClient
from binance_f.constant.test import *
from binance_f.model import *
from binance_f.exception.binanceapiexception import BinanceApiException
from binance_f.base.printobject import *
logger = logging.getLogger(“binance-futures”)
logger.setLevel(level=logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(’%(asctime)s - %(name)s - %(levelname)s - %(message)s’))
logger.addHandler(handler)
sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key)
def callback(data_type: ‘SubscribeMessageType’, event: ‘any’):
if data_type == SubscribeMessageType.RESPONSE:
print("Event ID: ", event)
elif data_type == SubscribeMessageType.PAYLOAD:
PrintBasic.print_obj(event)
sub_client.unsubscribe_all()
else:
print(“Unknown Data:”)
print()
def error(e: ‘BinanceApiException’):
print(e.error_code + e.error_message)
sub_client.subscribe_mark_price_event(“btcusdt”, callback, error)
I get the error mentioned above, then this one tick:
Event ID: 1614076217779
closeTime:1614076224735
count:371926
eventTime:1614076224738
eventType:24hrTicker
firstId:53275300
high:2222.0
json_parse:<function SymbolTickerEvent.json_parse at 0x000002B7C1B9E5E0>
lastId:53647842
lastPrice:1479.52
lastQty:6.208
low:20.0
open:1819.57
openTime:1613989800000
priceChange:-340.05
priceChangePercent:-18.688
symbol:ETHUSDT
totalTradedBaseAssetVolume:720890.177
totalTradedQuoteAssetVolume:1187451208.85
weightedAvgPrice:1647.2
2021-02-23 11:30:22,968 - binance-futures - ERROR - [Sub][1] Closing normally
2021-02-23 11:30:22,968 - binance-futures - INFO - [Sub][1] Connection event loop down
The same occurs with every subscription function i have tried, modifying the urls and recieve_limit: is_auto_connect=True, receive_limit_ms=3600000, url=“wss://fstream.binance.com”)