Skip to content

Commit b3e91c6

Browse files
committed
Merge branch 'feature_mac' of https://git.tigerbrokers.net/server/openapi/openapi-cpp-sdk into feature_mac
2 parents 33c143a + 47139b8 commit b3e91c6

File tree

8 files changed

+157
-44
lines changed

8 files changed

+157
-44
lines changed

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class TestTradeClient {
9191

9292

9393
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
94-
TestTradeClient::test_get_position(trade_client);
94+
TestTradeClient::test_place_order(trade_client);
9595
}
9696
};
9797

@@ -133,7 +133,7 @@ class TestQuoteClient {
133133
value symbols = value::array();
134134
symbols[0] = value::string(U("AAPL"));
135135
symbols[1] = value::string(U("JD"));
136-
value result = quote_client->get_timeline(symbols);
136+
value result = quote_client->get_timeline(symbols, false, 1675167178931);
137137
ucout << U("result: ") << result << endl;
138138
}
139139

@@ -299,7 +299,7 @@ class TestQuoteClient {
299299
}
300300

301301
static void test_quote(const std::shared_ptr<QuoteClient> quote_client) {
302-
TestQuoteClient::test_get_option_brief(quote_client);
302+
TestQuoteClient::test_get_timeline(quote_client);
303303
}
304304
};
305305

@@ -351,6 +351,7 @@ int main()
351351
U("-----END RSA PRIVATE KEY-----");
352352
config.tiger_id = U("2");
353353
config.account = U("402901");
354+
// config.lang = U("en_US");
354355

355356

356357
/**
@@ -363,8 +364,8 @@ int main()
363364
/**
364365
* ʹ�÷�װ��Ľ��׽ӿ� TradeClient
365366
*/
366-
// std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
367-
// TestTradeClient::test_trade(trade_client);
367+
// std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
368+
// TestTradeClient::test_trade(trade_client);
368369

369370
/**
370371
* ֱ��ʹ��δ��װ�� TigerApi

include/tigerapi/client_config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace TIGER_API {
3030
account(std::move(account)) {};
3131

3232
ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account,
33-
bool sandbox_debug = false) :
33+
bool sandbox_debug = false, utility::string_t lang = U("en_US")) :
3434
tiger_id(std::move(tiger_id)), private_key(std::move(private_key)),
35-
account(std::move(account)), sandbox_debug(sandbox_debug) {
35+
account(std::move(account)), sandbox_debug(sandbox_debug), lang(lang) {
3636
if (sandbox_debug) {
3737
server_url = SANDBOX_TIGER_SERVER_URL;
3838
server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
@@ -44,6 +44,7 @@ namespace TIGER_API {
4444
utility::string_t account;
4545
utility::string_t charset = U("UTF-8");
4646
utility::string_t sign_type = U("RSA");
47+
utility::string_t lang;
4748
utility::string_t device_id = get_device_id();
4849

4950
void set_server_url(const utility::string_t &url) {

include/tigerapi/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static utility::string_t P_METHOD = U("method");
1010
static utility::string_t P_CHARSET = U("charset");
1111
static utility::string_t P_SIGN_TYPE = U("sign_type");
1212
static utility::string_t P_SIGN = U("sign");
13+
static utility::string_t P_LANG = U("lang");
1314
static utility::string_t P_TIMESTAMP = U("timestamp");
1415
static utility::string_t P_VERSION = U("version");
1516
static utility::string_t P_ITEMS = U("items");

include/tigerapi/model.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class OPENAPI_EXPORT Contract {
4343
utility::string_t right;
4444
int multiplier = 0;
4545
utility::string_t contract_month;
46-
long contract_id;
46+
long contract_id = 0;
4747
utility::string_t identifier;
4848
utility::string_t market;
4949
};
@@ -64,21 +64,21 @@ class OPENAPI_EXPORT Order {
6464

6565
Contract contract;
6666
utility::string_t account;
67-
long id;
68-
long order_id;
67+
long id=0;
68+
long order_id=0;
6969
/** 订单类型, 'MKT' 市价单 / 'LMT' 限价单 / 'STP' 止损单 / 'STP_LMT' 止损限价单 / 'TRAIL' 跟踪止损单 **/
7070
utility::string_t order_type;
7171
/** 交易方向, 'BUY' / 'SELL' **/
7272
utility::string_t action;
7373
/** 下单数量 **/
74-
long total_quantity;
74+
long total_quantity=0;
7575
/** 限价单价格 **/
76-
double limit_price;
76+
double limit_price=0;
7777
/** 在止损单中, 表示触发止损单的价格, 在移动止损单中, 表示跟踪的价差 **/
78-
double aux_price;
79-
double trail_stop_price;
80-
double trailing_percent;
81-
double percent_offset;
78+
double aux_price=0;
79+
double trail_stop_price=0;
80+
double trailing_percent=0;
81+
double percent_offset=0;
8282
/** 有效期,'DAY' 日内有效 / 'GTC' good till cancel / 'GTD' good till date **/
8383
utility::string_t time_in_force;
8484
/** 是否允许盘前盘后交易(outside of regular trading hours 美股专属). True 允许, False 不允许 **/
@@ -89,20 +89,20 @@ class OPENAPI_EXPORT Order {
8989
*/
9090
bool adjust_limit;
9191
utility::string_t user_mark;
92-
long expire_time;
92+
long expire_time=0;
9393

9494
// 订单状态
9595
utility::string_t status;
9696
// 主订单id, 目前只用于 TigerTrade App端的附加订单中
9797
long parent_id;
9898
// 下单时间
99-
long open_time;
99+
time_t open_time;
100100
// 下单失败时, 会返回失败原因的描述
101101
utility::string_t reason;
102102
// 最新成交时间
103-
long latest_time;
103+
time_t latest_time;
104104
// order updated time
105-
long update_time;
105+
time_t update_time;
106106
// 成交数量
107107
long filled_quantity;
108108
// 包含佣金的平均成交价

include/tigerapi/trade_client.h

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ namespace TIGER_API {
5252
value get_positions(utility::string_t account = U(""), SecType sec_type = SecType::ALL, Currency currency = Currency::ALL,
5353
Market market = Market::ALL,
5454
utility::string_t symbol = U(""), const value &sub_accounts = value::array(), time_t expiry = -1,
55-
double strike = 0, Right right = Right::ALL);
55+
utility::string_t strike = U(""), Right right = Right::ALL);
5656

5757
value get_positions(const utility::string_t &account, const utility::string_t &sec_type = U(""), const utility::string_t &currency = U("ALL"),
5858
const utility::string_t &market = U("ALL"),
5959
const utility::string_t &symbol = U(""), const value &sub_accounts = value::array(), time_t expiry = -1,
60-
double strike = 0, const utility::string_t &right = U(""));
60+
utility::string_t strike = U(""), const utility::string_t &right = U(""));
6161

6262
vector<Position> get_position_list(utility::string_t account = U(""), utility::string_t sec_type = U(""), utility::string_t currency = U("ALL"),
6363
utility::string_t market = U("ALL"),
6464
utility::string_t symbol = U(""), const value &sub_accounts = value::array(), time_t expiry = -1,
65-
double strike = 0, utility::string_t right = U(""));
65+
utility::string_t strike = U(""), utility::string_t right = U(""));
6666
/**
6767
* 获取订单列表
6868
* @param account
@@ -80,27 +80,53 @@ namespace TIGER_API {
8080
*/
8181
value get_orders(const utility::string_t &account = U(""), const utility::string_t &sec_type = U(""),
8282
const utility::string_t &market = U("ALL"),
83-
const utility::string_t &symbol = U(""), long start_time = -1, time_t end_time = -1, int limit = 100,
83+
const utility::string_t &symbol = U(""), time_t start_time = -1, time_t end_time = -1, int limit = 100,
8484
bool is_brief = false, const value &states = value::array(), const utility::string_t &sort_by = U(""),
8585
const utility::string_t &seg_type = U(""));
8686

8787
value get_orders(utility::string_t account, SecType sec_type = SecType::ALL,
8888
Market market = Market::ALL,
89-
utility::string_t symbol = U(""), long start_time = -1, time_t end_time = -1, int limit = 100,
89+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, int limit = 100,
9090
bool is_brief = false, const value &states = value::array(),
9191
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
9292
SegmentType seg_type = SegmentType::SEC);
9393

9494
/** 获取未成交订单 **/
9595
value get_active_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
9696
utility::string_t market = U("ALL"),
97-
utility::string_t symbol = U(""), long start_time = -1, time_t end_time = -1, long parent_id = 0,
97+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
9898
utility::string_t sort_by = U(""),
9999
utility::string_t seg_type = U(""));
100100

101101
value get_active_orders(utility::string_t account, SecType sec_type = SecType::ALL,
102102
Market market = Market::ALL,
103-
utility::string_t symbol = U(""), long start_time = -1, time_t end_time = -1, long parent_id = 0,
103+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
104+
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
105+
SegmentType seg_type = SegmentType::SEC);
106+
107+
/** 获取已成交订单 **/
108+
value get_filled_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
109+
utility::string_t market = U("ALL"),
110+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
111+
utility::string_t sort_by = U(""),
112+
utility::string_t seg_type = U(""));
113+
114+
value get_filled_orders(utility::string_t account, SecType sec_type = SecType::ALL,
115+
Market market = Market::ALL,
116+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
117+
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
118+
SegmentType seg_type = SegmentType::SEC);
119+
120+
/** 获取已取消订单 **/
121+
value get_inactive_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
122+
utility::string_t market = U("ALL"),
123+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
124+
utility::string_t sort_by = U(""),
125+
utility::string_t seg_type = U(""));
126+
127+
value get_inactive_orders(utility::string_t account, SecType sec_type = SecType::ALL,
128+
Market market = Market::ALL,
129+
utility::string_t symbol = U(""), time_t start_time = -1, time_t end_time = -1, long parent_id = 0,
104130
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
105131
SegmentType seg_type = SegmentType::SEC);
106132

@@ -114,14 +140,14 @@ namespace TIGER_API {
114140
value modify_order(Order &order);
115141
value modify_order(Order &order, double limit_price=0, long total_quantity=0, double aux_price=0,
116142
double trail_stop_price=0, double trailing_percent=0, double percent_offset=0,
117-
utility::string_t time_in_force=U(""), bool outside_rth=false, long expire_time=0);
143+
utility::string_t time_in_force=U(""), bool outside_rth=false, time_t expire_time=0);
118144

119145

120146
value get_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t currency = U(""), utility::string_t exchange = U(""), time_t expiry = -1,
121-
double strike = 0, utility::string_t right = U(""));
147+
utility::string_t strike = U(""), utility::string_t right = U(""));
122148
value
123149
get_contract(utility::string_t symbol, SecType sec_type = SecType::STK, Currency currency = Currency::ALL, utility::string_t exchange = U(""), time_t expiry = -1,
124-
double strike = 0, Right right = Right::ALL);
150+
utility::string_t strike = U(""), Right right = Right::ALL);
125151

126152

127153

src/common/sign_util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ utility::string_t sha1_sign(const utility::string_t& context, const utility::str
7575
int ret = RSA_sign(NID_sha1, hash, SHA_DIGEST_LENGTH,
7676
encrypted, &encrypted_length, rsa);
7777
if (ret == 1) {
78-
7978
utility::string_t s(encrypted, encrypted + encrypted_length);
8079
return s;
8180
}

src/tiger_client.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ namespace TIGER_API {
7070
for (const auto &kvp: common_params.as_object()) {
7171
params[kvp.first] = kvp.second;
7272
}
73+
if (!client_config.lang.empty()) {
74+
body[P_LANG] = value::string(client_config.lang);
75+
}
7376
if (!body.is_null() && body.size() > 0) {
7477
params[P_BIZ_CONTENT] = value::string(body.serialize());
7578
}

0 commit comments

Comments
 (0)