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

Mini Ticker cannot be converted #3

Closed zyklone92 closed 4 years ago

zyklone92 commented 4 years ago

Hello,

I am using unicorn_fy in combination with the unicorn_binance_websocket_api and am trying to get data via mini ticker subscriptions (https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream).

However, when subscribing to a mini ticker, unicorn_fy is not able to process the stream output and throws an exception:

ERROR:root:Detected unknown data stream format (type2) in module `unicorn_fy`: please report to https://github.com/oliver-zehentleitner/unicorn_fy/issues {'stream': '!miniTicker@arr', 'data': [{'e': '24hrMiniTicker', 'E': 1588516002804, 's': 'BTCUSDT', 'c': '8900.00000000', 'o': '8898.33000000', 'h': '9200.00000000', 'l': '8811.00000000', 'v': '88800.22015400', 'q': '798918007.17006880'}, ... ]} - list indices must be integers or slices, not str

Here is the code I used:

from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
from unicorn_fy.unicorn_fy import UnicornFy

binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com")
binance_websocket_api_manager.create_stream(['!miniTicker'], [])

while True:
    oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
    if oldest_stream_data_from_stream_buffer:
        unicorn_fied_stream_data = UnicornFy.binance_com_websocket(oldest_stream_data_from_stream_buffer)
        print(unicorn_fied_stream_data)

It would be great, if support for mini tickers could be added.

Thanks in advance and best regards, Stefan

Edit: Corrected shown error and used code (they were not complete / reflecting the correct version used)

zyklone92 commented 4 years ago

I just realized that this functionality is already implemented, so this should actually be a bug report, sorry.

I also tested a slightly different version ("miniTicker" instead of "!miniTicker") and am receiving a different Error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\unicorn_fy\unicorn_fy.py", line 288, in binance_websocket
    for item in stream_data['items']:
KeyError: 'items'

This is the code I used:

from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
from unicorn_fy.unicorn_fy import UnicornFy

binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com")
binance_websocket_api_manager.create_stream(['miniTicker'], ['btcusdt', 'bnbbtc', 'ethbtc'])

while True:
    oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
    if oldest_stream_data_from_stream_buffer:
        unicorn_fied_stream_data = UnicornFy.binance_com_websocket(oldest_stream_data_from_stream_buffer)
        print(unicorn_fied_stream_data)

I installed both modules via pip: unicorn-binance-websocket-api 1.12.0 unicorn-fy 0.3.4

Tested on Windows 10, with Python 3.8 and pip 20.1

Best regards, Stefan

oliver-zehentleitner commented 4 years ago

Hi Stefan!

I know, there is some quirks inside the latest version. I am pretty sure it worked in the beginning and got broken through modifications.

I think you can try it with an older version like this one: https://github.com/oliver-zehentleitner/unicorn_fy/tree/cf21fb2c80bf2eee2c3c7d8071284367b8f964e7/unicorn_fy

I will need a while to make a clean fix for this, because i have to finish some things in the websocket lib, after that i will pick up unicorn-fy again.

Best regards, Oliver

oliver-zehentleitner commented 4 years ago

I was not able to test it as much as i want, but I think its stable again: https://pypi.org/project/unicorn-fy/

zyklone92 commented 4 years ago

Hi Oliver,

I updated unicorn-fy and tested both the miniTicker and the miniTicker for all markets (!miniTicker) and they both seem to be working correctly.

Thank you for fixing this so quickly.

Best regards, Stefan

oliver-zehentleitner commented 4 years ago

Your welcome! Best regards!