bmoscon / cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler
Other
2.14k stars 668 forks source link

Support for Bybit spot websocket endpoints #933

Closed kieran-mackle closed 5 months ago

kieran-mackle commented 1 year ago

Description of code - what bug does this fix / what feature does this add?

Added support for spot websocket endpoints on Bybit. Current implementation includes trade and orderbook channels.

Testing

To connect to a spot endpoint, specify a standardised spot symbol. See example code below, connecting to both spot and perpetual endpoints for trades and orderbook.

from decimal import Decimal
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Bybit
from cryptofeed.defines import TRADES, L2_BOOK, BID, ASK

async def book(book, receipt_timestamp):
    print(f'Book received at {receipt_timestamp} for {book.exchange} - {book.symbol}, with {len(book.book)} entries. Top of book prices: {book.book.asks.index(0)[0]} - {book.book.bids.index(0)[0]}')
    if book.delta:
        print(f"Delta from last book contains {len(book.delta[BID]) + len(book.delta[ASK])} entries.")
    if book.sequence_number:
        assert isinstance(book.sequence_number, int)

async def trade(t, receipt_timestamp):
    assert isinstance(t.timestamp, float)
    assert isinstance(t.side, str)
    assert isinstance(t.amount, Decimal)
    assert isinstance(t.price, Decimal)
    assert isinstance(t.exchange, str)
    print(f"Trade received at {receipt_timestamp}: {t}")

def main():
    f = FeedHandler()
    f.add_feed(Bybit(symbols=["ETH-USDT", "ETH-USDT-PERP"], channels=[TRADES, L2_BOOK], callbacks={TRADES: trade, L2_BOOK: book}))
    f.run()

if __name__ == '__main__':
    main()
kieran-mackle commented 1 year ago

@bmoscon I used Black. Formatting changes reverted, ready for review.

bmoscon commented 1 year ago

formatting changes persist, will review once they have been resolved

bastienjalbert commented 1 year ago

@bmoscon Are there still formatting issues?

bmoscon commented 1 year ago

@bastienjalbert - there was a merge conflict - i resolved it but now the tests are failing. if @kieran-mackle can fix them I will merge it. I can take a look at fixing them myself but might not get time for a few days. likely the test data for bybit needs to be regenerated and then the expected callback counts will need to be updated in the test case. that may not be all though

adamlansky commented 11 months ago

Hey @kieran-mackle I would love to see this merged - do you think you could look into merge conflict @bmoscon mentioned? Please let me know if you could use a hand here, I would be more than happy to contribute 👍🏼

bastienjalbert commented 8 months ago

Hello @bmoscon, do you need help to finally merge this PR ?

bmoscon commented 8 months ago

@bastienjalbert the tests are failing, if they are fixed, I will merge it, otherwise at some point in the not too distant future I'll close this PR

bastienjalbert commented 7 months ago

@bmoscon I’ll take a look within next days/weeks to make unit test passing.

bmoscon commented 6 months ago

@bastienjalbert let me know if you are still working on this

bastienjalbert commented 5 months ago

@bmoscon Hard to find time lately. I’ll probably work on it, but in fews months.

bmoscon commented 5 months ago

@bastienjalbert feel free to fork off this PR and open a new one when you have time to take it on.