Skip to content

Commit 6a0c104

Browse files
committed
fix str to long issue
1 parent db3bfae commit 6a0c104

File tree

8 files changed

+78
-56
lines changed

8 files changed

+78
-56
lines changed

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,46 @@ class TestTradeClient {
6262
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
6363
Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
6464
value res = trade_client->place_order(order);
65-
long id = res[U("id")].as_integer();
66-
ucout << U("order id: ") << id << endl;
65+
unsigned long long id = res[U("id")].as_number().to_uint64();
66+
ucout << U("return id: ") << id << endl;
67+
ucout << U("order id: ") << order.id << endl;
6768
ucout << U("place order result: ") << res << endl;
6869
}
6970

71+
static void test_place_future_order(const std::shared_ptr<TradeClient>& trade_client) {
72+
Contract contract = ContractUtil::future_contract(U("NG2308"), U("USD"));
73+
Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 1.5);
74+
value res = trade_client->place_order(order);
75+
unsigned long long id = res[U("id")].as_number().to_uint64();
76+
ucout << U("return id: ") << id << endl;
77+
ucout << U("order id: ") << order.id << endl;
78+
ucout << U("place order result: ") << res << endl;
79+
}
80+
81+
static void test_place_option_order(const std::shared_ptr<TradeClient>& trade_client) {
82+
Contract contract = ContractUtil::option_contract(U("AAPL"), U("20230721"), U("185.0"), U("CALL"), U("USD"));
83+
//Contract contract = ContractUtil::option_contract(U("AAPL"), U("20230721"), U("185.0"), U("PUT"), U("USD"));
84+
//Contract contract = ContractUtil::option_contract(U("AAPL 230721C00185000"));
85+
//Contract contract = ContractUtil::option_contract(U("AAPL 230721P00185000"));
86+
Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 1.5);
87+
value res = trade_client->place_order(order);
88+
//unsigned long long id = res[U("id")].as_number().to_uint64();
89+
ucout << U("order id: ") << order.id << endl;
90+
ucout << U("place order result: ") << res << endl;
91+
}
92+
93+
7094
static void test_get_order(const std::shared_ptr<TradeClient>& trade_client) {
7195
// Contract contract = stock_contract(U("AAPL"), U("USD"));
7296
// Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
7397
// trade_client->place_order(order);
74-
Order my_order = trade_client->get_order(29270263515317248);
98+
Order my_order = trade_client->get_order(31318009878020096);
99+
ucout << U("order id ") << my_order.id << endl;
75100
ucout << U("order : ") << my_order.to_string() << endl;
76101
}
77102

78103
static void test_cancel_order(const std::shared_ptr<TradeClient>& trade_client) {
79-
value res = trade_client->cancel_order(29270263515317248);
104+
value res = trade_client->cancel_order(31319396151853056);
80105
ucout << U("cancel order : ") << res << endl;
81106
}
82107

@@ -92,7 +117,7 @@ class TestTradeClient {
92117

93118

94119
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
95-
TestTradeClient::test_place_order(trade_client);
120+
TestTradeClient::test_get_orders(trade_client);
96121
}
97122
};
98123

@@ -303,7 +328,7 @@ class TestQuoteClient {
303328
}
304329

305330
static void test_quote(const std::shared_ptr<QuoteClient> quote_client) {
306-
TestQuoteClient::test_get_kline(quote_client);
331+
TestQuoteClient::test_get_quote_real_time(quote_client);
307332
}
308333
};
309334

@@ -337,13 +362,13 @@ int main()
337362
{
338363
/************************** set config **********************/
339364
ClientConfig config = ClientConfig();
340-
341365
config.private_key = U("");
342366
config.tiger_id = U("");
343367
config.account = U("");
344368

345369

346-
// config.lang = U("en_US");
370+
371+
//config.lang = U("en_US");
347372

348373

349374
/**
@@ -355,8 +380,8 @@ int main()
355380
/**
356381
* ʹ�÷�װ��Ľ��׽ӿ� TradeClient
357382
*/
358-
// std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
359-
// TestTradeClient::test_trade(trade_client);
383+
//std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
384+
//TestTradeClient::test_trade(trade_client);
360385

361386
/**
362387
* ֱ��ʹ��δ��װ�� TigerApi

include/tigerapi/contract_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace TIGER_API {
2121
static Contract
2222
option_contract(const utility::string_t symbol, const utility::string_t expiry, const utility::string_t strike,
2323
const utility::string_t right,
24-
const utility::string_t currency, long multiplier = 100,
24+
const utility::string_t currency = U("USD"), long multiplier = 100,
2525
const utility::string_t local_symbol = U(""),
2626
long contract_id = 0);
2727

include/tigerapi/model.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@ namespace TIGER_API {
6262
Order() {};
6363

6464
Order(const utility::string_t order_type, const utility::string_t account, Contract &contract,
65-
const utility::string_t action, long total_quantity) :
65+
const utility::string_t action, long long total_quantity) :
6666
order_type(order_type), account(account), contract(contract), action(action),
6767
total_quantity(total_quantity) {};
6868

6969
Order(const utility::string_t order_type, const utility::string_t account, Contract &contract,
70-
const utility::string_t action, long total_quantity,
70+
const utility::string_t action, long long total_quantity,
7171
double limit_price, double aux_price = 0, double trailing_percent = 0) :
7272
order_type(order_type), account(account), contract(contract), action(action),
7373
total_quantity(total_quantity),
7474
limit_price(limit_price), aux_price(aux_price), trailing_percent(trailing_percent) {};
7575

7676
Contract contract;
7777
utility::string_t account;
78-
long id = 0;
78+
unsigned long long id = 0;
7979
long order_id = 0;
8080
/** 订单类型, 'MKT' 市价单 / 'LMT' 限价单 / 'STP' 止损单 / 'STP_LMT' 止损限价单 / 'TRAIL' 跟踪止损单 **/
8181
utility::string_t order_type;
8282
/** 交易方向, 'BUY' / 'SELL' **/
8383
utility::string_t action;
8484
/** 下单数量 **/
85-
long total_quantity = 0;
85+
long long total_quantity = 0;
8686
/** 限价单价格 **/
8787
double limit_price = 0;
8888
/** 在止损单中, 表示触发止损单的价格, 在移动止损单中, 表示跟踪的价差 **/
@@ -100,12 +100,12 @@ namespace TIGER_API {
100100
*/
101101
bool adjust_limit;
102102
utility::string_t user_mark;
103-
long expire_time = 0;
103+
time_t expire_time = 0;
104104

105105
// 订单状态
106106
utility::string_t status;
107107
// 主订单id, 目前只用于 TigerTrade App端的附加订单中
108-
long parent_id;
108+
unsigned long long parent_id;
109109
// 下单时间
110110
time_t open_time;
111111
// 下单失败时, 会返回失败原因的描述
@@ -115,7 +115,7 @@ namespace TIGER_API {
115115
// order updated time
116116
time_t update_time;
117117
// 成交数量
118-
long filled_quantity;
118+
long long filled_quantity;
119119
// 包含佣金的平均成交价
120120
double avg_fill_price;
121121
// 实现盈亏
@@ -179,31 +179,31 @@ namespace TIGER_API {
179179
user_mark = json.at(U("userMark")).as_string();
180180
}
181181
if (json.has_field(U("expireTime"))) {
182-
expire_time = json.at(U("expireTime")).as_integer();
182+
expire_time = json.at(U("expireTime")).as_number().to_int64();
183183
}
184184
if (json.has_field(U("status"))) {
185185
status = json.at(U("status")).as_string();
186186
}
187187
if (json.has_field(U("parentId"))) {
188-
parent_id = json.at(U("parentId")).as_integer();
188+
parent_id = json.at(U("parentId")).as_number().to_uint64();
189189
}
190190
if (json.has_field(U("openTime"))) {
191-
open_time = json.at(U("openTime")).as_integer();
191+
open_time = json.at(U("openTime")).as_number().to_int64();
192192
}
193193
if (json.has_field(U("reason"))) {
194194
reason = json.at(U("reason")).as_string();
195195
}
196196
if (json.has_field(U("latestTime"))) {
197-
latest_time = json.at(U("latestTime")).as_integer();
197+
latest_time = json.at(U("latestTime")).as_number().to_int64();
198198
}
199199
if (json.has_field(U("updateTime"))) {
200-
update_time = json.at(U("updateTime")).as_integer();
200+
update_time = json.at(U("updateTime")).as_number().to_int64();
201201
}
202202
if (json.has_field(U("filledQuantity"))) {
203-
filled_quantity = json.at(U("filledQuantity")).as_integer();
203+
filled_quantity = json.at(U("filledQuantity")).as_number().to_int64();
204204
}
205205
if (json.has_field(U("totalQuantity"))) {
206-
total_quantity = json.at(U("totalQuantity")).as_integer();
206+
total_quantity = json.at(U("totalQuantity")).as_number().to_int64();
207207
}
208208
if (json.has_field(U("avgFillPrice"))) {
209209
avg_fill_price = json.at(U("avgFillPrice")).as_double();
@@ -228,7 +228,7 @@ namespace TIGER_API {
228228
public:
229229
Position() {};
230230

231-
Position(const utility::string_t &account, const Contract &contract, int position = 0,
231+
Position(const utility::string_t &account, const Contract &contract, long long position = 0,
232232
double average_cost = 0.0,
233233
double latest_price = 0.0, double market_value = 0.0, double realized_pnl = 0.0,
234234
double unrealized_pnl = 0.0)
@@ -276,7 +276,7 @@ namespace TIGER_API {
276276
latest_price = json.at(U("latestPrice")).as_double();
277277
}
278278
if (json.has_field(U("updateTimestamp"))) {
279-
update_timestamp = (long) json.at(U("updateTimestamp")).as_number().to_uint64();
279+
update_timestamp = json.at(U("updateTimestamp")).as_number().to_uint64();
280280
}
281281
if (json.has_field(U("status"))) {
282282
status = json.at(U("status")).as_integer();
@@ -285,14 +285,14 @@ namespace TIGER_API {
285285

286286
utility::string_t account;
287287
Contract contract;
288-
long position;
288+
long long position;
289289
double average_cost;
290290
double market_value;
291291
double realized_pnl;
292292
double unrealized_pnl;
293293
double latest_price;
294294
int status;
295-
long update_timestamp;
295+
time_t update_timestamp;
296296

297297

298298
utility::string_t to_string() {
@@ -467,9 +467,9 @@ namespace TIGER_API {
467467
double low = 0;
468468
double close = 0;
469469
time_t time;
470-
long volume = 0;
470+
long long volume = 0;
471471
time_t last_time;
472-
long open_interest = 0;
472+
long long open_interest = 0;
473473
double settlement = 0;
474474

475475
void from_json(const web::json::value& j) {
@@ -525,7 +525,7 @@ namespace TIGER_API {
525525
double high = 0;
526526
double low = 0;
527527
double close = 0;
528-
long volume = 0;
528+
long long volume = 0;
529529
double adj_pre_close = 0;
530530
double pre_close = 0;
531531
double ask_price = 0;
@@ -534,12 +534,12 @@ namespace TIGER_API {
534534
double bid_size = 0;
535535
double latest_price = 0;
536536
time_t latest_time;
537-
long latest_size = 0;
537+
long long latest_size = 0;
538538
utility::string_t status;
539539
utility::string_t symbol;
540540

541541
utility::string_t contract_code;
542-
long open_interest = 0;
542+
long long open_interest = 0;
543543
int limit_down = 0;
544544
int limit_up = 0;
545545

include/tigerapi/sign_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace TIGER_API {
6565
unsigned char hash[SHA_DIGEST_LENGTH] = {0};
6666

6767
auto str_transfer_content = Utils::str16to8(context);
68-
int context_size = str_transfer_content.size();
68+
unsigned int context_size = str_transfer_content.size();
6969
SHA1((const unsigned char *) str_transfer_content.c_str(), context_size, hash);
7070
RSA *rsa = create_rsa((utility::char_t *) key.c_str(), true);
7171
int ret = RSA_sign(NID_sha1, hash, SHA_DIGEST_LENGTH,

include/tigerapi/trade_client.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,47 +98,47 @@ namespace TIGER_API {
9898
/** 获取未成交订单 **/
9999
value get_active_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
100100
utility::string_t market = U("ALL"),
101-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
101+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
102102
utility::string_t sort_by = U(""),
103103
utility::string_t seg_type = U(""));
104104

105105
value get_active_orders(utility::string_t account, SecType sec_type = SecType::ALL,
106106
Market market = Market::ALL,
107-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
107+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
108108
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
109109
SegmentType seg_type = SegmentType::SEC);
110110

111111
/** 获取已成交订单 **/
112112
value get_filled_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
113113
utility::string_t market = U("ALL"),
114-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
114+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
115115
utility::string_t sort_by = U(""),
116116
utility::string_t seg_type = U(""));
117117

118118
value get_filled_orders(utility::string_t account, SecType sec_type = SecType::ALL,
119119
Market market = Market::ALL,
120-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
120+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
121121
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
122122
SegmentType seg_type = SegmentType::SEC);
123123

124124
/** 获取已取消订单 **/
125125
value get_inactive_orders(utility::string_t account = U(""), utility::string_t sec_type = U(""),
126126
utility::string_t market = U("ALL"),
127-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
127+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
128128
utility::string_t sort_by = U(""),
129129
utility::string_t seg_type = U(""));
130130

131131
value get_inactive_orders(utility::string_t account, SecType sec_type = SecType::ALL,
132132
Market market = Market::ALL,
133-
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, long parent_id = 0,
133+
utility::string_t symbol = U(""), time_t start_date = -1, time_t end_date = -1, unsigned long long parent_id = 0,
134134
OrderSortBy sort_by = OrderSortBy::LATEST_STATUS_UPDATED,
135135
SegmentType seg_type = SegmentType::SEC);
136136

137-
Order get_order(long id, bool is_brief=false);
137+
Order get_order(unsigned long long id, bool is_brief=false);
138138
Order get_transactions(utility::string_t account = U(""), long order_id = 0, utility::string_t sec_type = U(""),
139139
utility::string_t symbol = U(""), long start_time = -1, time_t end_time = -1,
140140
int limit = 100, utility::string_t expiry = U(""), double strike = 0, utility::string_t right = U(""));
141-
value cancel_order(long id);
141+
value cancel_order(unsigned long long id);
142142
value place_order(value &order);
143143
value place_order(Order &order);
144144
value modify_order(Order &order);

openapi-cpp-sdk.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<Filter Include="include\tigerapi">
1111
<UniqueIdentifier>{bfd89a3e-57e3-41ab-9046-00e64bdde15e}</UniqueIdentifier>
1212
</Filter>
13-
<Filter Include="src\common">
14-
<UniqueIdentifier>{3d6dbfc8-74a7-4caf-a400-57cc960e40a9}</UniqueIdentifier>
15-
</Filter>
1613
</ItemGroup>
1714
<ItemGroup>
1815
<ClInclude Include="include\tigerapi\client_config.h">

0 commit comments

Comments
 (0)