Closed leonwang908 closed 2 years ago
i can tell from your traceback that you are on an old version of the library. What version are you using?
I downloaded the library from github directly and the version is 2.2.2
@leonwang893 ok can you provide a reproducible example then? the code is referencing book data, but all i see is an add_feed for trade data
Hi, here is my code. btw, I could run my code on version 1.7.0
`from cryptofeed import FeedHandler from cryptofeed.callback import BookCallback, TradeCallback from cryptofeed.defines import BID, ASK, L2_BOOK, TRADES from cryptofeed.exchanges import Bitflyer from datetime import datetime import asyncio import time import pandas as pd import numpy as np
async def book(feed, symbol, book, timestamp, receipt): date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') asks_df = pd.DataFrame.from_dict({'price': book[ASK].keys(), 'size' : book[ASK].values()}) bids_df = pd.DataFrame.from_dict({'price': book[BID].keys(), 'size' : book[BID].values()}) asks_df.insert(0, 'ts', timestamp) bids_df.insert(0, 'ts', timestamp) print(asks_df) await asyncio.sleep(1)
async def trade(feed, symbol, order_id, timestamp, side, amount, price, receipt): current_ts = time.time() date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
def main(): f = FeedHandler() f.add_feed(Bitflyer(symbols=['FX-BTC-JPY'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)})) f.add_feed(Bitflyer(symbols=['FX-BTC-JPY'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)})) f.run()
if name == 'main': main()`
ok ,the error is because your callbacks have the wrong definitions. The callbacks only take 2 params - data object and receipt timestamp. Please fix that. look in examples/demo.py
for an example if you need one
Thanks for your help. I updated my code, and this time I can get data for 'BTC-JPY' but 'FX-BTX-JPY' is still a issue
Traceback (most recent call last): File "C:\Python38\lib\site-packages\cryptofeed\exchange.py", line 137, in std_symbol_to_exchange_symbol return self.normalized_symbol_mapping[symbol] KeyError: 'FX-BTC-JPY'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\bf2.py", line 46, in
you can see all the supported symbols by looking at the list returned by the .symbols()
method
Solved! Big thanks!
Here is for FX-BTC-JPY Press any key to continue . . . Traceback (most recent call last): File "C:\Python38\lib\site-packages\cryptofeed\exchange.py", line 137, in std_symbol_to_exchange_symbol return self.normalized_symbol_mapping[symbol] KeyError: 'FX-BTC-JPY'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "bitflyer.py", line 38, in
main()
File "bitflyer.py", line 33, in main
f.add_feed(Bitflyer(symbols=['FX-BTC-JPY'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)}))
Here is for BTC-JPY Press any key to continue . . . 2022-03-08 03:19:11,404 : ERROR : BITFLYER.ws.3: encountered an exception, reconnecting in 1.0 seconds Traceback (most recent call last): File "C:\Python38\lib\site-packages\cryptofeed\connection_handler.py", line 69, in _create_connection await self._handler(connection, self.handler) File "C:\Python38\lib\site-packages\cryptofeed\connection_handler.py", line 119, in _handler await handler(message, connection, self.conn.last_message) File "C:\Python38\lib\site-packages\cryptofeed\exchanges\bitflyer.py", line 194, in message_handler await self._book(msg, timestamp) File "C:\Python38\lib\site-packages\cryptofeed\exchanges\bitflyer.py", line 184, in _book await self.book_callback(L2_BOOK, self._l2_book[pair], timestamp, raw=msg, delta=delta) File "C:\Python38\lib\site-packages\cryptofeed\feed.py", line 240, in book_callback await self.callback(book_type, book, receipt_timestamp) File "C:\Python38\lib\site-packages\cryptofeed\feed.py", line 251, in callback await cb(obj, receipt_timestamp) File "C:\Python38\lib\site-packages\cryptofeed\callback.py", line 20, in call await self.callback(obj, receipt_timestamp) TypeError: book() missing 3 required positional arguments: 'book', 'timestamp', and 'receipt'