Cancel or Modify Orders
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
Arguments | Type | Description |
---|---|---|
account | str | Account id, if left empty, this method witll use the default account id defined in client_config |
id | int | Order 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_id | int | Local order id. Accessible with Order.order_id |
secret_key | str | Secret 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
Arguments | Type | Description |
---|---|---|
order | Order | Order object that needs to be modified(tigeropen.trade.domain.order.Order) |
quantity | int | New quantity |
limit_price | float | New limit price. Required when order_type is LMT/STP/STP_LMT |
aux_price | float | New stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT |
trail_stop_price | float | Trailing activation price for trailing stop orders |
trailing_percent | float | Trailing 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_force | str | Time in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel |
outside_rth | bool | if trade outside regular trading hours (only applicable to U.S. market) |
secret_key | str | Secret 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