Cancel or Modify Orders

About 1 min

cancel_order Cancel Order

value cancel_order(long id);

Description

Cancel an open order

Arguments

ArgumentsTypeDescription
accountstrAccount id, if left empty, this method witll use the default account id defined in client_config
idintOrder 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_idintLocal order id. Accessible with Order.order_id
secret_keystrSecret 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

ArgumentsTypeRequiredDescription
orderOrderOrder object that needs to be modified(tigeropen.trade.domain.order.Order)
quantityintNew quantity
limit_pricefloatNew limit price. Required when order_type is LMT/STP/STP_LMT
aux_pricefloatNew stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT
trail_stop_pricefloatTrailing activation price for trailing stop orders
trailing_percentfloatTrailing 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_forcestrTime in force,'DAY'-valid until market close,'GTC'-Good-Till-Cancel
outside_rthboolif trade outside regular trading hours (only applicable to U.S. market)
secret_keystrSecret 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;
}
Last update: