中文

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

ParameterTypeRequiredDescription
accountstrNoAccount ID, if not provided, the default account from client_config will be used
idintYesGlobal 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_idintNoLocal 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

ParameterTypeRequiredDescription
orderOrderYesThe Order object to be modified (tigeropen.trade.domain.order.Order)
quantityintNoModified order quantity
limit_pricefloatNoModified limit price, required when order_type is LMT, STP, STP_LMT
aux_pricefloatNoFor stop limit orders, represents trigger price; for trailing stop orders, represents price difference. Required when order_type is STP, STP_LMT
trail_stop_pricefloatNoRequired when order_type is TRAIL, the price that triggers the stop loss order
trailing_percentfloatNoTrailing stop order percentage, when order_type is TRAIL, aux_price and trailing_percent are mutually exclusive
time_in_forcestrNoOrder validity period, can only be 'DAY' (valid for the day) or 'GTC' (valid until canceled), defaults to 'DAY'
outside_rthboolNoWhether 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)