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

Fix generating cancel rejections for dYdX #1982

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions nautilus_trader/adapters/dydx/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ async def _cancel_all_orders(self, command: CancelAllOrders) -> None:
client_order_id=order.client_order_id,
)

async def _cancel_short_term_orders(self, orders: list[Order]) -> None:
async def _cancel_short_term_orders(self, orders: list[Order]) -> None: # noqa: C901
"""
Cancel multiple short order terms at once.
"""
Expand Down Expand Up @@ -1260,14 +1260,16 @@ async def _cancel_short_term_orders(self, orders: list[Order]) -> None:
)
if not retry_manager.result:
self._log.error(f"Failed to cancel batch of orders: {retry_manager.message}")
self.generate_order_cancel_rejected(
strategy_id=order.strategy_id,
instrument_id=order.instrument_id,
client_order_id=order.client_order_id,
venue_order_id=order.venue_order_id,
reason=retry_manager.message,
ts_event=self._clock.timestamp_ns(),
)

for order in orders:
self.generate_order_cancel_rejected(
strategy_id=order.strategy_id,
instrument_id=order.instrument_id,
client_order_id=order.client_order_id,
venue_order_id=order.venue_order_id,
reason=retry_manager.message,
ts_event=self._clock.timestamp_ns(),
)

async def _cancel_order_single(
self,
Expand Down
41 changes: 27 additions & 14 deletions nautilus_trader/adapters/dydx/grpc/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,22 @@ async def batch_cancel_orders(
"""
Batch cancels orders for a subaccount.

Args:
wallet (Wallet): The wallet to use for signing the transaction.
wallet_address (str): The dYdX wallet address.
subaccount (int): The subaccount number.
short_term_cancels (List[OrderBatch]): List of OrderBatch objects containing the orders to cancel.
good_til_block (int): The last block the short term order cancellations can be executed at.
Parameters
----------
wallet : Wallet
The wallet to use for signing the transaction.
wallet_address : str
The dYdX wallet address.
subaccount : int
The subaccount number.
short_term_cancels : list[OrderBatch]
List of OrderBatch objects containing the orders to cancel.
good_til_block : int
The last block the short term order cancellations can be executed at.

Returns:
Returns
-------
BroadcastTxResponse
The response from the transaction broadcast.

"""
Expand Down Expand Up @@ -419,15 +427,20 @@ async def cancel_order(
"""
Cancel an order.

Args:
----
wallet (Wallet): The wallet to use for signing the transaction.
order_id (OrderId): The ID of the order to cancel.
good_til_block (int, optional): The block number until which the order is valid. Defaults to None.
good_til_block_time (int, optional): The block time until which the order is valid. Defaults to None.
Parameters
----------
wallet : Wallet
The wallet to use for signing the transaction.
order_id : OrderId
The ID of the order to cancel.
good_til_block : int, optional
The block number until which the order is valid. Defaults to None.
good_til_block_time: int, optional
The block time until which the order is valid. Defaults to None.

Returns:
Returns
-------
BroadcastTxResponse
The response from the transaction broadcast.

"""
Expand Down
Loading