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

Add support of stop limit and stop market orders for dYdX #2069

Merged
merged 39 commits into from
Dec 7, 2024

Conversation

Saransh-Bhandari
Copy link
Contributor

This PR introduces support for Stop Limit and Stop Market order types in the nautilus_trader dYdX adapter. Key updates include:

  • Added the is_conditional_order flag to identify conditional orders.
  • Mapped new DYDXOrderStatus.UNTRIGGERED to OrderStatus.ACCEPTED.
  • Updated _submit_order_single to support STOP_LIMIT and STOP_MARKET order types, including handling trigger_price.
  • Introduced a new method calculate_conditional_order_trigger_subticks to compute trigger prices in subticks for conditional orders.
  • Extended the create_order method to include conditional_order_trigger_subticks and trigger_price.

See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
See release notes.
@CLAassistant
Copy link

CLAassistant commented Nov 22, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@davidsblom davidsblom left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Much appreciated. Did you manage to test this with the testnet or production network?

@@ -1027,7 +1027,7 @@ async def _submit_order_single(self, order) -> None:
)
return

if dydx_order_tags.is_short_term_order:
if dydx_order_tags.is_short_term_order and not dydx_order_tags.is_conditional_order:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering why an additional order tag is required. Can we also use the order type directly?

Choose a reason for hiding this comment

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

we can create a condition with order type. but as the structure followed in the code with the order tag we used the same if required we can change it .
please let us know what you suggest.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought to keep it simple for users and to have minimal changes between the nautilus api and dydx specific tags. Can also change it in a follow up commit.

@@ -1071,11 +1078,18 @@ async def _submit_order_single(self, order) -> None:
}

price = 0
trigger_price = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps merge the latest develop branch into your branch. I've made similar changes too but haven't gotten to thoroughly testing it yet.

Choose a reason for hiding this comment

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

yes we merged the develop branch in to ours.
we are currently testing it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great! Thanks.

@cjdsellers cjdsellers changed the base branch from master to develop December 5, 2024 06:59
@cjdsellers
Copy link
Member

Hi @Saransh-Bhandari and @Akshay-deqode

Thanks for the contribution! we just need the CLA signing to be able to merge (see the CLAassistant comment above).

@cjdsellers cjdsellers changed the title [WIP] Add support of stop limit and stop market dydx Add support of stop limit and stop market orders for dYdX Dec 6, 2024
@@ -1090,7 +1098,10 @@ async def _submit_order_single(self, order: Order) -> None:
if order.order_type == OrderType.LIMIT:
price = order.price.as_double()
elif order.order_type == OrderType.MARKET:
price = 0
if order.side == OrderSide.BUY:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to make this more generic. This the explanation from support of dydx:

There are a few possible reasons why the SDK allows setting a price for a market order:

  1. Price slippage protection: By setting a price for a market order, you can limit the potential price slippage. For example, if you set a price of $100 for a market buy order, the order will only be executed if the market price is at or below $100. If the market price is above $100, the order will not be executed.

Choose a reason for hiding this comment

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

yes actually I just added this to test if it working or not.
for a fix we can have a oracle price with +- 0.1% (configurable) slippage.

@@ -240,6 +240,7 @@ def create_order(
good_til_block: int | None = None,
good_til_block_time: int | None = None,
execution: OrderExecution = OrderExecution.DEFAULT,
conditional_order_trigger_subticks: int = 0,
Copy link
Collaborator

@davidsblom davidsblom Dec 7, 2024

Choose a reason for hiding this comment

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

I believe conditional_order_trigger_subticks can be removed. It is overwritten by trigger_price.

@@ -24,6 +24,7 @@ class DYDXOrderTags(NautilusConfig, frozen=True, repr_omit_defaults=True):

is_short_term_order: bool = True
num_blocks_open: int = 20
is_conditional_order: bool = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

This flag is probably not necessary. Only checking the order type is more robust if the end user forgets to set this property.

Choose a reason for hiding this comment

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

Yes , I feel so ,this can be simplified using the order type only I am updating it accordingly

Copy link

codspeed-hq bot commented Dec 7, 2024

CodSpeed Performance Report

Merging #2069 will not alter performance

Comparing Alfred-hq:master (f978a3b) with develop (865517b)

Summary

✅ 52 untouched benchmarks

@cjdsellers cjdsellers merged commit 4fb320b into nautechsystems:develop Dec 7, 2024
11 checks passed
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.

5 participants