Cancel or Modify Orders

Initialization

All examples on this page assume the following initialization has been completed:

from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import TigerOpenClientConfig

client_config = TigerOpenClientConfig(props_path='your_config_directory_path')
trade_client = TradeClient(client_config)

For details, see Prerequisites.


Cancel Order

TradeClient.cancel_order(account=None, id=None, order_id=None)

Description

Cancel a submitted order. Like order placement, cancellation is asynchronous: a successful call confirms only that the request was submitted.

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. See TradeClient.get_order for possible order states.

For batch orders, use TradeClient.get_open_orders to retrieve pending orders and cancel them individually. Do not submit another cancellation request for an order already pending cancellation. Wait briefly after the request, then check the pending orders again.

Parameters

ParameterTypeRequiredDescription
accountstrNoAccount ID, if not provided, the default account from client_config will be used
idintYesGlobal order ID. The id field is recommended for cancellation operations. After place_order, obtain it from Order.id
order_idintNoLocal order_id, can be obtained through Order.order_id

Returns

Returns the global order ID (int) when the cancellation request is submitted successfully; otherwise raises ApiException. Cancellation is asynchronous, so a returned ID does not mean the order is already canceled. Poll get_order until the status changes from PENDING_CANCEL to CANCELLED.

Example

# Assuming order id is 26731241425469440
trade_client.cancel_order(id=26731241425469440)

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_pricefloatNoNew activation price for a trailing stop order
trailing_percentfloatNoTrailing stop order percentage, when order_type is TRAIL, aux_price and trailing_percent are mutually exclusive
percent_offsetfloatNoNew percentage offset for a trailing stop order
time_in_forcestrNoOrder validity period: DAY, GTC, or GTD; defaults to DAY
outside_rthboolNoWhether to allow pre-market and after-hours trading (US stocks only)

Returns

Returns the global order ID (int) on success; otherwise raises ApiException.

Example

# Assuming order id is: 26731241425469440
order = trade_client.get_order(id=26731241425469440)
trade_client.modify_order(order, quantity=2, limit_price=105.0)

Did this page help you?