Cancel or Modify Order

C++ HTTP methods return the value of the complete response's data field. The outer code, message, and timestamp fields, and the data field name itself, are not part of the returned value.

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

ParameterTypeRequiredDescription
idunsigned long longYesOrder 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


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)

ParameterTypeRequiredDescription
orderOrder&YesModified 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)

ParameterTypeRequiredDescription
orderOrder&YesOriginal order object
limit_pricedoubleNoNew limit price, default 0 (no change)
total_quantitylongNoNew quantity, default 0 (no change)
aux_pricedoubleNoNew stop trigger price, default 0 (no change)
trail_stop_pricedoubleNoNew trailing stop price, default 0
trailing_percentdoubleNoNew trailing percentage, default 0
percent_offsetdoubleNoPercent offset, default 0
time_in_forceutility::string_tNoOrder validity period, default empty
outside_rthboolNoAllow pre-market and after-hours trading; default false
expire_timetime_tNoExpiry time, default 0

Modifiable Fields

FieldDescription
total_quantityTotal order quantity
limit_priceLimit price
aux_priceStop trigger price
trailing_percentTrailing stop percentage
time_in_forceOrder validity period
outside_rthAllows 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


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;
}

What’s Next

Did this page help you?