Place Order

About 4 min

place_oder Place Order

TradeClient.place_order():

Description

Interface for placing order. This method alllows you to set order types, quantity, buy/sell, of you choice, please see below for more information.

Please read the Introduction section of this documentation, as well as FAQ-Trade-Supported Order Types section,to make sure that the order types involved in your program are actually allowed.

If this method returns an error, or that your order gets canceled by the system, it is recommended that you refer to FAQ-Trade section for a quick inspection yourself.

When a order is sucessfully placed, the id attribute in Order object will be filled (order.id). This id can be used to identify a unique order and thus can be used to modify or cancel an order.

  • Market Order(MKT)and Stop Order(STP)do not support pre-market and post-market transactions. When placing the order, you need to set 'outside_rth' to false
  • For the symbol that can be shorted, the lock-up function is not currently supported, so it is impossible to hold long and short positions of the same symbol at the same time
  • Attached Order currently only supports limit orders
  • Market Order(MKT) and the paper trade account,GTC is not supported for 'time_in_force' parameter
  • The paper trade account currently does not support warrants and CBBC orders

Order Status Explanation

  • How can I determine the partial fulfillment status of my Prime or Paper accounts?

When the order status is not FILLED (may be NEW, CANCELLED, EXPIRED, REJECTED one of them), it may be a partially filled status, which can be judged by whether the number of orders filled is greater than 0.

  • How to determine the partial transaction status of Global Account?

The order status is FILLED, and the order quantity is greater than 0

Order Status Flow

Order Status Flow

Argument

Order Object (tigeropen.trade.domain.order.Order)

You can construct an Order Object using the functions defined in tigeropen.common.util.order_utils, such as limit_order() or market_order(). Please see Order Object - Construction for details. Another construction method is to use TradeClient.create_order() to request an order_id to create an order object (deprecated)

Common attributes:

AttributeTypeDescription
actionstrOrder direction,'BUY' for buying,'SELL' for selling orders
order_typestrOrder Types,'MKT'-Market Order / 'LMT'-Limit Order / 'STP'-Stop Order / 'STP_LMT'-Stop-Limit Order / 'TRAIL'-Trail Order
time_in_forcestrTime in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel, 'GTD' Good-Till-Date
limit_pricefloatLimit price, required if placing a limit order
quantityintQuantiy of the order,must be an integer greater than 0. Quantity must be a multiple of the lot size, You can use TradeClient.get_trade_metas to check the lotsize

Response

if the order is sucessfully placed , will return success,otherwise it will throw an exception.

Example 1

#include "tigerapi/trade_client.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"

using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;

class TestTradeClient {
public:
    static void test_place_order(const std::shared_ptr<TradeClient>& trade_client) {
        Contract contract = stock_contract("AAPL", "USD");
        Order order = limit_order(contract, "BUY", 1, 100.0);
        value res = trade_client->place_order(order);
        long id = res["id"].as_integer();
        cout << "order id: " << id << endl;
        cout << "place order result: " << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_orders(trade_client);
    }
};

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private key xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";


    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

create_order Create Order

TradeClient.create_order():

Description

Request order id, create order object.(not recommend), recommend use tigeropen.common.util.order_utils tool method, such as limit_order, market_order.

Argument

ArgumentTypeDescriptionMarket OrderLimit OrderStop OrderStop Limit OrderTrail Order
accountstrAccount idoptionaloptionaloptionaloptionaloptional
contractContractContract object
actionstr'BUY' or 'SELL'
order_typestrOrder type, 'MKT' market order / 'LMT' limit order / 'STP' stop loss order / 'STP_LMT' stop loss limit order / 'TRAIL' trailing stop loss orderMKTLMTSTPSTP_LMTTRAIL
quantityintOrder quantity, an integer greater than 0
limit_pricefloatlimit price, when order type is LMT or STP_LMT ,this field is required
aux_pricefloatIndicates the stop price on a stop order; indicates the spread on a trailing stop order
trail_stop_pricefloatTrailing Stop Order - the price at which the stop loss order is triggered
trailing_percentfloatTrailing stop loss order--percentage
adjust_limitfloatPrice fine-tuning range (default is 0 means no adjustment, positive number means upward adjustment, negative number means downward adjustment), and the incoming price is automatically adjusted to the legal price. For example: 0.001 is an upward adjustment of up to 0.1%; -0.001 is a downward adjustment of up to 0.1%. Default 0 means no adjustmentoptionaloptionaloptionaloptional
time_in_forcestrThe validity period of the order can only be DAY (valid on the day) and GTC (valid until canceled), and the default is DAYoptionaloptionaloptionaloptionaloptional
outside_rthboolTrue: Allow pre-market and after-hours trading (exclusive to US stocks), False: Not allowed, the default is True. (The market order is only valid in the intraday, and the outside_rth parameter will be ignored)optionaloptionaloptional
order_legsobjectAttach Order Paramsoptionaloptionaloptionaloptionaloptional
algo_paramsobjectAlgo Order Paramsoptionaloptionaloptionaloptionaloptional
secret_keystrDedicated to institutional users, trader keyoptionaloptionaloptionaloptionaloptional
user_markstrOrder remark information, which cannot be modified after the order is placed, and userMark information will be returned when querying the order (need to configure the developer's personal information)optionaloptionaloptionaloptionaloptional
Last update: