Cancel or Modify Order
C++ HTTP methods return the value of the complete response's
datafield. The outercode,message, andtimestampfields, and thedatafield name itself, are not part of the returnedvalue.
Cancel an Order
value TradeClient::cancel_order(unsigned long long id)
Description
Cancels an unfilled order. The returned order ID confirms only that the cancellation request was submitted; continue querying until the order is Cancelled or reaches another final state, such as a fill that completed first.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | unsigned long long | Yes | Order ID, i.e., order.id |
Return
web::json::value JSON object
Example
#include "tigerapi/trade_client.h"
#include "tigerapi/client_config.h"
using namespace TIGER_API;
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
// Cancel the specified order
value result = trade_client.cancel_order(14275856193552384);
ucout << result.serialize() << std::endl;Response Example
{
"code": 0,
"message": "success",
"timestamp": 1785528000000,
"data": {
"id": 123456,
"orderId": 789012
}
}Rate Limit
- Base rate: 120 requests per minute (counted per TigerId and interface in a 60-second rolling window).
Modify an Order
Description
Modifies an unfilled order. You can update the Order object and submit it, or pass the new values as method arguments. The return value confirms only submission; continue querying and verify that the new terms took effect or the order reached a final state.
Approach 1: Modify Order Object and Submit
value TradeClient::modify_order(Order &order)
| Parameter | Type | Required | Description |
|---|---|---|---|
| order | Order& | Yes | Modified order object |
Approach 2: Specify Modifications via Parameters
value TradeClient::modify_order(Order &order, double limit_price, long total_quantity, double aux_price, double trail_stop_price, double trailing_percent, double percent_offset, utility::string_t time_in_force, bool outside_rth, time_t expire_time)
| Parameter | Type | Required | Description |
|---|---|---|---|
| order | Order& | Yes | Original order object |
| limit_price | double | No | New limit price, default 0 (no change) |
| total_quantity | long | No | New quantity, default 0 (no change) |
| aux_price | double | No | New stop trigger price, default 0 (no change) |
| trail_stop_price | double | No | New trailing stop price, default 0 |
| trailing_percent | double | No | New trailing percentage, default 0 |
| percent_offset | double | No | Percent offset, default 0 |
| time_in_force | utility::string_t | No | Order validity period, default empty |
| outside_rth | bool | No | Allow pre-market and after-hours trading; default false |
| expire_time | time_t | No | Expiry time, default 0 |
Modifiable Fields
| Field | Description |
|---|---|
| total_quantity | Total order quantity |
| limit_price | Limit price |
| aux_price | Stop trigger price |
| trailing_percent | Trailing stop percentage |
| time_in_force | Order validity period |
| outside_rth | Allows pre-market and after-hours trading |
Return
web::json::value JSON object
Example
#include "tigerapi/trade_client.h"
#include "tigerapi/client_config.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"
using namespace TIGER_API;
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
// Place order first
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
Order order = OrderUtil::limit_order(config.account, contract, U("BUY"), 100, 150.0);
trade_client.place_order(order);
// Approach 1: Modify Order object properties directly
order.limit_price = 155.0;
order.total_quantity = 200;
value result = trade_client.modify_order(order);
ucout << result.serialize() << std::endl;
// Approach 2: Modify via parameters
value result2 = trade_client.modify_order(order, 160.0, 300);
ucout << result2.serialize() << std::endl;Response Example
{
"code": 0,
"message": "success",
"timestamp": 1785528000000,
"data": {
"id": 123456,
"orderId": 789012
}
}Rate Limit
- Base rate: 120 requests per minute (counted per TigerId and interface in a 60-second rolling window).
Full Example: Place, Query, Modify, Cancel
#include "tigerapi/trade_client.h"
#include "tigerapi/client_config.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"
using namespace TIGER_API;
int main() {
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
// 1. Build contract
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// 2. Place limit order
Order order = OrderUtil::limit_order(config.account, contract, U("BUY"), 100, 150.0);
trade_client.place_order(order);
std::cout << "Order placed, ID: " << order.id << std::endl;
// 3. Query order status (returns Order object)
Order order_info = trade_client.get_order(order.id);
ucout << U("Order status: ") << order_info.status << std::endl;
// 4. Modify order
order.limit_price = 155.0;
trade_client.modify_order(order);
std::cout << "Order modified" << std::endl;
// 5. Cancel order
trade_client.cancel_order(order.id);
std::cout << "Order cancelled" << std::endl;
return 0;
}Updated about 2 months ago
