LUCIT-Systems-and-Development / unicorn-fy

A Python SDK by LUCIT to convert received raw data from crypto exchange API endpoints into well-formed python dictionaries.
https://unicorn-fy.docs.lucit.tech
MIT License
54 stars 20 forks source link

Unhandled exception with UnicornFy #43

Closed casper-hansen closed 10 months ago

casper-hansen commented 2 years ago

Version of this library.

Using v1.41.0 of unicorn websocket and 0.12.2 of unicorn-fy.

Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.

Hardware?

VPS or other cloud hosting

Operating System?

Linux

Python version?

Python3.8

Installed packages

aiohttp                       3.8.1
aiosignal                     1.2.0
aniso8601                     9.0.1
async-timeout                 4.0.2
attrs                         22.1.0
autobahn                      22.6.1
Automat                       20.2.0
backports.zoneinfo            0.2.1
Backtesting                   0.3.2
binance-futures-connector     3.1.1
bokeh                         2.4.3
certifi                       2022.5.18.1
cffi                          1.15.1
charset-normalizer            2.0.12
cheroot                       8.6.0
click                         8.1.3
colorama                      0.4.5
constantly                    15.1.0
cryptography                  37.0.4
cycler                        0.11.0
dateparser                    1.1.1
et-xmlfile                    1.1.0
Flask                         2.1.2
Flask-RESTful                 0.3.9
fonttools                     4.34.3
frozenlist                    1.3.0
hyperlink                     21.0.0
idna                          3.3
importlib-metadata            4.12.0
incremental                   21.3.0
itsdangerous                  2.1.2
jaraco.functools              3.5.1
Jinja2                        3.1.2
kiwisolver                    1.4.3
MarketProfile                 0.2.0
MarkupSafe                    2.1.1
matplotlib                    3.5.2
more-itertools                8.14.0
multidict                     6.0.2
numpy                         1.22.4
openpyxl                      3.0.10
packaging                     21.3
pandas                        1.4.2
pandas-ta                     0.3.14b0
patsy                         0.5.2
Pillow                        9.2.0
pip                           22.1.2
plotly                        5.9.0
plotly-express                0.4.1
psutil                        5.9.1
pyasn1                        0.4.8
pyasn1-modules                0.2.8
pybit                         2.4.0
pycparser                     2.21
pyOpenSSL                     22.0.0
pyparsing                     3.0.9
python-binance                1.0.16
python-dateutil               2.8.2
pytz                          2022.1
pytz-deprecation-shim         0.1.0.post0
PyYAML                        6.0
regex                         2022.3.2
requests                      2.28.0
scipy                         1.9.0
seaborn                       0.11.2
service-identity              21.1.0
setuptools                    61.2.0
six                           1.16.0
statsmodels                   0.13.2
tenacity                      8.0.1
tornado                       6.1
Twisted                       22.4.0
twisted-iocpsupport           1.0.2
txaio                         22.2.1
typing_extensions             4.3.0
tzdata                        2022.1
tzlocal                       4.2
ujson                         5.4.0
unicorn-binance-websocket-api 1.41.0
unicorn-fy                    0.12.2
urllib3                       1.26.9
websocket-client              1.3.2
websockets                    10.3
Werkzeug                      2.1.2
wheel                         0.37.1
wincertstore                  0.2
yarl                          1.7.2
zipp                          3.8.1
zope.interface                5.4.0

Logging output

No response

Processing method?

stream_buffer

Used endpoint?

binance.com-futures-testnet

Issue

This problem happens specifically with .pop_stream_signal_from_stream_signal_buffer(). The issue appears after I open an order with a take profit and stop loss where one of them is filled and the other is canceled.

My question is; how do we handle this error since it cannot be caught as an exception in my handler/thread?

Stacktrace:

Exception in thread _create_stream_thread:  stream_id=708e339568d4-4c94-8349-c19f-2bb85a1e, time=1662466313.6806593:
Traceback (most recent call last):
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\site-packages\unicorn_binance_websocket_api\manager.py", line 529, in _create_stream_thread
    loop.run_until_complete(socket.start_socket())
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\site-packages\unicorn_binance_websocket_api\sockets.py", line 141, in start_socket
    received_stream_data = self.unicorn_fy.binance_com_futures_websocket(received_stream_data_json)
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\site-packages\unicorn_fy\unicorn_fy.py", line 129, in binance_com_futures_websocket
    return UnicornFy.binance_futures_websocket(stream_data_json,
  File "C:\Users\caspe\miniconda3\envs\tradingbot\lib\site-packages\unicorn_fy\unicorn_fy.py", line 647, in binance_futures_websocket
    if stream_data['data']['e'] == 'aggTrade':
KeyError: 'data'