LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
683 stars 164 forks source link

Ticker data key error #73

Closed ghost closed 4 years ago

ghost commented 4 years ago

I'm consistently getting key_error when I try to get data from the json output. For example print(unicorn_fied_stream_data) works But when I try to get the data part such as print(unicorn_fied_stream_data["data"]) it crashes with KeyError: 'data' I guess this is a bug in a newer version because same code works in my older vps.

oliver-zehentleitner commented 4 years ago

Hi Canercak!

This is related to unicorn-fy not to unicorn-binance-websocket-api :)

Anyway - Please tell me the exact channel name / create_stream()-settings you are using.

What shows a print(str(unicorn_fied_stream_data))?

ghost commented 4 years ago

Hi! This is my code. This code works in my mac and ubuntu 19 server. It doesn't work in two new ubuntu 19 servers. oldest_stream_data_from_stream_buffer comes empty so I get key error. It works when I just print oldest_stream_data_from_stream_buffer


binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com")
    binance_websocket_api_manager.create_stream(['ticker'], symbols_to_look )

    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)
            symbol = unicorn_fied_stream_data['data'][0]['symbol']
            fields=[symbol,
                    unicorn_fied_stream_data['data'][0]['event_time'],
                    unicorn_fied_stream_data['data'][0]['price_change'],
                    unicorn_fied_stream_data['data'][0]['price_change_percent'],
                    unicorn_fied_stream_data['data'][0]['last_price'],
                    unicorn_fied_stream_data['data'][0]['best_bid_price'],
                    unicorn_fied_stream_data['data'][0]['best_ask_price'],
                    unicorn_fied_stream_data['data'][0]['total_traded_base_asset_volume'],
                    unicorn_fied_stream_data['data'][0]['total_traded_quote_asset_volume']]

            path = data_path + symbol + '.csv'
            with open(path, 'a') as f:
                writer = csv.writer(f)
                writer.writerow(fields)
ghost commented 4 years ago

I found out version 4.0.0 of unicorn-fy works fine..I'm opening this issue on unicorn-fy