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

new event "listStatus" #19

Closed oliver-zehentleitner closed 3 years ago

oliver-zehentleitner commented 3 years ago

Hello, Sorry for reopening the issue. I have the same error today when listening on UserData Stream. I have verified the version of unicorn-fy, it's 0.6.0.

  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/jean/myriad/projects/pyenv/crypto/lib/python3.7/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 415, in _create_stream_thread
    loop.run_until_complete(socket.start_socket())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "/home/jean/myriad/projects/pyenv/crypto/lib/python3.7/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_socket.py", line 114, in start_socket
    received_stream_data = self.unicorn_fy.binance_com_websocket(received_stream_data_json)
  File "/home/jean/myriad/projects/pyenv/crypto/lib/python3.7/site-packages/unicorn_fy/unicorn_fy.py", line 85, in binance_com_websocket
    return UnicornFy.binance_websocket(stream_data_json, exchange="binance.com", show_deprecated_warning=False)
  File "/home/jean/myriad/projects/pyenv/crypto/lib/python3.7/site-packages/unicorn_fy/unicorn_fy.py", line 249, in binance_websocket
    if stream_data['data']['e'] == 'aggTrade':
KeyError: 'data'

[Update] I have identified the response that causes the error.

{
    "e": "listStatus",
    "E": 1606754342870,
    "s": "BTCUSDT",
    "g": 10610159,
    "c": "OCO",
    "l": "EXEC_STARTED",
    "L": "EXECUTING",
    "r": "NONE",
    "C": "VR0br4b4QJEFkbMqCsDUBJ",
    "T": 1606754342869,
    "O": [{
        "s": "BTCUSDT",
        "i": xxx,
        "c": "xxx"
    }, {
        "s": "BTCUSDT",
        "i": xxx,
        "c": "xxx"
    }]
}

Can you add support for this ? Thanks in advance for your help!

_Originally posted by @giahung24 in https://github.com/oliver-zehentleitner/unicorn_fy/issues/6#issuecomment-735872583_

oliver-zehentleitner commented 3 years ago

@giahung24 From which exchange did you receive that data?

giahung24 commented 3 years ago

@giahung24 From which exchange did you receive that data?

I stream from binance.com (spot/margin) In their API Document, they said:

If the order is an OCO, an event will be displayed named ListStatus in addition to the executionReport event.

oliver-zehentleitner commented 3 years ago

could you post me the original raw data JSON string like:

 data = '{"stream":"btcusdt@trade","data":{"e":"trade","E":1592591955766,"s":"BTCUSDT","t":343719861,"p":"9302.00000000","q":"0.00101900","b":2517144287,"a":2517144235,"T":1592591955765,"m":false,"M":true}}'

thx!

giahung24 commented 3 years ago

These are examples of raw data I get from binance_websocket_api_manager.pop_stream_data_from_stream_buffer() when the KeyError exception occurs:

{"e":"listStatus","E":1606946194410,"s":"ETHUSDT","g":10717037,"c":"OCO","l":"ALL_DONE","L":"ALL_DONE","r":"NONE","C":"i8B7NXuB37QkJ2Vy8f5KHh","T":1606946194409,"O":[{"s":"ETHUSDT","i":2175939815,"c":"electron_648187c31bda49b6a2e81d23ae0"},{"s":"ETHUSDT","i":2175939816,"c":"84wruoWCZdkBUqbqlKfpv6"}]}
{"e":"listStatus","E":1606946303696,"s":"ETHUSDT","g":10717129,"c":"OCO","l":"EXEC_STARTED","L":"EXECUTING","r":"NONE","C":"xbLYz3UmLud2uIYDTqa9Qx","T":1606946303694,"O":[{"s":"ETHUSDT","i":2175947289,"c":"electron_86b14903e6f047bc9869e85e3d2"},{"s":"ETHUSDT","i":2175947290,"c":"qhL7WPy7sENJOhvB6lfoCu"}]}
oliver-zehentleitner commented 3 years ago

This is the converted result:

result: {'stream_type': 'ethusdt@listStatus', 'event_type': 'listStatus', 'event_time': 1606946194410, 'symbol': 'ETHUSDT', 'order_list_id': 10717037, 'contingency_type': 'OCO', 'list_status_type': 'ALL_DONE', 'list_order_status': 'ALL_DONE', 'list_reject_reason': 'NONE', 'list_client_order_id': 'i8B7NXuB37QkJ2Vy8f5KHh', 'transaction_time': 1606946194409, 'objects': [{'symbol': 'ETHUSDT', 'order_id': 2175939815, 'client_order_id': 'electron_648187c31bda49b6a2e81d23ae0'}, {'symbol': 'ETHUSDT', 'order_id': 2175939816, 'client_order_id': '84wruoWCZdkBUqbqlKfpv6'}], 'unicorn_fied': ['binance.com', '0.6.0.dev']}

If you think thats fine too, I can prepare a release!

giahung24 commented 3 years ago

Hi, I think that's good! Glad to have quick reaction from you.

oliver-zehentleitner commented 3 years ago

Its released: https://pypi.org/project/unicorn-fy/