Place Order
Create Order
Request class: TradeOrderRequest
Description
Places an order for the specified instrument, order type, order side, and quantity.
Before submitting an order, confirm that the trading account and instrument support the selected order type, and that the order complies with the applicable trading-session rules.
Caution
- Market orders (
MKT) and stop orders (STP) are unavailable during pre-market and after-hours sessions. Setoutside_rthtofalsefor these orders.- Position hedging is not supported for shortable instruments. A trading account cannot hold both long and short positions in the same instrument.
- An attached parent order must currently be a limit order.
- A limit price must match one of the increments in the contract's
tickSizesfield. UseStockPriceUtilsto validate and adjust the price.- Market orders (
MKT) and paper trading accounts do not supportGTCfortime_in_force.- Paper trading accounts do not support warrant or CBBC orders.
Partial-fill status
-
Prime and paper trading accounts
If the status is neither
InitialnorFilled, includingPendingSubmit,Cancelled,Invalid, orInactive, a filled quantity greater than0indicates a partial fill. -
Global accounts
A
Filledstatus with a filled quantity greater than0indicates a partial fill.
Order Status Change Flow:
Other Notes
- Certain US index options, such as SPXW, and ETF options, such as IWM, SPY, and QQQ, may have tradable expirations from Monday through Friday. Available expirations depend on exchange listings.
- An order cannot close an existing position and open the opposite position at the same time. For example, if the trading account holds 100 shares long, an order to sell 200 shares is rejected. First sell 100 shares to close the long position, then submit a separate short-sale order.
Parameters
| Parameter | Type | Description | Market Order | Limit Order | Stop Order | Stop Limit Order | Trailing Stop Order |
|---|---|---|---|---|---|---|---|
| account | string | User authorized account: 402901 | Required | Required | Required | Required | Required |
| order_id | int | Order ID, used to prevent duplicate orders. Can be obtained through the order ID endpoint. If 0 is passed, the server will automatically generate an order ID. Passing 0 cannot prevent duplicate orders, please choose carefully | Optional | Optional | Optional | Optional | Optional |
| symbol | string | Stock symbol, e.g.: AAPL; (When sec_typ is warrant/CBBC, it's the 5-digit number below the name in the warrant/CBBC list) | Required | Required | Required | Required | Required |
| sec_type | string | Contract type (STK stock; OPT US stock option; WAR HK warrant; IOPT HK CBBC; FUT futures; FUND fund; CC Crypto) | Required | Required | Required | Required | Required |
| action | string | Order side BUY/SELL | Required | Required | Required | Required | Required |
| order_type | string | Order type MKT (market order), LMT (limit order), STP(stop order), STP_LMT (stop limit order), TRAIL (trailing stop order) | MKT | LMT | STP | STP_LMT | TRAIL |
| total_quantity | long | Order quantity; must be greater than 0. Required for every non-FUND order. FUND purchases use cash_amount. HK stocks, Shanghai-HK Stock Connect, warrants, and CBBCs have minimum quantity restrictions | Required | Required | Required | Required | Required |
| total_quantity_scale | int | Order quantity offset, default is 0. For fractional shares, total_quantity and total_quantity_scale combine to represent the real order quantity, e.g., total_quantity=111 total_quantity_scale=2, then real quantity=111*10^(-2)=1.11 | Optional | Optional | Optional | Optional | Optional |
| cash_amount | Double | Amount-based order amount. Required and positive for FUND purchases; unsupported for FUND sales. Although buildAmountOrder is available, current request validation still requires total_quantity for non-FUND orders, so stock amount orders are not currently supported | Optional | Not Required | Not Required | Not Required | Not Required |
| limit_price | double | Limit price, required when order_type is LMT, STP_LMT | Not Required | Required | Not Required | Required | Not Required |
| aux_price | double | Stop trigger price for STP/STP_LMT; trailing amount for TRAIL. Required for STP/STP_LMT. For TRAIL, provide aux_price or trailing_percent; if both are supplied, trailing_percent takes precedence | Not Required | Not Required | Required | Required | Choose One |
| trailing_percent | double | Trailing percentage for TRAIL; when used, it must be greater than 0 and less than 100. Provide this or aux_price; if both are effective, this field takes precedence | Not Required | Not Required | Not Required | Not Required | Choose One |
| outside_rth | boolean | true: Allow pre-market and after-hours trading (US stocks only), false: Not allowed, default is allowed. (Market orders, stop orders, trailing stop orders are only valid during market hours, will ignore outside_rth parameter) | Not Required | Optional | Optional | Not Required | Optional |
| trading_session_type | TradingSessionType | Trading-session enum. Availability depends on the account, market, instrument, and order type. See the enum meanings below | Not Required | Optional | Not Required | Optional | Not Required |
| adjust_limit | double | Price adjustment range (default 0 means no adjustment, positive numbers adjust upward, negative numbers adjust downward), automatically adjusts the input price to a legal price level. For example: 0.001 means adjust upward with a range not exceeding 0.1%; -0.001 means adjust downward with a range not exceeding 0.1%. Default 0 means no adjustment | Not Required | Optional | Optional | Optional | Optional |
| market | string | Market (US stocks US, HK stocks HK, Shanghai-HK Stock Connect CN) | Optional | Optional | Optional | Optional | Optional |
| currency | string | Currency (US stocks USD, HK stocks HKD, Shanghai-HK Stock Connect CNH) | Optional | Optional | Optional | Optional | Optional |
| time_in_force | string | The Java enum contains DAY, GTC, GTD, and OPG. When omitted, ordinary orders default to DAY and CC cryptocurrency orders default to GTC. The ordinary Prime-account path accepts DAY/GTC/GTD; OPG is primarily for supported auction and other account-dependent order flows. Actual support depends on the account, market, instrument, and order type | Optional | Optional | Optional | Optional | Optional |
| expire_time | long | Order validity deadline, 13-digit timestamp in milliseconds (required when time_in_force is GTD, invalid for other types) | Not Required | Optional | Optional | Not Required | Optional |
| exchange | string | Exchange (US stocks SMART, HK stocks SEHK, Shanghai-HK Stock Connect SEHKNTL, Shenzhen-HK Stock Connect SEHKSZSE) | Optional | Optional | Optional | Optional | Optional |
| expiry | string | Expiry date (options, warrants, CBBCs only) | Optional | Optional | Optional | Optional | Optional |
| strike | string | Strike price (options, warrants, CBBCs only) | Optional | Optional | Optional | Optional | Optional |
| right | string | Option right PUT/CALL (options, warrants, CBBCs only) | Optional | Optional | Optional | Optional | Optional |
| multiplier | float | Multiplier, quantity per lot (options, warrants, CBBCs only) | Optional | Optional | Optional | Optional | Optional |
| local_symbol | string | This field is required for warrants and CBBCs, the 5-digit number below the name in the warrant/CBBC list in the APP | Optional | Optional | Optional | Optional | Optional |
| secret_key | string | Trader key, for institutional users only | Optional | Optional | Optional | Optional | Optional |
| user_mark | string | Order comment; it cannot be modified after placement and may be returned as userMark. Trimming, length normalization, and return behavior are account-dependent. Prime accounts trim surrounding whitespace and retain at most the first 200 characters | Optional | Optional | Optional | Optional | Optional |
| alloc_accounts | List<String> | Global accounts only Sub-account list for an allocation order. Entries must be non-empty and correspond by index to alloc_shares | Optional | Optional | Optional | Optional | Optional |
| alloc_shares | List<Double> | Global accounts only Quantity allocated to each corresponding sub-account. Every value must be positive, and the list length must equal alloc_accounts | Optional | Optional | Optional | Optional | Optional |
| algo_strategy | string | Strategy name for supported algorithm orders only | Optional | Optional | Optional | Optional | Optional |
| algo_params | List<TagValue> | Parameters for supported algorithm orders only | Optional | Optional | Optional | Optional | Optional |
| source | string | Order source identifier. Set it with TradeParamBuilder.source(...); TradeOrderRequest has no corresponding setter | Optional | Optional | Optional | Optional | Optional |
| stop_loss_order_type | string | Attached stop-loss order type: STP, STP_LMT, or TRAIL | Optional | Optional | Optional | Optional | Optional |
| combo_type | string | Multi-leg combination type, typically used for option strategies but not restricted to options | Optional | Optional | Optional | Optional | Optional |
| contract_legs | List<ContractLeg> | Multi-leg contract definitions, typically option legs but not restricted to options | Optional | Optional | Optional | Optional | Optional |
| oca_orders | List<TradeOrderModel> | OCA child orders | Optional | Optional | Optional | Optional | Optional |
Supported time_in_force values depend on the account, market, instrument, and order type.
The trading_session_type enum contains PRE_RTH_POST (pre-market, regular, and post-market), RTH (regular), OVERNIGHT, FULL, HK_AUC (HK auction), HK_CTS (HK continuous trading), and HK_AUC_CTS (HK auction and continuous trading). These enum values do not imply that every account or order supports every session.
Ordinary orders use DAY when time_in_force is omitted, except CC cryptocurrency orders, which use GTC; FUND orders also use GTC.
-
Attached Order Parameters
Attached Orders are orders that can achieve profit-taking or stop-loss effects on the main order through attached sub-orders. The types of sub-orders that can be attached include limit orders (can be used for profit-taking) and stop limit orders/stop orders (can be used for stop-loss). Attached orders can be implemented by adding the following parameters
Parameter Type Description Attached Stop Loss Attached Profit Taking Attached Trailing Stop Attached Bracket attach_type string Attached order type, required when placing attached orders. (order_type should be LMT): PROFIT-profit taking order, LOSS-stop loss order, BRACKETS-bracket order (includes attached profit taking and stop loss orders) Required Required Required Required profit_taker_orderId int Profit taking order ID, can be obtained through the order ID endpoint. If 0 is passed, the server will automatically generate a profit taking order ID Not Required Optional Optional Optional profit_taker_price double Profit taking order price, required when placing profit taking orders Not Required Required Not Required Required profit_taker_tif string Same as time_in_force field, order validity period, can only be DAY (valid for the day) and GTC (valid until canceled), required when placing profit taking orders Not Required Required Not Required Required profit_taker_rth boolean Same as outside_rth field Not Required Required Not Required Required stop_loss_orderId int Stop loss order ID, can be obtained through the order ID endpoint. If 0 is passed, the server will automatically generate a stop loss order ID Required Not Required Not Required Required stop_loss_price double Stop loss order price (stop loss order trigger price), required when placing stop loss orders Required Not Required Not Required Required stop_loss_limit_price double Stop loss order execution limit price (currently only valid for prime accounts). When the stop loss order limit price is not filled, it's an attached stop loss market order Optional Not Required Not Required Optional stop_loss_tif string Same as time_in_force field, order validity period, can only be DAY (valid for the day) and GTC (valid until canceled), required when placing stop loss orders Required Not Required Required Required stop_loss_trailing_percent double Trailing percentage; when used, it must be greater than 0 and less than 100. An attached trailing stop requires this field or stop_loss_trailing_amount; if both are effective, the percentage is usedOptional Not Required Choose One Optional stop_loss_trailing_amount double Trailing stop order - stop amount. When placing trailing stop orders, one of stop percentage (stopLossTrailingPercent) and stop amount (stopLossTrailingAmount) must be filled. If both are filled, the stop percentage will be used as the parameter. Optional Not Required Choose One Optional
-
TWAP/VWAP Order Parameters
TWAP and VWAP builders support stocks only. Both can only be placed during regular trading hours and do not support pre-market orders.
TWAP and VWAP orders use
sec_type=STK,outside_rth=false, andtime_in_force=DAY. Their algorithm parameters includestart_timeandend_time; VWAP also supportsparticipation_rate.Parameter Type Algorithm Parameter Description TWAP VWAP order_type string Order type, TWAP/VWAP Required Required account string Trading account Required Required symbol string Stock symbol e.g.: AAPL Required Required sec_type string Only supports STK Required Required total_quantity long Order quantity Required Required algo_params List<TagValue>Algorithm parameters Optional Optional - long start_time Strategy start time (13-digit millisecond timestamp) Optional Optional - long end_time Strategy end time (13-digit millisecond timestamp) Optional Optional - Double participation_rate Maximum participation rate (volume as maximum proportion of daily average volume), valid range 0.01-0.5 Not Required Optional
-
Iceberg Order Parameters
Iceberg orders only support US stock underlying assets (sec_type=STK), can only be placed during market hours, and do not support pre-market orders. Iceberg orders split large orders into smaller batches, exposing only
display_sizequantity to the market at a time to reduce market impact.Parameter Type Description Required order_type string Order type, fixed as ICEBERGRequired account string Trading account Required symbol string Stock symbol, e.g. AAPL Required sec_type string Contract type, only supports STK Required action string Order side BUY/SELL Required total_quantity int Total order quantity Required limit_price double Limit price, required when price_type is LIMIT_PRICE Conditional display_size int Display quantity per slice (visible to market); must be positive. Required when min_display_sizeis suppliedOptional min_display_size int Minimum display quantity (actual display randomized between [min_display_size, display_size]); must not exceed display_size. Defaults todisplay_sizeOptional check_intervals int Price check interval (seconds); must be positive when supplied Optional price_type string Price type: LIMIT_PRICE/ASK_PRICE/BID_PRICE/LATEST_PRICE, default LIMIT_PRICEOptional start_time long Strategy effective start time (13-digit millisecond timestamp) Optional end_time long Strategy effective end time (13-digit millisecond timestamp) Optional The Java Iceberg builders set
time_in_force=DAY. The short overload defaultsmin_display_sizetodisplay_size, leavescheck_intervals,start_time, andend_timeunset, and usesprice_type=LIMIT_PRICE. The full overload also substitutesdisplay_sizeandLIMIT_PRICEwhenmin_display_sizeorprice_typeisnull. The builders do not validate the ordering of directly suppliedstart_timeandend_timevalues.
-
Response
Account path Returned fields Global idand deprecatedorderId; attached-order placement also returnssubIdsPrime/Paper id, deprecatedorderId,subIds, andorders;subIdslists child order IDs andorderscontains returned order detailsA successful response means the placement request was accepted, not that the order filled. Query any returned order or use the order-query API to confirm its final status.
Depending on the account and order scenario,
TradeOrdermay also includecashQuantity,lastFillPrice,goodTillDate,triggerStatus,ocaGroupId,comboLegs,allocAccounts,allocShares,algoStrategy,algoParameters,comboType,comboTypeDesc,legs,displaySize,minDisplaySize,checkIntervals,priceType,startTime, andendTime, in addition to the fields documented on Get Order Information.
Rate Limit
The base rate limit is 120 requests/min.
Build Contract Object
// US stock contract
ContractItem contract = ContractItem.buildStockContract("SPY", "USD");
// HK stock contract
ContractItem hkStockContract = ContractItem.buildStockContract("00700", "HKD");
// HK warrant contract (note that for the same symbol, the expiry may be different for global and prime accounts)
ContractItem warrantContract = ContractItem.buildWarrantContract("13745", "20211217", 719.38D, Right.CALL.name());
// HK CBBC contract
ContractItem cbbcContract = ContractItem.buildCbbcContract("50296", "20220331", 457D, Right.CALL.name());
// US stock option contract
ContractItem occOptionContract = ContractItem.buildOptionContract("AAPL 190118P00160000");
ContractItem optionContract = ContractItem.buildOptionContract("AAPL", "20211119", 150.0D, "CALL");
// Futures contract
// Global account
ContractItem globalFutureContract = ContractItem.buildFutureContract("CL", "USD", "SGX", "20190328", 1.0D);
// Prime account
ContractItem primeFutureContract = ContractItem.buildFutureContract("CL2112", "USD");Build Orders
Market Order (MKT)
// get contract(use default account)
ContractRequest contractRequest = ContractRequest.newRequest(new ContractModel("AAPL"));
ContractResponse contractResponse = client.execute(contractRequest);
ContractItem contract = contractResponse.getItem();
// market order(use default account)
TradeOrderRequest request = TradeOrderRequest.buildMarketOrder(contract, ActionType.BUY, 10);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// get contract(use account parameter)
contractRequest = ContractRequest.newRequest(new ContractModel("AAPL"), "402901");
contractResponse = client.execute(contractRequest);
contract = contractResponse.getItem();
// market order(use account parameter)
request = TradeOrderRequest.buildMarketOrder("402901", contract, ActionType.BUY, 10);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Limit Order (LMT)
// use default account
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder(contract, ActionType.BUY, 1, 100.0d);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 100.0d);
// set user_mark
request.setUserMark("test001");
// set GTD order's expire_time
request.setTimeInForce(TimeInForce.GTD);
request.setExpireTime(1669363583804L);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Overnight/Full-time Orders
US stocks only
// place overnight order in the US market
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 200.0d);
request.setTradingSessionType(TradingSessionType.OVERNIGHT);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// place full-time order in the US market
request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 200.0d);
request.setTradingSessionType(TradingSessionType.FULL);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Auction Orders (AM/AL)
// auction order in hk market
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 100, 100.0d);
// Pre-market auction: AM or AL + OPG, if not filled participate in regular trading; Post-market auction: AM or AL + DAY
// participate in the pre-market auction, set auction limit order
request.setAuctionOrder(OrderType.AL, TimeInForce.OPG);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
request = TradeOrderRequest.buildMarketOrder("402901", contract, ActionType.BUY, 100);
// Participate in the after-hours auction, set auction market order
request.setAuctionOrder(OrderType.AM, TimeInForce.DAY);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Stop Order (STP)
// use default account
TradeOrderRequest request = TradeOrderRequest.buildStopOrder(contract, ActionType.BUY, 1, 120.0d);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildStopOrder("402901", contract, ActionType.BUY, 1, 120.0d);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Stop Limit Order (STP_LMT)
// use default account
TradeOrderRequest request = TradeOrderRequest.buildStopLimitOrder(contract, ActionType.BUY, 1,150d,130.0d);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildStopLimitOrder("402901", contract, ActionType.BUY, 1,150d,130.0d);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Trailing Stop Order (TRAIL)
// use default account
TradeOrderRequest request = TradeOrderRequest.buildTrailOrder(contract, ActionType.BUY, 1,10d,130.0d);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter. standard account currently not supported
request = TradeOrderRequest.buildTrailOrder("402901", contract, ActionType.BUY, 1, 10d, 130.0d);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Main Order + Attached Profit Taking Order
// use default account
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder(contract, ActionType.BUY, 1, 199d);
TradeOrderRequest.addProfitTakerOrder(request, 250D, TimeInForce.DAY, Boolean.FALSE);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 199d);
TradeOrderRequest.addProfitTakerOrder(request, 250D, TimeInForce.DAY, Boolean.FALSE);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Main Order + Additional Stop Loss Order
// use default account
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder(contract, ActionType.BUY, 1, 129d);
TradeOrderRequest.addStopLossOrder(request, 100D, TimeInForce.DAY);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 129d);
// Add additional stop loss market order, the stop loss price is the trigger price (options are not supported)
TradeOrderRequest.addStopLossOrder(request, 100D, TimeInForce.DAY);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// Options can use additional stop loss limit orders
ContractItem optionContract = ContractItem.buildOptionContract("AAPL", "20211231", 175.0D, "CALL");
request = TradeOrderRequest.buildLimitOrder("402901", optionContract, ActionType.BUY, 1, 2.0d);
// Add additional stop loss limit order, where the first price 1.7 is the trigger price, and the second price 1.69 is the limit price for the additional stop loss order (currently only supports prime accounts)
TradeOrderRequest.addStopLossLimitOrder(request, 1.7D, 1.69D, TimeInForce.DAY);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Main Order + Additional Trailing Stop Loss Order
ContractItem contract = ContractItem.buildStockContract("AAPL", "USD");
// use default account
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder(contract, ActionType.BUY, 1, 165D);
TradeOrderRequest.addStopLossTrailOrder(request, 10.0D, null, TimeInForce.DAY);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildLimitOrder("402901", contract, ActionType.BUY, 1, 165D);
TradeOrderRequest.addStopLossTrailOrder(request, 10.0D, null, TimeInForce.DAY);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Main Order + Additional Bracket Order
// use default account
TradeOrderRequest request = TradeOrderRequest.buildLimitOrder(contract, ActionType.BUY, 1, 199d);
TradeOrderRequest.addBracketsOrder(request, 250D, TimeInForce.DAY, Boolean.FALSE, 180D, TimeInForce.GTC);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// use account parameter
request = TradeOrderRequest.buildLimitOrder("13810712", contract, ActionType.BUY, 1, 199d);
TradeOrderRequest.addBracketsOrder(request, 250D, TimeInForce.DAY, Boolean.FALSE, 180D, TimeInForce.GTC);
response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));Currency Exchange Order
The Forex order model uses source_currency, source_amount, and target_currency; provide valid source currency, source amount, and target currency values. The builder itself does not validate a uniform positive-amount range. The model also exposes seg_type, external_id, and time_in_force.
ForexTradeOrderRequest request = ForexTradeOrderRequest.buildRequest("402901",
SegmentType.SEC, Currency.HKD, 1000D, Currency.USD);
ForexTradeOrderResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
} else {
System.out.println(response.getMessage());
}Fund Amount Order
ContractItem contract = ContractItem.buildFundContract("IE00B464Q616.USD", "USD");
TradeOrderRequest request = TradeOrderRequest.buildAmountOrder(
"13810712", contract, ActionType.BUY, 100.0D);
request.setUserMark("test-amount-order");
TradeOrderResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
} else {
System.out.println(response.getMessage());
}TWAP/VWAP Orders
Only supports US stocks, only supports intraday orders. Cannot be modified, but can be canceled.
// TWAP order
TradeOrderRequest twapRequest = TradeOrderRequest.buildTWAPOrder(
"572386", "DM", ActionType.BUY, 500,
DateUtils.getTimestamp("2023-06-20 09:30:00", TimeZoneId.NewYork),
DateUtils.getTimestamp("2023-06-20 11:00:00", TimeZoneId.NewYork),
1.5D)
.setUserMark("testTWAP001")
.setLang(Language.en_US);
TradeOrderResponse twapResponse = client.execute(twapRequest);
if (twapResponse.isSuccess()) {
System.out.println(JSONObject.toJSONString(twapResponse));
} else {
System.out.println(twapResponse.getMessage());
}
// VWAP order
TradeOrderRequest vwapRequest = TradeOrderRequest.buildVWAPOrder(
"572386", "DM", ActionType.BUY, 500,
DateUtils.getTimestamp("2023-06-20 09:30:00", TimeZoneId.NewYork),
DateUtils.getTimestamp("2023-06-20 11:00:00", TimeZoneId.NewYork),
0.5D, 1.5D)
.setUserMark("testVWAP001")
.setLang(Language.en_US);
TradeOrderResponse vwapResponse = client.execute(vwapRequest);
if (vwapResponse.isSuccess()) {
System.out.println(JSONObject.toJSONString(vwapResponse));
} else {
System.out.println(vwapResponse.getMessage());
}Iceberg Order
Only supports US stocks, only during market hours. Does not support pre-market orders. Supports modification and cancellation.
import com.tigerbrokers.stock.openapi.client.struct.enums.PriceType;
import com.tigerbrokers.stock.openapi.client.util.DateUtils;
import com.tigerbrokers.stock.openapi.client.struct.enums.TimeZoneId;
// Iceberg order (basic parameters, limit price mode)
ContractItem contract = ContractItem.buildStockContract("AAPL", "USD");
TradeOrderRequest request = TradeOrderRequest.buildIcebergOrder(
"402901", contract, ActionType.BUY, 1000, 180.0, 100);
TradeOrderResponse response = client.execute(request);
System.out.println(JSONObject.toJSONString(response));
// Iceberg order (full parameters)
TradeOrderRequest fullRequest = TradeOrderRequest.buildIcebergOrder(
"402901", contract, ActionType.BUY, 1000, 180.0,
100, // displaySize: display 100 shares each time
50, // minDisplaySize: minimum 50 shares (actual display randomized between 50~100)
30, // checkIntervals: check every 30 seconds
PriceType.LIMIT_PRICE, // priceType
DateUtils.getTimestamp("2025-06-20 09:30:00", TimeZoneId.NewYork), // startTime
DateUtils.getTimestamp("2025-06-20 16:00:00", TimeZoneId.NewYork) // endTime
);
TradeOrderResponse fullResponse = client.execute(fullRequest);
System.out.println(JSONObject.toJSONString(fullResponse));Options Multi-Leg Orders
List<ContractLeg> contractLegs = new ArrayList<>();
ContractLeg leg1 = new ContractLeg(SecType.OPT, "AAPL",
"170.0", "20231013", Right.CALL,
ActionType.BUY, 1);
contractLegs.add(leg1);
ContractLeg leg2 = new ContractLeg(SecType.OPT, "AAPL",
"170.0", "20231013", Right.PUT,
ActionType.BUY, 1);
contractLegs.add(leg2);
TradeOrderRequest request = TradeOrderRequest.buildMultiLegOrder(
"572386", contractLegs, ComboType.CUSTOM,
ActionType.BUY, 3,
OrderType.LMT, 2.01d, null, null)
.setLang(Language.en_US)
.setUserMark("test_multi_leg");
TradeOrderResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
} else {
System.out.println(response.getMessage());
}OCA Bracket Orders
Not supported in paper trading accounts.
OCA bracket orders contain two orders with the same underlying asset: one take-profit limit order and another stop-loss order or stop-loss limit order. When one order is executed, the other order is automatically canceled. After placing the order, two order objects are returned, and orders with the same ocaGroupId belong to the same group.
ContractItem contract = ContractItem.buildStockContract("BILI", "USD");
TradeOrderRequest request = TradeOrderRequest.buildOCABracketsOrder(
"13810712", contract, ActionType.SELL, 1,
17.0D, TimeInForce.DAY, Boolean.TRUE,
12.0D, null, TimeInForce.DAY, Boolean.FALSE);
request.setLang(Language.en_US).setUserMark("test-oca");
TradeOrderResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
// get oca order info
List<TradeOrder> ocaOrders = response.getItem().getOrders();
} else {
System.out.println(response.getMessage());
}Example Response
Additional Bracket Order
{
"id":30325712346546176,
"orderId":0,
"subIds":[
30325712346546177,
30325712346677250
],
"orders":[
{
"account":"13810712",
"action":"BUY",
"algoStrategy":"LMT",
"attrDesc":"",
"avgFillPrice":0,
"canCancel":true,
"canModify":true,
"commission":0,
"currency":"HKD",
"discount":0,
"filledQuantity":0,
"id":30325712346546176,
"identifier":"00700",
"latestPrice":385.8,
"latestTime":1680266023000,
"limitPrice":295,
"liquidation":false,
"market":"HK",
"name":"Tencent Holdings",
"openTime":1680266023000,
"orderId":91,
"orderType":"LMT",
"outsideRth":true,
"realizedPnl":0,
"remark":"",
"secType":"STK",
"source":"OpenApi",
"status":"Initial",
"symbol":"00700",
"timeInForce":"DAY",
"totalQuantity":100,
"updateTime":1680266023000,
"userMark":"test_bracket"
},
{
"account":"13810712",
"action":"SELL",
"algoStrategy":"LMT",
"attrDesc":"",
"avgFillPrice":0,
"canCancel":true,
"canModify":true,
"commission":0,
"currency":"HKD",
"discount":0,
"filledQuantity":0,
"id":30325712346546177,
"identifier":"00700",
"latestPrice":385.8,
"latestTime":1680266023000,
"limitPrice":320,
"liquidation":false,
"market":"HK",
"name":"Tencent Holdings",
"ocaGroupId":87055,
"openTime":1680266023000,
"orderId":92,
"orderType":"LMT",
"outsideRth":true,
"parentId":30325712346546176,
"realizedPnl":0,
"remark":"",
"secType":"STK",
"source":"OpenApi",
"status":"Initial",
"symbol":"00700",
"timeInForce":"DAY",
"totalQuantity":100,
"updateTime":1680266023000,
"userMark":"test_bracket"
},
{
"account":"13810712",
"action":"SELL",
"algoStrategy":"STP_LMT",
"attrDesc":"",
"auxPrice":280,
"avgFillPrice":0,
"canCancel":true,
"canModify":true,
"commission":0,
"currency":"HKD",
"discount":0,
"filledQuantity":0,
"id":30325712346677248,
"identifier":"00700",
"latestPrice":385.8,
"latestTime":1680266023000,
"limitPrice":278,
"liquidation":false,
"market":"HK",
"name":"Tencent Holdings",
"ocaGroupId":87055,
"openTime":1680266023000,
"orderId":93,
"orderType":"STP_LMT",
"outsideRth":true,
"parentId":30325712346546176,
"realizedPnl":0,
"remark":"",
"secType":"STK",
"source":"OpenApi",
"status":"Initial",
"symbol":"00700",
"timeInForce":"DAY",
"totalQuantity":100,
"updateTime":1680266023000,
"userMark":"test_bracket"
}
]
}Updated about 1 month ago
