bmoscon / cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler
Other
2.21k stars 682 forks source link

'NoneType' object is not iterable #934

Closed stupidanon closed 1 year ago

stupidanon commented 1 year ago

Describe the bug Request max_depth=500 on Binance spot L2_book feed, but sometimes receive less. This makes creating dataframes weird:

df = pd.DataFrame(
    {
        "exchange": data["exchange"],
        "symbol": data["symbol"],
        "bid_price": [float(k) for k in data["book"]["bid"].keys()],
        "bid_amount": [float(v) for v in data["book"]["bid"].values()],
        "ask_price": [float(k) for k in data["book"]["ask"].keys()],
        "ask_amount": [float(v) for v in data["book"]["ask"].values()],
        "timestamp": str(data["timestamp"]),
    }
)

will yield the error: 'NoneType' object is not iterable

I believe this is relevant?

To Reproduce Steps to reproduce the behavior:

  1. Create a regular feed
f = FeedHandler()
elif exchange == "Binance":
    f.add_feed(
        cryptofeed.exchanges.Binance(
            max_depth=500,
            refresh_snapshot=True,
            symbols=symbols,
            channels=[TRADES, TICKER, L2_BOOK],
            callbacks={
                TICKER: ticker_function,
                TRADES: trades_function,
                L2_BOOK: l2_function,
            },
        )
    )
f.run()
  1. Run print(len(data['book']['bid'].keys())) in the callback after converting data with to_dict() to see <500 appears sometimes

Expected behavior Give length of 500 arrays of bid/ask price/amounts, with 0 as value if no amount.

Operating System:

Cryptofeed Version

stupidanon commented 1 year ago

this is not necessarily a bug in cryptofeed can just check for the rows and work around what response the exchange gives, not much cryptofeed can do, my apologies