Cancel Order

View as MarkdownOpen in Claude

cancel_order_sync(

order_id: Integer. Identifier for the order to cancel. Retrieved from the original [Order Placement](/tws-api/doc/synchronous-api/place-order) or [get_open_orders()](/tws-api/doc/synchronous-api/open-orders).

order: [OrderCancel Object](/tws-api/ref/order-cancel-class-reference). Order cancellation parameters.

timeout: Integer. A default value of 3 seconds is supplied.

)

app.cancel_order_sync(347, OrderCancel())

Upon cancellingan order, a dictionary containing all of the order status’s information will be returned. As the response is static, refer to the [get_open_orders](/tws-api/doc/synchronous-api/open-orders) function more more details on the current order status.

Response Object

{

orderId: Integer. The identifier for the order. Relevant for order tracking, modification, and cancellation.

status: String. The current status of the order. See [Order Status](/tws-api/doc/order-management/order-status/introduction-message) for more details.

filled: Decimal. The total quantity of executed shares for the order.

remaining: Decimal. The total quantity of shares that have yet to execute for the order.

avgFillPrice: Float. The average execution price across fills.

permId: Integer. The permanent identifier for the order. This is calculated based on orderId and client ID for internal order tracking.

parentId: Integer. The orderId for the parent of this contract. Will return 0 unless trading a bracket or OCA order.

lastFillPrice: Float. The price of the most recent execution for the order.

clientId: Integer. The identifier for which client ID the order was placed through. Orders can only be cancelled or modified by their on the [clientId](/tws-api/doc/orders/modifying-orders) they are bound to.

whyHeld: String. In the event an order is held instead of being transmitted, the reason will be documented here.

mktCapPrice: Float. If an order is capped due to it exceeding the market price and the price is automatically modified, the modified price will be returned. Otherwise 0.0 is displayed.

}

{'orderId': 347, 'status': 'PendingCancel', 'filled': Decimal('0'), 'remaining': Decimal('100'), 'avgFillPrice': 0.0, 'permId': 1395073938, 'parentId': 0, 'lastFillPrice': 0.0, 'clientId': 8675309, 'whyHeld': '', 'mktCapPrice': 0.0}