Get Order Information

About 8 min

get_order Get Order

Order get_order(unsigned long long id, bool is_brief=false));

Description

Retrieve an order by its order id

Parameters

ParameterTypeRequiredDescription
idunsigned long longyesorder id
is_briefboolNoWhether to return simplified order data (Global Accounts Only)
default: false

Response

Order object

Refer to Order object for more details

Example

#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_get_order(const std::shared_ptr<TradeClient>& trade_client) {
//        Contract contract = stock_contract("AAPL", "USD");
//        Order order = limit_order(contract, "BUY", 1, 100.0);
//        trade_client->place_order(order);
        Order my_order = trade_client->get_order(29270263515317248);
        cout << "order : " << my_order.to_string() << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_order(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;
}

Response

{
    "account":"402901",
    "action":"BUY",
    "algoStrategy":"LMT",
    "attrDesc":"",
    "attrList":["ALGORITHM","NON_TRADING_HOURS","TEST_ORDER"],
    "avgFillPrice":0,
    "canCancel":false,
    "canModify":false,
    "cancelStatus":"NONE",
    "commission":0,
    "currency":"USD",
    "discount":0,
    "externalId":"939",
    "filledCashAmount":0,
    "filledQuantity":0,
    "filledQuantityScale":0,
    "gst":0,
    "id":29143867257783296,
    "identifier":"AAPL",
    "isOpen":true,
    "latestTime":1671330602000,
    "limitPrice":100,
    "liquidation":false,
    "market":"US",
    "name":"Apple Inc",
    "openTime":1671249261000,
    "orderDiscount":0,
    "orderId":1176,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "remark":"Order is expired",
    "replaceStatus":"NONE",
    "secType":"STK",
    "source":"OpenApi",
    "status":"Inactive",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "totalQuantityScale":0,
    "updateTime":1671330602000,
    "userMark":""
}

get_orders Get a List of Orders

value get_orders(const utility::string_t &account = U(""), const utility::string_t &sec_type = U(""),
                 const utility::string_t &market = U("ALL"),
                 const utility::string_t &symbol = U(""), time_t start_date = -1, time_t end_date = -1, int limit = 100,
                 bool is_brief = false, const value &states = value::array(), const utility::string_t &sort_by = U(""),
                 const utility::string_t &seg_type = U(""));
value get_orders(utility::string_t account, SecType sec_type = SecType::ALL,
                 Market market = Market::ALL,
                 utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, int limit = 100,
                 bool is_brief = false, const value &states = value::array(),
                 OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                 SegmentType seg_type = SegmentType::SEC);

Description

Get a list of all history orders of a specific account id. You can filter the orders by parameters listed below

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id, if left empty, this method will use the default account id defined in client_config
sec_typeSecTypeNoSecurity type
marketMarketNoFilter by market
symbolutility::string_tNoTicker symbol of the security
start_datetime_tNoStart time. Unix time in millisecond, for example: 1643346000000
Default: -1
end_datetime_tNoEnd time. Unix time in millisecond,for example: 1643346000000
Default: -1
limitintNoThe number of orders retrieved each time
Default: 100
is_briefboolNoA bool,if true, the interface will return simplified order data
stateslist<OrderStatus>NoA list of order status enumerations
sort_byOrderSortByNoFields used to sort and filter start_date and end_date,LATEST_CREATED/LATEST_STATUS_UPDATED; Default:LATEST_STATUS_UPDATED
seg_typeSegmentTypeNoAccount segment

Response

value

Example

#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_get_orders(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_orders();
        cout << "orders: " << 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;
}

Response

[
  {
    "account":"572386",
    "action":"BUY", 
    "algoStrategy":"LMT",
    "attrDesc":"",
    "attrList":["ALGORITHM","NON_TRADING_HOURS","TEST_ORDER"],
    "avgFillPrice":0,
    "canCancel":false,
    "canModify":false,
    "cancelStatus":"NONE",
    "commission":0,
    "currency":"USD",
    "discount":0,
    "externalId":"953",
    "filledCashAmount":0,
    "filledQuantity":0,
    "filledQuantityScale":0,
    "gst":0,
    "id":31070403805184000,
    "identifier":"AAPL",
    "isOpen":true,
    "latestTime":1686010200000,
    "limitPrice":100,
    "liquidation":false,
    "market":"US",
    "name":"Apple",
    "openTime":1685947568000,
    "orderDiscount":0,
    "orderId":953,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "remark":"Order is expired",
    "replaceStatus":"NONE",
    "secType":"STK",
    "source":"OpenApi",
    "status":"Cancelled",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "totalQuantityScale":0,
    "updateTime":1686010200000,
    "userMark":""
  },
  {
    "account":"572386",
    "action":"BUY",
    "algoStrategy":"LMT",
    "attrDesc":"",
    "attrList":["ALGORITHM","NON_TRADING_HOURS","TEST_ORDER"],
    "avgFillPrice":0,
    "canCancel":false,
    "canModify":false,
    "cancelStatus":"RECEIVED",
    "commission":0,
    "currency":"USD",
    "discount":0,
    "externalId":"952",
    "filledCashAmount":0,
    "filledQuantity":0,
    "filledQuantityScale":0,
    "gst":0,
    "id":31070403803482112,
    "identifier":"AAPL",
    "isOpen":true,
    "latestTime":1685947571000,
    "limitPrice":100,
    "liquidation":false,
    "market":"US",
    "name":"Apple",
    "openTime":1685947568000,
    "orderDiscount":0,
    "orderId":952,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "replaceStatus":"NONE",
    "secType":"STK",
    "source":"OpenApi",
    "status":"Cancelled",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "totalQuantityScale":0,
    "updateTime":1685947571000,
    "userMark":""
  }
]

get_active_orders Get Open Orders

value get_active_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
                        utility::string_t market = U("ALL"),
                        utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
                        utility::string_t sort_by = U(""),
                        utility::string_t seg_type = U(""));

value get_active_orders(utility::string_t account, SecType sec_type = SecType::ALL,
                        Market market = Market::ALL,
                        utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
                        OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                        SegmentType seg_type = SegmentType::SEC);

Description

Get a list of open orders

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id, if left empty, the API will return the default account defined in client_config
sec_typeSecTypeNoSecurity type
default: SecType::ALL
marketMarketNoAffiliated market
default: Market:ALL
symbolutility::string_tNoTicker symbol of the security
start_datetime_tNoStart time. Unix time in milliseconds
end_datetime_tNoEnd time. Unix time in milliseconds
parent_idunsigned long longNoMain order id
sort_byOrderSortByNoFields used to sort and filter start_date and end_date,LATEST_CREATED/LATEST_STATUS_UPDATED; Default:LATEST_STATUS_UPDATED
seg_typeSegmentTypeNoAccount segment
default: SegmentType::SEC

Response

list

Each element of this list is an Order object (include/tigerapi/enums.h), Refer to Order object for details

Example

#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_get_active_orders(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_active_orders();
        cout << "active orders: " << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_active_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;
}

Response

[
  {
    "account":"572386",
    "action":"BUY",
    "algoStrategy":"LMT",
    "attrDesc":"",
    "attrList":["ALGORITHM","NON_TRADING_HOURS","TEST_ORDER"],
    "avgFillPrice":0,
    "canCancel":true,
    "canModify":true,
    "cancelStatus":"NONE",
    "commission":0,
    "currency":"USD",
    "discount":0,
    "externalId":"1026",
    "filledCashAmount":0,
    "filledQuantity":0,
    "filledQuantityScale":0,
    "gst":0,
    "id":38442973239706624,
    "identifier":"AAPL",
    "isOpen":true,
    "latestPrice":213.28999999999999,
    "latestTime":1742195809000,
    "limitPrice":105,
    "liquidation":false,
    "market":"US",
    "name":"Apple",
    "openTime":1742195809000,
    "orderDiscount":0,
    "orderId":1026,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "remark":"Change order succeeded",
    "replaceStatus":"REPLACED",
    "secType":"STK",
    "source":"OpenApi",
    "status":"PendingSubmit",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "totalQuantityScale":0,
    "tradingSessionType":"PRE_RTH_POST",
    "updateTime":1742195810000,
    "userMark":""
  }
]


get_inactive_orders Get a List of Inactive Orders

value get_inactive_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
                          utility::string_t market = U("ALL"),
                          utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
                          utility::string_t sort_by = U(""),
                          utility::string_t seg_type = U(""));

value get_inactive_orders(utility::string_t account, SecType sec_type = SecType::ALL,
                          Market market = Market::ALL,
                          utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
                          OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                          SegmentType seg_type = SegmentType::SEC);

Description

Get a list of inactive orders. The list also includes orders that are cancelled by our system, and any orders that are expired but not filled.

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id, if left empty, the API witll return the default account defined in client_config
sec_typeSecTypeNoSecurity type
default: SecType::ALL
marketMarketNoFilter by market
default: Market::ALL
symbolutility::string_tNoTicker symbol of the security
start_datetime_tNoStart time. Unix time in milliseconds
end_datetime_tNoEnd time. Unix time in milliseconds
parent_idunsigned long longNoMain order id
sort_byOrderSortByNoFields used to sort and filter start_date and end_date,LATEST_CREATED/LATEST_STATUS_UPDATED; Default:LATEST_STATUS_UPDATED
seg_typeSegmentTypeNoAccount segment
default: SegmentType::SEC

Response

list

Each element of this list is an Order object. Refer to Order object for details

#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_get_inctive_orders(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_inactive_orders();
        cout << "inactive orders: " << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_inactive_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;
}

Example

[
  {
    "account":"572386",
    "action":"BUY",
    "algoStrategy":"LMT",
    "attrDesc":"",
    "attrList":["ALGORITHM","NON_TRADING_HOURS","TEST_ORDER"],
    "avgFillPrice":0,
    "canCancel":false,
    "canModify":false,
    "cancelStatus":"RECEIVED",
    "commission":0,
    "currency":"USD",
    "discount":0,
    "externalId":"1026",
    "filledCashAmount":0,
    "filledQuantity":0,
    "filledQuantityScale":0,
    "gst":0,
    "id":38442973239706624,
    "identifier":"AAPL",
    "isOpen":true,
    "latestTime":1742195998000,
    "limitPrice":105,
    "liquidation":false,
    "market":"US",
    "name":"Apple",
    "openTime":1742195809000,
    "orderDiscount":0,
    "orderId":1026,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "replaceStatus":"NONE",
    "secType":"STK",
    "source":"OpenApi",
    "status":"Cancelled",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "totalQuantityScale":0,
    "tradingSessionType":"PRE_RTH_POST",
    "updateTime":1742195998000,
    "userMark":""
  }
]


get_filled_orders Get a List of Filled Orders

value get_filled_orders(utility::string_t account, SecType sec_type = SecType::ALL,
                        Market market = Market::ALL,
                        utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
                        OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                        SegmentType seg_type = SegmentType::SEC);

Description

Get filled order history

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id, if left empty, the API witll return the default account defined in client_config
sec_typeSecTypeNoSecurity type
default: SecType::ALL
marketMarketNoAffiliated market
default: Market:ALL
symbolutility::string_tNoTicker symbol of the security
start_datetime_tNoStart time. Unix time in milliseconds
end_datetime_tNoEnd time. Unix time in milliseconds
parent_idunsigned long longNoMain order id
sort_byOrderSortByNoFields used to sort and filter start_date and end_date,LATEST_CREATED/LATEST_STATUS_UPDATED; Default:LATEST_STATUS_UPDATED
seg_typeSegmentTypeNoAccount segment
default: SegmentType::SEC

Responselist

Each element of this list is an order object, refer to Order object for details

Response

same as get_orders but filtered by filled orders


get_transactions Get Transactions

value get_transactions(utility::string_t account, long long order_id);
value get_transactions(utility::string_t account, utility::string_t symbol, utility::string_t sec_type = U(""),
                       long start_time = -1, time_t end_time = -1,
                       int limit = 100, utility::string_t expiry = U(""), utility::string_t strike = U(""), utility::string_t right = U(""),
                       long long order_id = 0);

Description

Get a detailed list of filled order (Only for Prime Account)。

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id
order_idintYesOrder id
ParameterTypeRequiredDescription
accountutility::string_tYesAccount id
symbolutility::string_tYesTicker symbol of the security
sec_typeSecTypeNoSecurity type
start_timelongNoStart time. Unix time in millisecond,for example: 1643346000000
end_timelongNoEnd time. Unix time in millisecond, for example: 1643346000000
limitintNoMaximum record returned
expiryutility::string_tNoOptions expiration date, format: 'yyyyMMdd', example: '220121'
strikeutility::string_tNoOptions strike price, example: 100.5
rightutility::string_tNo'PUT' / 'CALL' for options
order_idintNoOrder id

Responselist

FieldTypeDescription
accountIdintAccount id
actionutility::string_tOrder direction
currencyutility::string_tCurrency
filledAmountfloatTransacted amount
filledPricefloatTransacted price
filledQuantityintTransacted quantity
idintTransaction id
marketutility::string_tMarket
orderIdintOrder id
secTypeutility::string_tSecurity type
symbolutility::string_tTicker symbol of the security
transactedAtutility::string_tTransacted time given as "yyyy-mm-dd 00:00::00"
transactionTimetime_tTransacted time given in milliseconds

Example

#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_get_transactions(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_transactions(trade_client->client_config.account,U("AAPL"));
        cout << U("transactions: ") << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_transactions(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;
}

Response Example

[
  {
    "accountId":572386,
    "action":"BUY",
    "currency":"USD",
    "filledAmount":100,
    "filledPrice":25.5749,
    "filledQuantity":391,
    "id":35631544146200576,
    "market":"SI",
    "orderId":35620179683181568,
    "secType":"FUND",
    "symbol":"LU0689472784.USD",
    "transactedAt":"2024-07-11 00:00:00",
    "transactionTime":1720627200000
  },
  {
    "accountId":572386,
    "action":"BUY",
    "currency":"USD",
    "filledAmount":99.989999999999995,
    "filledPrice":25.326899999999998,
    "filledQuantity":3948,
    "id":35586246013878272,
    "market":"SI",
    "orderId":35540907181473792,
    "secType":"FUND",
    "symbol":"LU0689472784.USD",
    "transactedAt":"2024-07-05 00:00:00",
    "transactionTime":1720108800000
  }
]
Last update: