bmoscon / cryptofeed

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

feat(bybit): Add spot support and migrate to API V5 #1017

Closed kosmodromov closed 6 months ago

kosmodromov commented 7 months ago

This PR adds support for the spot market on Bybit exchange and migrate to V5 API.

Updated market data endpoints:

Only linear futures is supported. No inverse futures support. Private endpoints remain unmodified.

from cryptofeed import FeedHandler
from cryptofeed.exchanges import Bybit
from cryptofeed.defines import TRADES, L2_BOOK, BID, ASK, CANDLES, LIQUIDATIONS, TICKER, FUNDING, OPEN_INTEREST, INDEX, FILLS, ORDER_INFO

async def book(d, receipt_timestamp):
    print(f'{receipt_timestamp} for {d.exchange} - {d.symbol}, with {len(d.book)} entries. bid/ask: {d.book.bids.index(0)[0]}/{d.book.asks.index(0)[0]}, delta: {len(d.delta[BID]) + len(d.delta[ASK])} entries')

async def anything(d, receipt_timestamp):
    print(d)

def main():
    f = FeedHandler()
    f.add_feed(Bybit(symbols=["ETH-USDT", "ETH-USDT-PERP"], channels=[TRADES, L2_BOOK], callbacks={TRADES: anything, L2_BOOK: book}))
    f.add_feed(Bybit(symbols=["BTC-USDT-PERP", "XRP-USDC-PERP"], channels=[TRADES, L2_BOOK, FUNDING, OPEN_INTEREST, INDEX],callbacks={TRADES: anything, L2_BOOK: book, FUNDING: anything, OPEN_INTEREST: anything, INDEX: anything}))
    f.run()

if __name__ == '__main__':
    main()

Fixes: #1010 #1012

bmoscon commented 6 months ago

@kosmodromov - thanks for the PR - just one question for you, then we can merge this.