Skip to navigation

Cancel Order

View as MarkdownOpen in Claude

Introduction

An order can be cancelled from the API with the functions EClient.cancelOrder and EClient.reqGlobalCancel.

EClient.cancelOrder can only be used to cancel an order that was placed originally by a client with the same client ID (or from TWS for client ID 0).

EClient.reqGlobalCancel will cancel all open orders, regardless of how they were originally placed.


Cancel Individual Order

EClient.cancelOrder(orderId, orderCancel)

Cancels an active order placed by from the same API client ID.

Note: API clients cannot cancel individual orders placed by other clients. Only reqGlobalCancel is available.

orderId
int

Specify which order should be cancelled by its identifier.

orderCancel
orderCancel

An OrderCancel object that can receive the manualOrderCancelTime, manualOrderIndicator, and extOperator fields. See OrderCancel Reference for more insight on the OrderCancel class.


self.cancelOrder(orderId, OrderCancel())

Cancel All Open Orders

EClient.reqGlobalCancel()

This method will cancel ALL open orders including those placed directly from TWS.

orderCancel
orderCancel

An OrderCancel object that can receive the manualOrderCancelTime, manualOrderIndicator, and extOperator fields. See OrderCancel Reference for more insight on the OrderCancel class.


self.reqGlobalCancel(OrderCancel())