Place Order
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
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:
Attribute | Type | Description |
---|---|---|
action | str | Order direction,'BUY' for buying,'SELL' for selling orders |
order_type | str | Order Types,'MKT'-Market Order / 'LMT'-Limit Order / 'STP'-Stop Order / 'STP_LMT'-Stop-Limit Order / 'TRAIL'-Trail Order |
time_in_force | str | Time in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel, 'GTD' Good-Till-Date |
limit_price | float | Limit price, required if placing a limit order |
quantity | int | Quantiy 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
Argument | Type | Description | Market Order | Limit Order | Stop Order | Stop Limit Order | Trail Order |
---|---|---|---|---|---|---|---|
account | str | Account id | optional | optional | optional | optional | optional |
contract | Contract | Contract object | |||||
action | str | 'BUY' or 'SELL' | |||||
order_type | str | Order type, 'MKT' market order / 'LMT' limit order / 'STP' stop loss order / 'STP_LMT' stop loss limit order / 'TRAIL' trailing stop loss order | MKT | LMT | STP | STP_LMT | TRAIL |
quantity | int | Order quantity, an integer greater than 0 | |||||
limit_price | float | limit price, when order type is LMT or STP_LMT ,this field is required | |||||
aux_price | float | Indicates the stop price on a stop order; indicates the spread on a trailing stop order | |||||
trail_stop_price | float | Trailing Stop Order - the price at which the stop loss order is triggered | |||||
trailing_percent | float | Trailing stop loss order--percentage | |||||
adjust_limit | float | Price 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 adjustment | optional | optional | optional | optional | |
time_in_force | str | The validity period of the order can only be DAY (valid on the day) and GTC (valid until canceled), and the default is DAY | optional | optional | optional | optional | optional |
outside_rth | bool | True: 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) | optional | optional | optional | ||
order_legs | object | Attach Order Params | optional | optional | optional | optional | optional |
algo_params | object | Algo Order Params | optional | optional | optional | optional | optional |
secret_key | str | Dedicated to institutional users, trader key | optional | optional | optional | optional | optional |
user_mark | str | Order 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) | optional | optional | optional | optional | optional |