Cancel or Modify Orders
About 1 min
cancel_order Cancel Order
value cancel_order(long id);
Description
Cancel an open order
Arguments
Arguments | Type | Description |
---|---|---|
account | str | Account id, if left empty, this method witll use the default account id defined in client_config |
id | int | Order id. Using this id to cancel or modify orders is recommended. If you construct the order object locally, this id will be available after placing order to a server. |
order_id | int | Local order id. Accessible with Order.order_id |
secret_key | str | Secret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user |
Response
modify_order Modify Order
value modify_order(Order &order, double limit_price=0, long total_quantity=0, double aux_price=0,
double trail_stop_price=0, double trailing_percent=0, double percent_offset=0,
string time_in_force="", bool outside_rth=false, long expire_time=0)
Description
Modify an order. Refer to the argument list for parameters that can be modified
Arguments
Arguments | Type | Required | Description |
---|---|---|---|
order | Order | Order object that needs to be modified(tigeropen.trade.domain.order.Order) | |
quantity | int | New quantity | |
limit_price | float | New limit price. Required when order_type is LMT/STP/STP_LMT | |
aux_price | float | New stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT | |
trail_stop_price | float | Trailing activation price for trailing stop orders | |
trailing_percent | float | Trailing activation price for trailing stop orders (by percentage), when order_type is set to TRAIL, assigning value to both aux_price and trailing_percent will get an error | |
time_in_force | str | Time in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel | |
outside_rth | bool | if trade outside regular trading hours (only applicable to U.S. market) | |
secret_key | str | Secret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user |
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_modify_order(const std::shared_ptr<TradeClient>& trade_client) {
Contract contract = stock_contract("AAPL", "USD");
Order order = limit_order(contract, "BUY", 1, 100.0);
long id = (long) trade_client->place_order(order)["id"].as_number().to_uint64();
value res = trade_client->modify_order(order, 105);
cout << "modify order res: " << res << endl;
Order mod_order = trade_client->get_order(id);
cout << "modified order: " << mod_order.to_string() << endl;
}
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
TestTradeClient::test_modify_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;
}