Cancel or Modify Order
cancel_order Cancel Order
value TradeClient::cancel_order(unsigned long long id)
Description
Cancel an unfilled order
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("/path/to/your/properties/"));
TradeClient trade_client(config);
// Cancel the specified order
value result = trade_client.cancel_order(14275856193552384);
ucout << result.serialize() << std::endl;modify_order Modify Order
Description
Modify an unfilled order. Two overloaded approaches are available: modify Order object properties directly and submit, or specify modification content through parameters.
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 | Whether to allow pre/post market, 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 | Whether to allow pre/post market 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("/path/to/your/properties/"));
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;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("/path/to/your/properties/"));
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 1 day ago
