-
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 support of stop limit and stop market orders for dYdX #2069
Conversation
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.
See release notes.
See release notes.
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.
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: |
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.
Wondering why an additional order tag is required. Can we also use the order type directly?
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.
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.
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 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 |
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.
Perhaps merge the latest develop branch into your branch. I've made similar changes too but haven't gotten to thoroughly testing it yet.
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.
yes we merged the develop branch in to ours.
we are currently testing it.
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.
Great! Thanks.
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). |
@@ -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: |
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 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:
- 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.
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.
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, |
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 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 |
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.
This flag is probably not necessary. Only checking the order type is more robust if the end user forgets to set this property.
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.
Yes , I feel so ,this can be simplified using the order type only I am updating it accordingly
CodSpeed Performance ReportMerging #2069 will not alter performanceComparing Summary
|
This PR introduces support for Stop Limit and Stop Market order types in the
nautilus_trader
dYdX adapter. Key updates include:is_conditional_order
flag to identify conditional orders.DYDXOrderStatus.UNTRIGGERED
toOrderStatus.ACCEPTED
._submit_order_single
to supportSTOP_LIMIT
andSTOP_MARKET
order types, including handlingtrigger_price
.calculate_conditional_order_trigger_subticks
to compute trigger prices in subticks for conditional orders.create_order
method to includeconditional_order_trigger_subticks
andtrigger_price
.