Cancel or Modify Orders
About 2 min
cancel_order Cancel Order
value cancel_order(unsigned long long id)
Description
Cancel an open order
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
id | unsigned long long | Yes | Order id to be cancelled |
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_cancel_order(const std::shared_ptr<TradeClient>& trade_client) {
value res = trade_client->cancel_order(38442973239706624);
ucout << U("cancel order : ") << res << endl;
}
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
TestTradeClient::test_cancel_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
cancel order : {"id":38442973239706624}
modify_order Modify Order
value modify_order(Order &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,
utility::string_t time_in_force=U(""), bool outside_rth=false, time_t expire_time=0);
Description
Modify an order. Refer to the parameter list for parameters that can be modified
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
order | Order | Yes | Order object that needs to be modified |
limit_price | double | No | New limit price. Required when order_type is LMT/STP/STP_LMT |
total_quantity | long | No | New quantity |
aux_price | double | No | New stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT |
trail_stop_price | double | No | Trailing activation price for trailing stop orders |
trailing_percent | double | No | 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 |
percent_offset | double | No | |
time_in_force | utility::string_t | No | Time in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel |
outside_rth | bool | No | Whether to allow pre-market and post-market trading, exclusive to US stocks |
expire_time | time_t | No | GTD Order expire time |
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;
}
Response
modify order res: {"id":38442973239706624}