Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Bybit spot websocket endpoints #933

Closed
wants to merge 12 commits into from

Conversation

kieran-mackle
Copy link

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()
  • - Tested
  • - Changelog updated
  • - Tests run and pass
  • - Flake8 run and all errors/warnings resolved
  • - Contributors file updated (optional)

@kieran-mackle kieran-mackle changed the title Bybit spot Support for Bybit spot websocket endpoints Nov 24, 2022
Copy link
Owner

@bmoscon bmoscon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what formatting tool you used, but undo all the un-necessary formatting changes and then I will review the real changes

@kieran-mackle
Copy link
Author

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

@bmoscon
Copy link
Owner

bmoscon commented Dec 12, 2022

formatting changes persist, will review once they have been resolved

@bastienjalbert
Copy link
Contributor

@bmoscon Are there still formatting issues?

@bmoscon
Copy link
Owner

bmoscon commented Jun 3, 2023

@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
Copy link

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
Copy link
Contributor

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

@bmoscon
Copy link
Owner

bmoscon commented Nov 5, 2023

@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
Copy link
Contributor

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

@bmoscon
Copy link
Owner

bmoscon commented Jan 7, 2024

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

@bastienjalbert
Copy link
Contributor

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

@bmoscon
Copy link
Owner

bmoscon commented Feb 10, 2024

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

@bmoscon bmoscon closed this Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants