Skip to content

Fix error on cancel order for IB #2475

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

Merged
merged 2 commits into from
Mar 28, 2025
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
11 changes: 7 additions & 4 deletions nautilus_trader/adapters/interactive_brokers/client/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ibapi.contract import Contract
from ibapi.execution import Execution
from ibapi.order import Order as IBOrder
from ibapi.order_cancel import OrderCancel as IBOrderCancel
from ibapi.order_state import OrderState as IBOrderState

from nautilus_trader.adapters.interactive_brokers.client.common import AccountOrderRef
Expand Down Expand Up @@ -70,19 +71,21 @@ def place_order_list(self, orders: list[IBOrder]) -> None:
order.orderRef = f"{order.orderRef}:{order.orderId}"
self._eclient.placeOrder(order.orderId, order.contract, order)

def cancel_order(self, order_id: int, manual_cancel_order_time: str = "") -> None:
def cancel_order(self, order_id: int, order_cancel: IBOrderCancel = None) -> None:
"""
Cancel an order through the EClient.

Parameters
----------
order_id : int
The unique identifier for the order to be canceled.
manual_cancel_order_time : str, optional
The timestamp indicating when the order was canceled manually.
order_cancel : OrderCancel object, optional.
The Order cancellation parameters when cancelling an order, when subject to CME Rule 576.

"""
self._eclient.cancelOrder(order_id, manual_cancel_order_time)
if order_cancel is None:
order_cancel = IBOrderCancel()
self._eclient.cancelOrder(order_id, order_cancel)

def cancel_all_orders(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest.mock import Mock

import pytest
from ibapi.order_cancel import OrderCancel as IBOrderCancel

from nautilus_trader.adapters.interactive_brokers.client.common import AccountOrderRef
from nautilus_trader.adapters.interactive_brokers.common import IBContract
Expand Down Expand Up @@ -64,12 +65,12 @@ def test_cancel_order(ib_client):
ib_client._eclient.cancelOrder = MagicMock()

# Act
ib_client.cancel_order(order_id)
ib_client.cancel_order(order_id, IBOrderCancel)

# Assert
ib_client._eclient.cancelOrder.assert_called_with(
order_id,
"",
IBOrderCancel,
)


Expand Down
Loading