Skip to content

Commit 6e7de32

Browse files
committed
Merge branch 'feat_secretkey' into 'dev'
Feat secretkey See merge request server/openapi/openapi-cpp-sdk!9
2 parents 6f4c7f9 + edefc66 commit 6e7de32

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

changlog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
## 0.1.0 (2023-02-15)
22
### New
3-
- Beta版本,支持交易、行情接口
3+
- Beta版本,支持交易、行情接口
4+
5+
## 0.1.5 (2024-02-04)
6+
### Modify
7+
- 交易接口支持 `secret_key`

include/tigerapi/client_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace TIGER_API {
4646
utility::string_t sign_type = U("RSA");
4747
utility::string_t lang;
4848
utility::string_t device_id = Utils::get_device_id();
49+
utility::string_t secret_key;
4950

5051
void check() {
5152
if (this->tiger_id.empty()) {

include/tigerapi/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static utility::string_t P_SDK_VERSION_PREFIX = U("openapi-cpp-sdk-");
2323
static utility::string_t P_USER_AGENT = U("User-Agent");
2424
static utility::string_t P_BIZ_CONTENT = U("biz_content");
2525
static utility::string_t P_ACCOUNT = U("account");
26+
static utility::string_t P_SECRET_KEY = U("secret_key");
2627
static utility::string_t P_MARKET = U("market");
2728
static utility::string_t P_SYMBOLS = U("symbols");
2829
static utility::string_t P_SYMBOL = U("symbol");

include/tigerapi/trade_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ namespace TIGER_API {
172172

173173
private:
174174
value get_account_param(const utility::string_t &account=U(""));
175+
176+
void set_secret_key(value &obj);
175177
};
176178
}
177179

include/tigerapi/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef TIGERAPI_VERSION_H
66
#define TIGERAPI_VERSION_H
77

8-
#define PROJECT_VERSION "0.1.4"
8+
#define PROJECT_VERSION "0.1.5"
99
#include "easylogging++.h"
1010
INITIALIZE_EASYLOGGINGPP
1111
#endif //TIGERAPI_VERSION_H

src/trade_client.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ namespace TIGER_API {
1313

1414
value TradeClient::get_accounts() {
1515
value obj = value::object(true);
16+
set_secret_key(obj);
1617
return post(ACCOUNTS, obj);
1718
}
1819

1920
value TradeClient::get_prime_asset(const utility::string_t &account, const utility::string_t &base_currency) {
2021
value obj = value::object(true);
2122
obj[P_ACCOUNT] = get_account_param(account);
23+
set_secret_key(obj);
2224
obj[U("base_currency")] = value::string(base_currency);
2325
return post(PRIME_ASSETS, obj);
2426
}
@@ -49,6 +51,7 @@ namespace TIGER_API {
4951
value TradeClient::get_asset(utility::string_t account, const value &sub_accounts, bool segment, bool market_value) {
5052
value obj = value::object(true);
5153
obj[P_ACCOUNT] = get_account_param(account);
54+
set_secret_key(obj);
5255
obj[U("segment")] = segment;
5356
obj[U("market_value")] = market_value;
5457
return post(ASSETS, obj);
@@ -61,11 +64,18 @@ namespace TIGER_API {
6164
return value::string(account);
6265
}
6366

67+
void TradeClient::set_secret_key(value &obj) {
68+
if (!client_config.secret_key.empty()) {
69+
obj[U("secretKey")] = value::string(client_config.secret_key);
70+
}
71+
}
72+
6473
value TradeClient::get_positions(const utility::string_t &account, const utility::string_t &sec_type, const utility::string_t &currency,
6574
const utility::string_t &market, const utility::string_t &symbol,
6675
const value &sub_accounts, time_t expiry, utility::string_t strike, const utility::string_t &right) {
6776
value obj = value::object(true);
6877
obj[P_ACCOUNT] = get_account_param(account);
78+
set_secret_key(obj);
6979
if (!sec_type.empty()) {
7080
obj[P_SEC_TYPE] = value::string(sec_type);
7181
}
@@ -118,6 +128,7 @@ namespace TIGER_API {
118128
const utility::string_t &seg_type) {
119129
value obj = value::object(true);
120130
obj[P_ACCOUNT] = get_account_param(account);
131+
set_secret_key(obj);
121132
if (!sec_type.empty()) {
122133
obj[P_SEC_TYPE] = value::string(sec_type);
123134
}
@@ -162,6 +173,7 @@ namespace TIGER_API {
162173
time_t end_date, unsigned long long parent_id, utility::string_t sort_by, utility::string_t seg_type) {
163174
value obj = value::object(true);
164175
obj[P_ACCOUNT] = get_account_param(account);
176+
set_secret_key(obj);
165177
if (!sec_type.empty()) {
166178
obj[P_SEC_TYPE] = value::string(sec_type);
167179
}
@@ -203,6 +215,7 @@ namespace TIGER_API {
203215
utility::string_t sort_by, utility::string_t seg_type) {
204216
value obj = value::object(true);
205217
obj[P_ACCOUNT] = get_account_param(account);
218+
set_secret_key(obj);
206219
if (!sec_type.empty()) {
207220
obj[P_SEC_TYPE] = value::string(sec_type);
208221
}
@@ -244,6 +257,7 @@ namespace TIGER_API {
244257
utility::string_t sort_by, utility::string_t seg_type) {
245258
value obj = value::object(true);
246259
obj[P_ACCOUNT] = get_account_param(account);
260+
set_secret_key(obj);
247261
if (!sec_type.empty()) {
248262
obj[P_SEC_TYPE] = value::string(sec_type);
249263
}
@@ -281,6 +295,7 @@ namespace TIGER_API {
281295
value TradeClient::get_transactions(utility::string_t account, long order_id) {
282296
value obj = value::object(true);
283297
obj[P_ACCOUNT] = get_account_param(account);
298+
set_secret_key(obj);
284299
obj[U("order_id")] = (long long) order_id;
285300
return post(ORDER_TRANSACTIONS, obj)[P_ITEMS];
286301
}
@@ -291,6 +306,7 @@ namespace TIGER_API {
291306
long order_id) {
292307
value obj = value::object(true);
293308
obj[P_ACCOUNT] = get_account_param(account);
309+
set_secret_key(obj);
294310
if (order_id != 0) {
295311
obj[U("order_id")] = (long long) order_id;
296312
}
@@ -325,6 +341,7 @@ namespace TIGER_API {
325341
utility::string_t strike, utility::string_t right) {
326342
value obj = value::object(true);
327343
obj[P_ACCOUNT] = get_account_param();
344+
set_secret_key(obj);
328345
if (!symbol.empty()) {
329346
obj[P_SYMBOL] = value::string(symbol);
330347
}
@@ -360,6 +377,7 @@ namespace TIGER_API {
360377
utility::string_t right) {
361378
value obj = value::object(true);
362379
obj[P_ACCOUNT] = get_account_param();
380+
set_secret_key(obj);
363381
obj[P_SYMBOLS] = symbols;
364382
if (!sec_type.empty()) {
365383
obj[P_SEC_TYPE] = value::string(sec_type);
@@ -386,6 +404,7 @@ namespace TIGER_API {
386404
TradeClient::get_quote_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t expiry) {
387405
value obj = value::object(true);
388406
obj[P_ACCOUNT] = get_account_param();
407+
set_secret_key(obj);
389408
if (!symbol.empty()) {
390409
obj[P_SYMBOL] = value::string(symbol);
391410
}
@@ -404,6 +423,7 @@ namespace TIGER_API {
404423
obj[kvp.first] = kvp.second;
405424
}
406425
obj[P_ACCOUNT] = get_account_param(order[P_ACCOUNT].as_string());
426+
set_secret_key(obj);
407427
value res = post(PLACE_ORDER, obj);
408428
return res;
409429
}
@@ -437,6 +457,7 @@ namespace TIGER_API {
437457
}
438458

439459
obj[P_ACCOUNT] = get_account_param(order.account);
460+
set_secret_key(obj);
440461

441462
if (!order.secret_key.empty()) {
442463
obj[U("secret_key")] = value::string(order.secret_key);
@@ -503,6 +524,7 @@ namespace TIGER_API {
503524
Order TradeClient::get_order(unsigned long long id, bool is_brief) {
504525
value obj = value::object(true);
505526
obj[P_ACCOUNT] = get_account_param();
527+
set_secret_key(obj);
506528
obj[U("id")] = id;
507529
obj[U("is_brief")] = is_brief;
508530
value res = post(ORDERS, obj);
@@ -518,6 +540,7 @@ namespace TIGER_API {
518540
value TradeClient::cancel_order(unsigned long long id) {
519541
value obj = value::object(true);
520542
obj[P_ACCOUNT] = get_account_param();
543+
set_secret_key(obj);
521544
obj[U("id")] = id;
522545
value res = post(CANCEL_ORDER, obj);
523546
return res;
@@ -527,7 +550,7 @@ namespace TIGER_API {
527550
value obj = value::object(true);
528551

529552
obj[P_ACCOUNT] = get_account_param(order.account);
530-
553+
set_secret_key(obj);
531554
if (order.id != 0) {
532555
obj[U("id")] = order.id;
533556
}
@@ -579,7 +602,7 @@ namespace TIGER_API {
579602
utility::string_t time_in_force, bool outside_rth, time_t expire_time) {
580603
value obj = value::object(true);
581604
obj[P_ACCOUNT] = get_account_param(order.account);
582-
605+
set_secret_key(obj);
583606
if (order.id != 0) {
584607
obj[U("id")] = order.id;
585608
}
@@ -625,6 +648,7 @@ namespace TIGER_API {
625648
value TradeClient::get_estimate_tradable_quantity(Order &order, utility::string_t seg_type) {
626649
value obj = value::object(true);
627650
obj[P_ACCOUNT] = get_account_param(order.account);
651+
set_secret_key(obj);
628652
obj[U("seg_type")] = value::string(seg_type);
629653
Contract contract = order.contract;
630654
if (!contract.symbol.empty()) {
@@ -665,6 +689,7 @@ namespace TIGER_API {
665689
utility::string_t currency, utility::string_t sub_account) {
666690
value obj = value::object(true);
667691
obj[P_ACCOUNT] = get_account_param(account);
692+
set_secret_key(obj);
668693
if (!start_date.empty()) {
669694
obj[U("start_date")] = value::string(start_date);
670695
}
@@ -686,6 +711,7 @@ namespace TIGER_API {
686711
value TradeClient::get_segment_fund_history(int limit) {
687712
value obj = value::object(true);
688713
obj[P_ACCOUNT] = get_account_param();
714+
set_secret_key(obj);
689715
if (limit > 0) {
690716
obj[U("limit")] = limit;
691717
}
@@ -695,6 +721,7 @@ namespace TIGER_API {
695721
value TradeClient::get_segment_fund_available(utility::string_t from_segment, utility::string_t currency) {
696722
value obj = value::object(true);
697723
obj[P_ACCOUNT] = get_account_param();
724+
set_secret_key(obj);
698725
if (!from_segment.empty()) {
699726
obj[U("from_segment")] = value::string(from_segment);
700727
}
@@ -709,6 +736,7 @@ namespace TIGER_API {
709736
utility::string_t currency) {
710737
value obj = value::object(true);
711738
obj[P_ACCOUNT] = get_account_param();
739+
set_secret_key(obj);
712740
if (!from_segment.empty()) {
713741
obj[U("from_segment")] = value::string(from_segment);
714742
}
@@ -728,6 +756,7 @@ namespace TIGER_API {
728756
utility::string_t target_currency, double source_amount) {
729757
value obj = value::object(true);
730758
obj[P_ACCOUNT] = get_account_param();
759+
set_secret_key(obj);
731760
if (!seg_type.empty()) {
732761
obj[U("seg_type")] = value::string(seg_type);
733762
}

0 commit comments

Comments
 (0)