Get Order Information

About 6 min

get_orders Get a List of Orders

value get_orders(string account, SecType sec_type = SecType::ALL,
Market market = Market::ALL,
string symbol = "", long start_time = -1, long end_time = -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

Arguments

ArgumentTypeRequiredDescription
accountstrnoAccount id, if left empty, this method witll use the default account id defined in client_config
sec_typeSecurityTypenoSecurity type, you can use the constants defined in tigeropen.common.consts.SecurityType
marketMarketnoFilter by market, you can use the constants defined in tigeropen.common.consts.Market
symbolstrnoTicker symbol of the security
start_timestr/intnoStart time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
end_timestr/intnoEnd time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
is_briefboolnoA bool,if true, the interface will return simplified order data
statusOrderStatusnoOrder Status,yoiu can use constants defined in tigeropen.common.consts.OrderStatus
sort_byOrderSortBynoFields used to sort and filter start_date and end_date,LATEST_CREATED/LATEST_STATUS_UPDATED; Default:LATEST_CREATED
secret_keystrnoSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

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": "402901",
    "action": "BUY",
    "algoStrategy": "LMT",
    "attrDesc": "",
    "avgFillPrice": 0,
    "canCancel": false,
    "canModify": false,
    "commission": 0,
    "currency": "USD",
    "discount": 0,
    "filledQuantity": 0,
    "id": 29404332116673536,
    "identifier": "AAPL",
    "latestTime": 1673313004000,
    "limitPrice": 100,
    "liquidation": false,
    "market": "US",
    "name": "Apple Inc",
    "openTime": 1673236450000,
    "orderId": 1276,
    "orderType": "LMT",
    "outsideRth": true,
    "realizedPnl": 0,
    "remark": "Order is expired",
    "secType": "STK",
    "source": "OpenApi",
    "status": "Cancelled",
    "symbol": "AAPL",
    "timeInForce": "DAY",
    "totalQuantity": 1,
    "updateTime": 1673313004000,
    "userMark": ""
    },
    {
    "account": "402901",
    "action": "BUY",
    "algoStrategy": "LMT",
    "attrDesc": "",
    "avgFillPrice": 0,
    "canCancel": false,
    "canModify": false,
    "commission": 0,
    "currency": "USD",
    "discount": 0,
    "filledQuantity": 0,
    "id": 29404332093867008,
    "identifier": "AAPL",
    "latestTime": 1673236453000,
    "limitPrice": 100,
    "liquidation": false,
    "market": "US",
    "name": "Apple Inc",
    "openTime": 1673236450000,
    "orderId": 1275,
    "orderType": "LMT",
    "outsideRth": true,
    "realizedPnl": 0,
    "secType": "STK",
    "source": "OpenApi",
    "status": "Cancelled",
    "symbol": "AAPL",
    "timeInForce": "DAY",
    "totalQuantity": 1,
    "updateTime": 1673236453000,
    "userMark": ""
    }
]

get_order Get Order

Order get_order(long id);

Description

Retreive an order by its order id

Arguments

ArgumentTypeRequiredDescription
idintyesorder id, this id is used to identify an order on the server

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":"",
    "avgFillPrice":0,
    "canCancel":false,
    "canModify":false,
    "commission":0,
    "currency":"USD",
    "discount":0,
    "filledQuantity":0,
    "id":29143867257783296,
    "identifier":"AAPL",
    "latestTime":1671330602000,
    "limitPrice":100,
    "liquidation":false,
    "market":"US",
    "name":"Apple Inc",
    "openTime":1671249261000,
    "orderId":1176,
    "orderType":"LMT",
    "outsideRth":true,
    "realizedPnl":0,
    "remark":"Order is expired",
    "secType":"STK",
    "source":"OpenApi",
    "status":"Inactive",
    "symbol":"AAPL",
    "timeInForce":"DAY",
    "totalQuantity":1,
    "updateTime":1671330602000,
    "userMark":""
}

get_active_orders Get Open Orders

value get_active_orders(string account, SecType sec_type = SecType::ALL,
                        Market market = Market::ALL,
                        string symbol = "", long start_time = -1, long end_time = -1, long parent_id = 0,
                        OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                        SegmentType seg_type = SegmentType::SEC)

Description

Get a list of open orders

Arguments

ArgumentTypeRequiredDescription
accountstrnoAccount id, if left empty, the API witll return the default account defined in client_config
sec_typeSecurityTypenoSecurity type, you can use the constants defined in tigeropen.common.consts.SecurityType
marketMarketnoAffiliated market,you can use the constants defined in tigeropen.common.consts.Market
symbolstrnoTicker symbol of the security
start_timestr/intnoStart time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
end_timestr/intnoEnd time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
secret_keystrnoSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

Response

list

Each element of this list is an Order object (tigeropen.trade.domain.order.Order), 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

same as get_orders


get_cancelled_orders Get a List of Canceled Orders

value get_cancelled_orders(string account, SecType sec_type = SecType::ALL,
                        Market market = Market::ALL,
                        string symbol = "", long start_time = -1, long end_time = -1, long parent_id = 0,
                        OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                        SegmentType seg_type = SegmentType::SEC)

Description

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

Argument

ArgumentTypeRequiredDescription
accountstrnoAccount id, if left empty, the API witll return the default account defined in client_config
sec_typeSecurityTypenoSecurity type, you can use the constants defined in tigeropen.common.consts.SecurityType
marketMarketnoFilter by market, you can use the constants defined in tigeropen.common.consts.Market
symbolstrnoTicker symbol of the security
start_timestr/intnoStart time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
end_timestr/intnoEnd time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
secret_keystrnoSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

Response

list

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

Example

same as get_orders


get_filled_orders Get a List of Filled Orders

value get_filled_orders(string account, SecType sec_type = SecType::ALL,
                        Market market = Market::ALL,
                        string symbol = "", long start_time = -1, long end_time = -1, long parent_id = 0,
                        OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
                        SegmentType seg_type = SegmentType::SEC)

Description

Get filled order history

Argument

ArgumentTypeRequiredDescription
accountstrnoAccount id, if left empty, the API witll return the default account defined in client_config
sec_typeSecurityTypenoSecurity type, you can use the constants defined in tigeropen.common.consts.SecurityType
marketMarketnoFilter by market, you can use the constants defined in tigeropen.common.consts.Market
symbolstrnoTicker symbol of the security
start_timestr/intnoStart time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
end_timestr/intnoEnd time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
secret_keystrnoSecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user

Responselist

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

Example

Response

same as get_orders


get_transactions Get Transactions

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

Argument

ArgumentTypeRequiredDescription
accountstrnoAccount id, if left empty, the API witll return the default account defined in client_config
order_idintnoOrder id
symbolstrnoTicker symbol of the security, sec_type is required when filtering by symbol
sec_typeSecurityTypenoSecurity type, you can use the constants defined in tigeropen.common.consts.SecurityType
start_timestr/intnoStart time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
end_timestr/intnoEnd time. Unix time in millisecond, or a string of date and time,for example: 1643346000000 or '2019-01-01' or '2019-01-01 12:00:00
limitintnoMaximum record returned
expirystrnoOptions expiration date, format: 'yyyyMMdd', example: '220121'
strikefloatnoOptions strike price, example: 100.5
put_callstrno'PUT' / 'CALL' for options

Responselist Each element of this list is a Transaction object. Transaction

Example

Response Example

Transaction({'account': 111111, 'order_id': 20947299719447552, 'contract': AAPL/STK/USD, 'id': 20947300069016576, 'action': 'BUY', 'filled_quantity': 1, 'filled_price': 132.25, 'filled_amount': 132.25, 'transacted_at': '2020-12-23 17:06:54'}), 

Transaction({'account': 111111, 'order_id': 19837920138101760, 'contract': AAPL/STK/USD, 'id': 19837920740508672, 'action': 'BUY', 'filled_quantity': 1, 'filled_price': 116.21, 'filled_amount': 116.21, 'transacted_at': '2020-09-16 18:02:00'})]
        
Last update: