PythonForForex/Binance-api-step-by-step-guide

Restarting socket not working

sniffski opened this issue · 6 comments

There's something wrong with socket restart. It says can't start new thread as old is still running...

There's something wrong with socket restart. It says can't start new thread as old is still running...

I found a solution, it seem I need the redefine the manager:
bsm.stop()
sleep(5)
bsm = ThreadedWebsocketManager()
bsm.start()
bsm.start_symbol_ticker_socket(symbol='BTCUSDT', callback=btc_pairs_trade)

However I'm trying to make a never ending loop to monitor the price and trade but faced another issue:

SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x7f7acb8377f0>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>> Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data) File "/usr/lib/python3.7/asyncio/sslproto.py", line 207, in feed_ssldata
self._sslobj.unwrap()
File "/usr/lib/python3.7/ssl.py", line 767, in unwrap return self._sslobj.shutdown()
ssl.SSLError: [SSL: KRB5_S_INIT] application data after close notify (_ssl.c:2609)

Any ideas what could possibly be wrong here?

This could be an issue with the aiohttp library when attempting a graceful shutdown but messages are still incoming. The easy solution would be to send an unsubscribe message to the Binance websocket though I don't believe Python-binance has a function for that.

Could you send a pip list of your packages? Interested to see which version of Python-binance and aiohttp you are running.

This could be an issue with the aiohttp library when attempting a graceful shutdown but messages are still incoming. The easy solution would be to send an unsubscribe message to the Binance websocket though I don't believe Python-binance has a function for that.

Could you send a pip list of your packages? Interested to see which version of Python-binance and aiohttp you are running.

$ pip list
Package               Version
--------------------- -------------
acme                  0.31.0
aiohttp               3.8.0
aiosignal             1.2.0
asn1crypto            0.24.0
async-timeout         4.0.1
asynctest             0.13.0
attrs                 21.2.0
backports.zoneinfo    0.2.1
bta-lib               1.0.0
certbot               0.31.0
certifi               2018.8.24
chardet               3.0.4
charset-normalizer    2.0.7
ConfigArgParse        0.13.0
configobj             5.0.6
cryptography          2.6.1
dateparser            1.1.0
distro-info           0.21
entrypoints           0.3
frozenlist            1.2.0
future                0.16.0
httplib2              0.11.3
idna                  2.6
josepy                1.1.0
keyring               17.1.1
keyrings.alt          3.1.1
mock                  2.0.0
multidict             5.2.0
numpy                 1.21.4
pandas                1.3.4
parsedatetime         2.4
pbr                   4.2.0
pip                   18.1
pycrypto              2.6.1
pycurl                7.43.0.2
PyGObject             3.30.4
pyOpenSSL             19.0.0
pyRFC3339             1.1
PySimpleSOAP          1.16.2
python-apt            1.8.4.3
python-binance        1.0.15
python-dateutil       2.8.2
python-debian         0.1.35
python-debianbts      2.8.2
pytz                  2019.1
pytz-deprecation-shim 0.1.0.post0
pyxdg                 0.25
regex                 2021.11.10
reportbug             7.5.3-deb10u1
requests              2.21.0
requests-toolbelt     0.8.0
SecretStorage         2.3.1
setuptools            40.8.0
six                   1.12.0
typing-extensions     3.10.0.2
tzdata                2021.5
tzlocal               4.1
ujson                 4.2.0
unattended-upgrades   0.1
urllib3               1.24.1
websockets            9.1
wheel                 0.32.3
yarl                  1.7.2
zope.component        4.3.0
zope.event            4.2.0
zope.hookable         4.0.4
zope.interface        4.3.2
$

Here you are

There is a newer version of aiohttp, upgrading to the latest would be a good place to start.

If that doesn't resolve it, if you can post the code to reproduce it, I will try and take a more detailed look.

Checking up on this issue. If updating aiohttp resolved it or there was another solution I'll close this issue.

Checking up on this issue. If updating aiohttp resolved it or there was another solution I'll close this issue.

It solved the issue! Thanks!