Place 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.
Place an Order
value TradeClient::place_order(Order &order)
Description
Submits an order for trading.
After a successful place_order call, the order object's id field contains the ID to use for later queries or cancellation. A successful response confirms submission, not execution. Execution is asynchronous. Call get_order or get_orders to check the order status.
Note
- Market orders (MKT) and stop orders (STP) do not support pre-market or after-hours trading
- For shortable symbols, position locking is not currently supported. You cannot hold both long and short positions for the same symbol simultaneously
- Directly opening a reverse position is prohibited
Parameters
Order object, built using the OrderUtil utility class
Return
A web::json::value JSON object containing the order information when submission succeeds.
Rate Limit
- Base rate: 120 requests per minute (counted per TigerId and interface in a 60-second rolling window).
Building Contract Object Examples
#include "tigerapi/contract_util.h"
using namespace TIGER_API;
// US stock
Contract contract = ContractUtil::stock_contract(U("TIGR"), U("USD"));
// HK stock
Contract contract = ContractUtil::stock_contract(U("00700"), U("HKD"));
// Option
Contract contract = ContractUtil::option_contract(U("AAPL 240621C00190000"));
// or
Contract contract = ContractUtil::option_contract(U("AAPL"), U("20240621"), U("190"), U("CALL"));
// Futures
Contract contract = ContractUtil::future_contract(U("CL2312"), U("USD"));Limit Order (LMT)
#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);
// Build stock contract
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Build limit order
Order order = OrderUtil::limit_order(
config.account, // Trading account
contract, // Contract object
U("BUY"), // Buy direction
100, // Quantity
150.0 // Limit price
);
// Place order
value result = trade_client.place_order(order);
ucout << result.serialize() << std::endl;
// Get order ID
std::cout << "Order ID: " << order.id << std::endl;Market Order (MKT)
#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);
// Build stock contract
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Build market order
Order order = OrderUtil::market_order(
config.account, // Trading account
contract, // Contract object
U("BUY"), // Buy direction
100 // Quantity
);
// Place order
value result = trade_client.place_order(order);Stop Order (STP)
#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);
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Build stop order
Order order = OrderUtil::stop_order(
config.account, // Trading account
contract, // Contract object
U("SELL"), // Sell direction
100, // Quantity
140.0 // Stop trigger price
);
value result = trade_client.place_order(order);Stop Limit Order (STP_LMT)
#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);
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Build stop limit order
Order order = OrderUtil::stop_limit_order(
config.account, // Trading account
contract, // Contract object
U("SELL"), // Sell direction
100, // Quantity
139.0, // Limit price
140.0 // Stop trigger price
);
value result = trade_client.place_order(order);Trailing Stop Order (TRAIL)
#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);
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Trailing stop order - by trailing amount
Order order = OrderUtil::trail_order(
config.account, // Trading account
contract, // Contract object
U("SELL"), // Sell direction
100, // Quantity
5.0, // Trailing amount (aux_price)
0 // Trailing percent (0 means not used)
);
// Trailing stop order - by percentage
Order order2 = OrderUtil::trail_order(
config.account,
contract,
U("SELL"),
100,
0, // aux_price, 0 means not used
8.0 // trailing_percent 8%
);
value result = trade_client.place_order(order);Place HK Stock Order
For Hong Kong stocks, the order quantity must be a multiple of the stock's lot size.
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
Contract contract = ContractUtil::stock_contract(U("00700"), U("HKD"));
Order order = OrderUtil::limit_order(
config.account,
contract,
U("BUY"),
100, // Tencent has 100 shares per lot
400.0
);
value result = trade_client.place_order(order);Place Futures Order
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
Contract contract = ContractUtil::future_contract(U("CL2312"), U("USD"));
Order order = OrderUtil::limit_order(
config.account,
contract,
U("BUY"),
1,
70.0
);
value result = trade_client.place_order(order);Place Option Order
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
// Build contract using option identifier
Contract contract = ContractUtil::option_contract(U("AAPL 240621C00190000"));
Order order = OrderUtil::limit_order(
config.account,
contract,
U("BUY"),
1,
2.5
);
value result = trade_client.place_order(order);Price Correction for Orders
Use PriceUtil to adjust an order price to the contract's tick size. Tick-size requirements can vary by price tier, and the API rejects prices with invalid precision.
#include "tigerapi/trade_client.h"
#include "tigerapi/client_config.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"
#include "tigerapi/price_util.h"
using namespace TIGER_API;
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
// Query contract to get tickSizes information
value contract_info = trade_client.get_contract(U("AAPL"), U("STK"));
value tick_sizes = contract_info[U("tickSizes")];
double price = 150.173;
// Check if price matches tick size specification
bool is_ok = PriceUtil::match_tick_size(price, tick_sizes);
// Fix price (default rounds down)
double fixed_price = PriceUtil::fix_price_by_tick_size(price, tick_sizes);
// fixed_price = 150.17
// Fix price (rounds up)
double fixed_price_up = PriceUtil::fix_price_by_tick_size(price, tick_sizes, true);
// fixed_price_up = 150.18
// Place order with corrected price
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
Order order = OrderUtil::limit_order(config.account, contract, U("BUY"), 1, fixed_price);
trade_client.place_order(order);Order Object Properties
| Property | Type | Description |
|---|---|---|
| id | unsigned long long | Order ID |
| order_id | long | External order ID |
| account | utility::string_t | Account ID |
| contract | Contract | Contract object (contains symbol, sec_type, market, currency) |
| action | utility::string_t | Trade direction BUY/SELL |
| order_type | utility::string_t | Order type MKT/LMT/STP/STP_LMT/TRAIL |
| total_quantity | long long | Total order quantity |
| total_quantity_scale | long | Quantity decimal scale; actual quantity is total_quantity * 10^-total_quantity_scale |
| limit_price | double | Limit price |
| s_limit_price | utility::string_t | String-form limit price; when nonempty, it is sent as limit_price |
| aux_price | double | Stop trigger price |
| trail_stop_price | double | Trailing stop price |
| trailing_percent | double | Trailing stop percentage |
| percent_offset | double | Percent offset |
| time_in_force | utility::string_t | Order validity period DAY/GTC/GTD |
| outside_rth | bool | Allows US pre-market and after-hours trading. The default constructor does not initialize this field; set it explicitly after constructing an order. |
| adjust_limit | double | Price adjustment range |
| user_mark | utility::string_t | User remarks |
| expire_time | time_t | Expiry time |
| status | utility::string_t | Order status |
| parent_id | unsigned long long | Parent order ID |
| filled_quantity | long long | Filled quantity |
| filled_quantity_scale | long | Filled-quantity decimal scale |
| avg_fill_price | double | Volume-weighted average of fill prices, excluding commissions and other fees |
| realized_pnl | double | Realized P&L; commission and GST are returned separately. Refer to the account statement for the exact calculation basis and currency |
| commission | double | Commission; the model cannot distinguish a missing field from an explicit zero |
| gst | double | Goods and services tax; the model cannot distinguish a missing field from an explicit zero |
| open_time | time_t | Order placement time |
| latest_time | time_t | Latest fill time |
| update_time | time_t | Order update time |
| reason | utility::string_t | Order failure reason |
| sub_ids | web::json::value | Child-order ID list |
| algo_strategy | utility::string_t | Algorithm strategy such as TWAP or VWAP |
| algo_params | vector<AlgoParam> | Algorithm parameters; each item has string tag and value fields |
| display_size | long long | Iceberg display quantity; 0 omits it |
| min_display_size | long long | Iceberg minimum display quantity; 0 omits it |
| check_intervals | long long | Iceberg check interval; 0 omits it |
| price_type | utility::string_t | Iceberg price type |
| start_time | long long | Iceberg start time in Unix milliseconds; 0 omits it |
| end_time | long long | Iceberg end time in Unix milliseconds; 0 omits it |
| cash_amount | double | Cash amount for amount orders; 0 omits it |
| combo_type | utility::string_t | Combo strategy type |
| contract_legs | vector<ContractLeg> | Combo legs; each has symbol, sec_type, expiry, strike, right, action, and ratio |
| oca_orders | vector<Order> | OCA child orders |
| attach_type | utility::string_t | Attached-order type: PROFIT, LOSS, or BRACKETS |
| profit_taker_order_id | int64_t | Profit-taker child order ID; 0 omits it |
| profit_taker_price | double | Profit-taker price; 0 omits it |
| profit_taker_tif | utility::string_t | Profit-taker time in force |
| profit_taker_rth | bool | Whether the profit taker permits extended hours; false is omitted |
| stop_loss_order_type | utility::string_t | Stop-loss type such as STP, STP_LMT, or TRAIL |
| stop_loss_order_id | int64_t | Stop-loss child order ID; 0 omits it |
| stop_loss_price | double | Stop trigger price; 0 omits it |
| stop_loss_limit_price | double | Stop-limit price; 0 omits it |
| stop_loss_tif | utility::string_t | Stop-loss time in force |
| stop_loss_trailing_percent | double | Trailing-stop percentage; 0 omits it |
| stop_loss_trailing_amount | double | Trailing-stop amount; 0 omits it |
Response Example
{
"code": 0,
"message": "success",
"timestamp": 1785528000000,
"data": {
"id": 123458,
"orderId": 789014,
"subIds": []
}
}Iceberg Order (ICEBERG)
Iceberg orders support only US stocks. You can place them only during regular trading hours; pre-market orders are not supported.
#include "tigerapi/trade_client.h"
#include "tigerapi/order_util.h"
ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
// Iceberg order (basic parameters)
Order order = OrderUtil::iceberg_order(
config.account, contract, U("BUY"), 1000, 180.0, 100);
value result = trade_client.place_order(order);
// Iceberg order (full parameters)
Order full_order = OrderUtil::iceberg_order(
config.account, contract, U("BUY"), 1000, 180.0,
100, // display_size
50, // min_display_size
30, // check_intervals (seconds)
U("LIMIT_PRICE"), // price_type: LIMIT_PRICE/ASK_PRICE/BID_PRICE/LATEST_PRICE
start_time, // effective start time (epoch ms)
end_time // effective end time (epoch ms)
);
value full_result = trade_client.place_order(full_order);Updated about 2 months ago
