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

  1. Market orders (MKT) and stop orders (STP) are unavailable during pre-market and after-hours sessions. Set outside_rth to false for these orders.
  2. Position hedging is not supported for shortable instruments. A trading account cannot hold both long and short positions in the same instrument.
  3. An attached parent order must currently be a limit order.
  4. A limit price must match one of the increments in the contract's tickSizes field. Use StockPriceUtils to validate and adjust the price.
  5. Market orders (MKT) and paper trading accounts do not support GTC for time_in_force.
  6. Paper trading accounts do not support warrant or CBBC orders.

Partial-fill status

  1. Prime and paper trading accounts

    If the status is neither Initial nor Filled, including PendingSubmit, Cancelled, Invalid, or Inactive, a filled quantity greater than 0 indicates a partial fill.

  2. Global accounts

    A Filled status with a filled quantity greater than 0 indicates 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

ParameterTypeDescriptionMarket OrderLimit OrderStop OrderStop Limit OrderTrailing Stop Order
accountstringUser authorized account: 402901RequiredRequiredRequiredRequiredRequired
order_idintOrder 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 carefullyOptionalOptionalOptionalOptionalOptional
symbolstringStock symbol, e.g.: AAPL; (When sec_typ is warrant/CBBC, it's the 5-digit number below the name in the warrant/CBBC list)RequiredRequiredRequiredRequiredRequired
sec_typestringContract type (STK stock; OPT US stock option; WAR HK warrant; IOPT HK CBBC; FUT futures; FUND fund; CC Crypto)RequiredRequiredRequiredRequiredRequired
actionstringOrder side BUY/SELLRequiredRequiredRequiredRequiredRequired
order_typestringOrder type MKT (market order), LMT (limit order), STP(stop order), STP_LMT (stop limit order), TRAIL (trailing stop order)MKTLMTSTPSTP_LMTTRAIL
total_quantitylongOrder 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 restrictionsRequiredRequiredRequiredRequiredRequired
total_quantity_scaleintOrder 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.11OptionalOptionalOptionalOptionalOptional
cash_amountDoubleAmount-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 supportedOptionalNot RequiredNot RequiredNot RequiredNot Required
limit_pricedoubleLimit price, required when order_type is LMT, STP_LMTNot RequiredRequiredNot RequiredRequiredNot Required
aux_pricedoubleStop 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 precedenceNot RequiredNot RequiredRequiredRequiredChoose One
trailing_percentdoubleTrailing 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 precedenceNot RequiredNot RequiredNot RequiredNot RequiredChoose One
outside_rthbooleantrue: 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 RequiredOptionalOptionalNot RequiredOptional
trading_session_typeTradingSessionTypeTrading-session enum. Availability depends on the account, market, instrument, and order type. See the enum meanings belowNot RequiredOptionalNot RequiredOptionalNot Required
adjust_limitdoublePrice 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 adjustmentNot RequiredOptionalOptionalOptionalOptional
marketstringMarket (US stocks US, HK stocks HK, Shanghai-HK Stock Connect CN)OptionalOptionalOptionalOptionalOptional
currencystringCurrency (US stocks USD, HK stocks HKD, Shanghai-HK Stock Connect CNH)OptionalOptionalOptionalOptionalOptional
time_in_forcestringThe 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 typeOptionalOptionalOptionalOptionalOptional
expire_timelongOrder validity deadline, 13-digit timestamp in milliseconds (required when time_in_force is GTD, invalid for other types)Not RequiredOptionalOptionalNot RequiredOptional
exchangestringExchange (US stocks SMART, HK stocks SEHK, Shanghai-HK Stock Connect SEHKNTL, Shenzhen-HK Stock Connect SEHKSZSE)OptionalOptionalOptionalOptionalOptional
expirystringExpiry date (options, warrants, CBBCs only)OptionalOptionalOptionalOptionalOptional
strikestringStrike price (options, warrants, CBBCs only)OptionalOptionalOptionalOptionalOptional
rightstringOption right PUT/CALL (options, warrants, CBBCs only)OptionalOptionalOptionalOptionalOptional
multiplierfloatMultiplier, quantity per lot (options, warrants, CBBCs only)OptionalOptionalOptionalOptionalOptional
local_symbolstringThis field is required for warrants and CBBCs, the 5-digit number below the name in the warrant/CBBC list in the APPOptionalOptionalOptionalOptionalOptional
secret_keystringTrader key, for institutional users onlyOptionalOptionalOptionalOptionalOptional
user_markstringOrder 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 charactersOptionalOptionalOptionalOptionalOptional
alloc_accountsList<String>Global accounts only Sub-account list for an allocation order. Entries must be non-empty and correspond by index to alloc_sharesOptionalOptionalOptionalOptionalOptional
alloc_sharesList<Double>Global accounts only Quantity allocated to each corresponding sub-account. Every value must be positive, and the list length must equal alloc_accountsOptionalOptionalOptionalOptionalOptional
algo_strategystringStrategy name for supported algorithm orders onlyOptionalOptionalOptionalOptionalOptional
algo_paramsList<TagValue>Parameters for supported algorithm orders onlyOptionalOptionalOptionalOptionalOptional
sourcestringOrder source identifier. Set it with TradeParamBuilder.source(...); TradeOrderRequest has no corresponding setterOptionalOptionalOptionalOptionalOptional
stop_loss_order_typestringAttached stop-loss order type: STP, STP_LMT, or TRAILOptionalOptionalOptionalOptionalOptional
combo_typestringMulti-leg combination type, typically used for option strategies but not restricted to optionsOptionalOptionalOptionalOptionalOptional
contract_legsList<ContractLeg>Multi-leg contract definitions, typically option legs but not restricted to optionsOptionalOptionalOptionalOptionalOptional
oca_ordersList<TradeOrderModel>OCA child ordersOptionalOptionalOptionalOptionalOptional

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

    ParameterTypeDescriptionAttached Stop LossAttached Profit TakingAttached Trailing StopAttached Bracket
    attach_typestringAttached 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)RequiredRequiredRequiredRequired
    profit_taker_orderIdintProfit taking order ID, can be obtained through the order ID endpoint. If 0 is passed, the server will automatically generate a profit taking order IDNot RequiredOptionalOptionalOptional
    profit_taker_pricedoubleProfit taking order price, required when placing profit taking ordersNot RequiredRequiredNot RequiredRequired
    profit_taker_tifstringSame 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 ordersNot RequiredRequiredNot RequiredRequired
    profit_taker_rthbooleanSame as outside_rth fieldNot RequiredRequiredNot RequiredRequired
    stop_loss_orderIdintStop loss order ID, can be obtained through the order ID endpoint. If 0 is passed, the server will automatically generate a stop loss order IDRequiredNot RequiredNot RequiredRequired
    stop_loss_pricedoubleStop loss order price (stop loss order trigger price), required when placing stop loss ordersRequiredNot RequiredNot RequiredRequired
    stop_loss_limit_pricedoubleStop 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 orderOptionalNot RequiredNot RequiredOptional
    stop_loss_tifstringSame 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 ordersRequiredNot RequiredRequiredRequired
    stop_loss_trailing_percentdoubleTrailing 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 usedOptionalNot RequiredChoose OneOptional
    stop_loss_trailing_amountdoubleTrailing 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.OptionalNot RequiredChoose OneOptional

  • 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, and time_in_force=DAY. Their algorithm parameters include start_time and end_time; VWAP also supports participation_rate.

    ParameterTypeAlgorithm ParameterDescriptionTWAPVWAP
    order_typestringOrder type, TWAP/VWAPRequiredRequired
    accountstringTrading accountRequiredRequired
    symbolstringStock symbol e.g.: AAPLRequiredRequired
    sec_typestringOnly supports STKRequiredRequired
    total_quantitylongOrder quantityRequiredRequired
    algo_paramsList<TagValue>Algorithm parametersOptionalOptional
    -longstart_timeStrategy start time (13-digit millisecond timestamp)OptionalOptional
    -longend_timeStrategy end time (13-digit millisecond timestamp)OptionalOptional
    -Doubleparticipation_rateMaximum participation rate (volume as maximum proportion of daily average volume), valid range 0.01-0.5Not RequiredOptional

  • 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_size quantity to the market at a time to reduce market impact.

    ParameterTypeDescriptionRequired
    order_typestringOrder type, fixed as ICEBERGRequired
    accountstringTrading accountRequired
    symbolstringStock symbol, e.g. AAPLRequired
    sec_typestringContract type, only supports STKRequired
    actionstringOrder side BUY/SELLRequired
    total_quantityintTotal order quantityRequired
    limit_pricedoubleLimit price, required when price_type is LIMIT_PRICEConditional
    display_sizeintDisplay quantity per slice (visible to market); must be positive. Required when min_display_size is suppliedOptional
    min_display_sizeintMinimum display quantity (actual display randomized between [min_display_size, display_size]); must not exceed display_size. Defaults to display_sizeOptional
    check_intervalsintPrice check interval (seconds); must be positive when suppliedOptional
    price_typestringPrice type: LIMIT_PRICE / ASK_PRICE / BID_PRICE / LATEST_PRICE, default LIMIT_PRICEOptional
    start_timelongStrategy effective start time (13-digit millisecond timestamp)Optional
    end_timelongStrategy effective end time (13-digit millisecond timestamp)Optional

    The Java Iceberg builders set time_in_force=DAY. The short overload defaults min_display_size to display_size, leaves check_intervals, start_time, and end_time unset, and uses price_type=LIMIT_PRICE. The full overload also substitutes display_size and LIMIT_PRICE when min_display_size or price_type is null. The builders do not validate the ordering of directly supplied start_time and end_time values.


  • Response

    Account pathReturned fields
    Globalid and deprecated orderId; attached-order placement also returns subIds
    Prime/Paperid, deprecated orderId, subIds, and orders; subIds lists child order IDs and orders contains returned order details

    A 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, TradeOrder may also include cashQuantity, lastFillPrice, goodTillDate, triggerStatus, ocaGroupId, comboLegs, allocAccounts, allocShares, algoStrategy, algoParameters, comboType, comboTypeDesc, legs, displaySize, minDisplaySize, checkIntervals, priceType, startTime, and endTime, 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"
        }
    ]
}




Did this page help you?