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

Update "outboundAccountPosition" not supported #11

Closed bmschwartz closed 3 years ago

bmschwartz commented 4 years ago

Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])

Select one:

Environment

Operating System? (include version)

Exact Python Version?

Python 3.8.5

Pip Version?

pip 20.1.1

Description of your issue

I found that unicorn_fy does not support the outboundAccountPosition socket update. The fix is pretty straightforward and I can create a PR or just use what I put in the comments here

Traceback (most recent call last):
  File "/Users/bschwartz/.pyenv/versions/3.8.5/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/bschwartz/.pyenv/versions/3.8.5/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "./project/exchange_account.py", line 23, in print_stream_data_from_stream_buffer
    stream_data = UnicornFy.binance_com_websocket(received_stream_data_json)
  File "/.../venv/lib/python3.8/site-packages/unicorn_fy/unicorn_fy.py", line 125, in binance_com_websocket
    return UnicornFy.binance_websocket(stream_data_json, exchange="binance.com", show_deprecated_warning=False)
  File "/.../venv/lib/python3.8/site-packages/unicorn_fy/unicorn_fy.py", line 246, in binance_websocket
    if stream_data['data']['e'] == 'aggTrade':
KeyError: 'data'

Fix

In unicorn_fy/unicorn_fy.py

On line 204 beneath the executionReport block

elif stream_data['e'] == 'outboundAccountPosition':
    stream_data = {'data': stream_data}

On line 441 beneath the outboundAccountInfo block:

elif stream_data['data']['e'] == 'outboundAccountPosition':
    unicorn_fied_data = {'stream_type': '!userData@arr',
                            'event_type': stream_data['data']['e'],
                            'event_time': stream_data['data']['E'],
                            'last_update_time': stream_data['data']['u'],
                            'balances': []}
    for item in stream_data['data']['B']:
        new_item = {'asset': item['a'],
                    'free': item['f'],
                    'locked': item['l']}
        unicorn_fied_data['balances'] += [new_item]
CryptoFuturesAU commented 3 years ago

When will this be available in the main package? Thank you

oliver-zehentleitner commented 3 years ago

@bmschwartz Thanks you very much!

oliver-zehentleitner commented 3 years ago

Thank you! https://github.com/oliver-zehentleitner/unicorn_fy/releases/tag/0.5.0