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

Bybit tickers request endpoint and example strategy #1403

Merged
merged 10 commits into from
Dec 13, 2023

Conversation

filipmacek
Copy link
Member

@filipmacek filipmacek commented Dec 9, 2023

Pull Request

  • created tickers endpoint and tested it in Bybit adapter integration tests
  • created method fetch_send_tickers in BybitDataClient that uses this endpoint
  • registered custom endpoint bybit.data.tickers so that strategies and other components can fetch tickers data from Bybit, when requesting it from request_data method
  • created a simple RequestDemoStrategy in bybit examples folder, that showcases the usage of this endpoint and also shows how to wire up the clock timer so that it can fetch data from this endpoint periodically
  • finished generate_position_status_reports

When running this demo strategy you get printed tickers response for predefined instrument every 10 seconds

2023-12-12T20:17:10.083335001Z [INF] TESTER-001.RequestDemoStrategy-000: BybitTickerData(symbol='ETHUSDT', bid1Price='2177.26', bid1Size='1568.93', ask1Price='2177.27', ask1Size='4538.99', lastPrice='2177.27', highPrice24h='2243.53', lowPrice24h='2168.28', turnover24h='19102057640.1569', volume24h='8634450.0400')
2023-12-12T20:17:18.575656001Z [INF] TESTER-001.RequestDemoStrategy-000: [REQ]--> DataRequest(BybitTickerData{'symbol': Symbol('ETHUSDT-LINEAR')}).

@filipmacek filipmacek added python Pull requests that update Python code adapter Nautilus integration with external systems labels Dec 9, 2023
@filipmacek filipmacek self-assigned this Dec 9, 2023
super().__init__()
self.interval = config.interval
self.instrument_id = InstrumentId.from_str(config.instrument_id)
self.linear_request_ticker_uuid = UUID4()
Copy link
Member

Choose a reason for hiding this comment

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

Each request should have a unique UUID4, it could cause downstream issues to be hanging onto the request_id reference and potentially reusing it with several in-flight

Copy link
Member Author

Choose a reason for hiding this comment

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

Delete this, this demo strategy is not much simpler it uses request_data and listens on on_historical_method callback


def on_data(self, data: DataResponse):
## check generic data response by uuid
if data.correlation_id == self.linear_request_ticker_uuid:
Copy link
Member

Choose a reason for hiding this comment

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

We can use some other method to know if this is a request ticker response.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pls check again the new implementation

@filipmacek filipmacek force-pushed the bybit-ticker-request-endpoint branch 2 times, most recently from 5396626 to 6d6af21 Compare December 12, 2023 20:31
@filipmacek filipmacek force-pushed the bybit-ticker-request-endpoint branch 3 times, most recently from 2646619 to 6b51269 Compare December 12, 2023 20:36
@filipmacek filipmacek force-pushed the bybit-ticker-request-endpoint branch 3 times, most recently from 5e77731 to 86cdefb Compare December 12, 2023 20:47


class RequestDemoStrategyConfig(StrategyConfig, frozen=True):
instrument_id: str
Copy link
Member

Choose a reason for hiding this comment

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

We can also type as InstrumentId now for configs.

return get_env_key("BYBIT_TESTNET_API_KEY")
key = get_env_key("BYBIT_TESTNET_API_KEY")
if not key:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't get_env_key raise this exception already if not found?

from nautilus_trader.core.data import Data


class BybitTickerData(Data):
Copy link
Member

Choose a reason for hiding this comment

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

If you make this a type of Ticker, then you don't need to define a custom data type, and data will be returned through the normal Ticker methods and channels (see Binance for a similar pattern).

Copy link
Member

Choose a reason for hiding this comment

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

I don't see where we're initializing ts_init or ts_event?

@cjdsellers cjdsellers merged commit ab5472b into develop Dec 13, 2023
13 checks passed
@cjdsellers cjdsellers deleted the bybit-ticker-request-endpoint branch December 13, 2023 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter Nautilus integration with external systems python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants