Place Order
place_order Place Order
value place_order(value &order); value place_order(Order &order);
Description
Interface for placing order. This method allows 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 successfully 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 (NEW, CANCELLED, EXPIRED, REJECTED), 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
Parameters
Order
Object
You can construct an Order
Object using the functions defined in src/order_util.cpp
, such as limit_order() or market_order(). Please see Order Object - Construction for details.
Common Attributes:
Attribute | Type | Description |
---|---|---|
order_type | utility::string_t | Order Types,'MKT'-Market Order / 'LMT'-Limit Order / 'STP'-Stop Order / 'STP_LMT'-Stop-Limit Order / 'TRAIL'-Trail Order |
account | utility::string_t | Account to which the order belongs |
contract | Contract | Order contract |
action | utility::string_t | Order direction,'BUY' for buying,'SELL' for selling orders |
total_quantity | long long | Quantity 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 lot size |
Response
if the order is successfully 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;
}
Market Order (MKT)
Order
OrderUtil::market_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity) {
// market order
return Order(U("MKT"), account, contract, action, quantity);
}
Limit Order (LMT)
Order
OrderUtil::limit_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
double limit_price) {
// limit order
return Order(U("LMT"), account, contract, action, quantity, limit_price);
}
Order OrderUtil::limit_order(Contract &contract, const utility::string_t action, long quantity, double limit_price) {
// limit order
return Order(U("LMT"), U(""), contract, action, quantity, limit_price);
}
Order OrderUtil::limit_order(Contract& contract, const utility::string_t action, long quantity, utility::string_t limit_price) {
// limit order, price is string type
Order order = Order();
order.order_type = U("LMT");
order.contract = contract;
order.action = action;
order.total_quantity = quantity;
order.s_limit_price = limit_price;
return order;
}
Stop Order (STP)
Order OrderUtil::stop_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
double aux_price) {
// stop order
return Order(U("STP"), account, contract, action, quantity, 0, aux_price);
}
Stop Limit Order (STP_LMT)
Order
OrderUtil::stop_limit_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
double limit_price, double aux_price) {
// stop limit order
return Order(U("STP_LMT"), account, contract, action, quantity, limit_price, aux_price);
}
Trail Order (TRAIL)
Order
OrderUtil::trail_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
double aux_price, double trailing_percent) {
// trailing stop order
return Order(U("TRAIL"), account, contract, action, quantity, 0, aux_price, trailing_percent);
}
place_forex_order
value place_forex_order(utility::string_t seg_type, utility::string_t source_currency, utility::string_t target_currency, double source_amount);
Description
Currency exchange order, return Order object
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
seg_type | utility::string_t | Yes | Account segment. Available: SegmentType::SEC for Securities; SegmentType::FUT for Commodities |
source_currency | utility::string_t | Yes | Currency to be converted |
target_currency | utility::string_t | Yes | Currency to be received after conversion |
source_amount | double | Yes | Amount of source_currency to convert |
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_place_forex_order(const std::shared_ptr<TradeClient>& trade_client) {
value res = trade_client->place_forex_order(U("SEC"), U("USD"), U("HKD"), 1.0);
ucout << U("place forex order: ") << res << endl;
}
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
TestTradeClient::test_place_forex_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;
}