Cancel or Modify Orders

About 2 min

cancel_order Cancel Order

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

Description

Cancel an order that has already been placed. Cancellation is similar to placing an order, and it is executed asynchronously. After calling this command, it means that the cancellation request is sent successfully, and the execution of the cancellation will be processed asynchronously. After using TradeClient.place_order to submit an order, the submitted order will enter various states according to different situations. Orders that have been filled or rejected by the system cannot be canceled. Only orders that have been submitted or partially filled can be canceled. Please refer to the description of the TradeClient.get_order method for possible order statuses.

For orders placed in batches, you can use TradeClient.get_open_orders to get the list of orders to be filled, and cancel the orders one by one. For orders that have already been requested to cancel, do not repeat the request. You can wait for a period of time to check the pending orders again during the execution of the cancellation order.

Arguments

ArgumentsTypeDescription
accountstrAccount id, if left empty, this method witll use the default account id defined in client_config
idintOrder id. Using this id to cancel or modify orders is recommended. If you construct the order object locally, this id will be available after placing order to a server.
order_idintLocal order id. Accessible with Order.order_id
secret_keystrSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

Response

If the return value is True, your order has been successfully submitted to the server end

If the return value is False, it means that the request is failed

Example

from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)

is_cancelled = trade_client.cancel_order(id=1230001200123)

Response Example

True

modify_order Modify Order

TradeClient.modify_order(order, quantity, limit_price, aux_price, trail_stop_price, trailing_percent, time_in_force, outside_rth)

Description

Modify an order. Refer to the argument list for parameters that can be modified

Arguments

ArgumentsTypeDescription
orderOrderOrder object that needs to be modified(tigeropen.trade.domain.order.Order)
quantityintNew quantity
limit_pricefloatNew limit price. Required when order_type is LMT/STP/STP_LMT
aux_pricefloatNew stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT
trail_stop_pricefloatTrailing activation price for trailing stop orders
trailing_percentfloatTrailing activation price for trailing stop orders (by percentage), when order_type is set to TRAIL, assigning value to both aux_price and trailing_percent will get an error
time_in_forcestrTime in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel
outside_rthboolif trade outside regular trading hours (only applicable to U.S. market)
secret_keystrSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

Response

bool

True means sucess, False means that the request has failed

Example

from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)



contract = stock_contract(symbol='AAPL', currency='USD')
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=100.0, quantity=1)
trade_client.place_order(order)

is_modified = trade_client.modify_order(order, quantity=2, limit_price=105.0)

Response Example

True
Last update: