Cancel or Modify Orders
cancel_order Cancel Order
TradeClient.cancel_order(account=None, id=None, order_id=None)
Description
Cancel a submitted order. Order cancellation, like order placement, is executed asynchronously. After calling this command, it indicates that the cancellation request was sent successfully, and the cancellation execution will be processed asynchronously.
After submitting an order using TradeClient.place_order, the submitted order will enter various states depending on different circumstances. Orders that have been filled or rejected by the system cannot be canceled. Only orders in submitted or partially filled states can be canceled. Please refer to the description of the TradeClient.get_order method to understand the possible order states.
For batch orders, you can use TradeClient.get_open_orders to get the list of pending orders and cancel them one by one. For orders that have already been requested for cancellation, do not repeat the request. After executing the cancellation command, wait for a period of time and check the pending orders again.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | str | No | Account ID, if not provided, the default account from client_config will be used |
| id | int | Yes | Global order ID, it is recommended to use the id field for cancel order operations. After place_order, you can obtain it through Order.id |
| order_id | int | No | Local order_id, can be obtained through Order.order_id |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
# Assuming order id is 26731241425469440
trade_client.cancel_order(id=26731241425469440)modify_order Modify Order
TradeClient.modify_order(order, quantity=None, limit_price=None, aux_price=None, trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None, outside_rth=None, **kwargs)
Description
Modify a submitted order. Order type modification is not supported. See the table below for specific modifiable fields.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| order | Order | Yes | The Order object to be modified (tigeropen.trade.domain.order.Order) |
| quantity | int | No | Modified order quantity |
| limit_price | float | No | Modified limit price, required when order_type is LMT, STP, STP_LMT |
| aux_price | float | No | For stop limit orders, represents trigger price; for trailing stop orders, represents price difference. Required when order_type is STP, STP_LMT |
| trail_stop_price | float | No | Required when order_type is TRAIL, the price that triggers the stop loss order |
| trailing_percent | float | No | Trailing stop order percentage, when order_type is TRAIL, aux_price and trailing_percent are mutually exclusive |
| time_in_force | str | No | Order validity period, can only be 'DAY' (valid for the day) or 'GTC' (valid until canceled), defaults to 'DAY' |
| outside_rth | bool | No | Whether to allow pre-market and after-hours trading (US stocks only) |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
# Assuming order id is: 26731241425469440
order = trade_client.get_order(id=26731241425469440)
trade_client.modify_order(order, quantity=2, limit_price=105.0)Updated 1 day ago
