Cancel or Modify Orders

Cancel Order

value cancel_order(unsigned long long id)

Description

Cancel an open order

Parameters

ParameterTypeRequiredDescription
idunsigned long longYesOrder id to be cancelled

Example Call

#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;

    ClientConfig config(true, U("tiger_openapi_config.properties"));
   
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

Example Response

cancel order : {"id":38442973239706624}

Modify Order

⚠️

modify_order is not based on order ID, rather on stock ticker, price and quantity.
call works, but might produce incorrect 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 modifiable parameters

Parameters

ParameterTypeRequiredDescription
orderOrderYesOrder object that needs to be modified
limit_pricedoubleNoNew limit price. Required when order_type is LMT/STP/STP_LMT
total_quantitylongNoNew quantity
aux_pricedoubleNoNew stop price (stop order)/trailing price(Trailing Orders) when Required when order_type is set to STP/STP_LMT
trail_stop_pricedoubleNoTrailing activation price for trailing stop orders
trailing_percentdoubleNoTrailing 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_offsetdoubleNo
time_in_forceutility::string_tNoTime in force, 'DAY'-valid until market close, 'GTC'-Good-Till-Cancel
outside_rthboolNoWhether to allow pre-market and post-market trading, exclusive to US stocks

Example Call

#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 = TIGER_API::ContractUtil::stock_contract(U("AAPL"), U("USD"));
        Order order = TIGER_API::OrderUtil::limit_order(trade_client->client_config.account,contract,U("BUY"),1,310.0);
        value place_res = trade_client->place_order(order);
        long long id = place_res.at(U("id")).as_number().to_int64();
        value mod_res = trade_client->modify_order(order, 105);
        Order mod_order = trade_client->get_order(id);

        ucout << "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[]) {

    ClientConfig config(true, U("tiger_openapi_config.properties"));

    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);

    return 0;
}

Example Response

modify order res: {"id":38442973239706624}

Did this page help you?