-
Notifications
You must be signed in to change notification settings - Fork 551
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
Add OKX adapter #1951
Add OKX adapter #1951
Conversation
Hey @miller-moore Many thanks for the contribution! On initial glance its looking good, but I'll have a closer look tomorrow. |
def parse_okx_trigger_type(self, trigger_type: OKXTriggerType) -> TriggerType: | ||
return check_dict_keys(trigger_type, self.okx_to_nautilus_trigger_type) | ||
|
||
def parse_okx_order_type(self, ordType: OKXOrderType) -> OrderType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its interesting that crypto exchanges sometimes refer to time in force as "order type" (Polymarket is the same).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed and to fully implement OKX’s algo order capabilities (tp, sl, trailing, contingencies, etc) will require much improved parsing logic.
VALID_SUFFIXES: Final[list[str]] = [ | ||
"-SPOT", | ||
"-MARGIN", | ||
"-LINEAR", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use -PERP
instead of -LINEAR
? (I'd be willing to change Bybit as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objection to your suggestion. One thing to keep in mind is that OKX linear and inverse perps already contain the suffix “-SWAP” on their internal symbols. I kept the Bybit convention to distinguish them explicitly but a simpler alternative is always desirable
passphrase: str | None = None | ||
instrument_types: tuple[OKXInstrumentType] | None = (OKXInstrumentType.SWAP,) | ||
contract_types: tuple[OKXContractType] | None = (OKXContractType.LINEAR,) | ||
base_url_http: str | None = get_http_base_url() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only want to offer one base_url_*
override in the config, otherwise it'll be inferred from whether is_demo
etc (see Bybit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I’ll refactor accordingly
Solid work here, what's the current plan then? I understand you implemented mostly for the perp derivatives - was there anything else you intended to add/improve before this is merged? we could then just iterate and improve from there. |
It would be ideal to contribute the spot and margin product types and whatever adapter changes are needed to support them but my bandwidth for such a contribution does not exist at this time. There is one odd hack or idiosyncrasy I added to prevent OKX websocket connections from being severed, which is an async task that checks for the most recent last pong time received by the websocket and, if the time delta exceeds the allowed time delta (currently hardcoded to 1 minute), a completely new Otherwise, iterate and improve is my best recommendation |
Understood, that is strange on the ping-pong issue. Was there anything else you wanted to add/change before we merge this then? |
Nope! |
Pull Request
Include a summary of the changes.
Adds an OKX adapter
Delete options that are not relevant.
How has this change been tested?
The adapter has only been tested by contrived live experiments with linear perpetual instruments. No code tests have yet been implemented.