From 9824a22148d3adbe1c129229aa7d6b37b4bcb951 Mon Sep 17 00:00:00 2001 From: David Blom Date: Fri, 4 Oct 2024 14:04:52 +0200 Subject: [PATCH] Fix generating cancel rejections for dYdX --- nautilus_trader/adapters/dydx/execution.py | 20 +++++---- nautilus_trader/adapters/dydx/grpc/account.py | 41 ++++++++++++------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/nautilus_trader/adapters/dydx/execution.py b/nautilus_trader/adapters/dydx/execution.py index 41cb9805d3d..d640e40f90a 100644 --- a/nautilus_trader/adapters/dydx/execution.py +++ b/nautilus_trader/adapters/dydx/execution.py @@ -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. """ @@ -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, diff --git a/nautilus_trader/adapters/dydx/grpc/account.py b/nautilus_trader/adapters/dydx/grpc/account.py index 34ed83b415b..d61966e63c8 100644 --- a/nautilus_trader/adapters/dydx/grpc/account.py +++ b/nautilus_trader/adapters/dydx/grpc/account.py @@ -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. """ @@ -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. """