Skip to content

Commit 0ca8ca7

Browse files
committed
modify exit;accounts api
1 parent 0b0f809 commit 0ca8ca7

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

include/tigerapi/client_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ namespace TIGER_API {
5050
void check() {
5151
if (this->tiger_id.empty()) {
5252
LOG(ERROR) << U("Client Config error: tiger_id can't be empty") << endl;
53-
exit(0);
53+
throw std::runtime_error("Client Config error: tiger_id can't be empty");
5454
}
5555
if (this->private_key.empty()) {
5656
LOG(ERROR) << U("Client Config error: private_key can't be empty") << endl;
57-
exit(0);
57+
throw std::runtime_error("Client Config error: private_key can't be empty");
5858
}
5959
}
6060

6161
void check_account() {
6262
if (this->account.empty()) {
6363
LOG(ERROR) << U("Client Config error: account can't be empty") << endl;
64-
exit(0);
64+
throw std::runtime_error("Client Config error: account can't be empty");
6565
}
6666
}
6767

include/tigerapi/trade_client.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace TIGER_API {
1818
public:
1919
TradeClient();
2020
TradeClient(const ClientConfig &cf);
21+
22+
/** 获取账户列表 **/
23+
value get_accounts();
24+
2125
/**
2226
* 获取资产(适用综合/模拟账户) get asset
2327
* @param account

src/quote_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ namespace TIGER_API {
402402
value QuoteClient::get_future_tick(utility::string_t contract_code, long begin_index, long end_index, int limit) {
403403
value obj = value::object(true);
404404
obj[P_CONTRACT_CODE] = value::string(contract_code);
405-
obj[P_BEGIN_INDEX] = begin_index;
406-
obj[P_END_INDEX] = end_index;
405+
obj[P_BEGIN_INDEX] = (int64_t) begin_index;
406+
obj[P_END_INDEX] = (int64_t) end_index;
407407
obj[P_LIMIT] = limit;
408408
return post(FUTURE_TICK, obj);
409409
}

src/tiger_client.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,31 @@ namespace TIGER_API {
102102
}
103103
catch (std::exception &ex) {
104104
LOG(ERROR) << U("Exception: ") << ex.what() << endl;
105-
exit(0);
105+
throw ex;
106106
}
107107
try {
108108
result = response.extract_json().get();
109109
result_str = result.serialize();
110110
if (result[P_CODE].is_null()) {
111111
LOG(ERROR) << U("Exception: api error, response: ") << result.serialize();
112-
exit(-1);
112+
throw std::runtime_error(Utils::str16to8(result.serialize()).c_str());
113113
}
114114
int code = result[P_CODE].as_integer();
115115
if (code != 0) {
116116
LOG(ERROR) << U("Exception: api code error, response: ") << result.serialize();
117-
exit(code);
117+
throw std::runtime_error(Utils::str16to8(result.serialize()).c_str());
118118
}
119119
utility::string_t res_sign = result[P_SIGN].as_string();
120120
bool is_sign_ok = Utils::verify_sign(client_config.get_server_pub_key(), params[P_TIMESTAMP].as_string(), res_sign);
121121
if (!is_sign_ok) {
122122
LOG(ERROR) << U("Exception: response sign verify failed. ");
123-
exit(-1);
123+
throw std::runtime_error("Exception: response sign verify failed");
124124
}
125125
result_data = result[P_DATA];
126126
}
127127
catch (const std::exception &e) {
128128
LOG(ERROR) << U("get response error :") << e.what() << endl;
129+
throw e;
129130
}
130131
LOG(DEBUG) << U("response:\n") << result.serialize();
131132
// json format

src/trade_client.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace TIGER_API {
1111
this->client_config.check_account();
1212
}
1313

14+
value TradeClient::get_accounts() {
15+
value obj = value::object(true);
16+
return post(ACCOUNTS, obj);
17+
}
18+
1419
value TradeClient::get_prime_asset(const utility::string_t &account, const utility::string_t &base_currency) {
1520
value obj = value::object(true);
1621
obj[P_ACCOUNT] = get_account_param(account);
@@ -366,7 +371,7 @@ namespace TIGER_API {
366371
obj[U("action")] = value::string(order.action);
367372
}
368373
if (order.total_quantity) {
369-
obj[U("total_quantity")] = order.total_quantity;
374+
obj[U("total_quantity")] = (int64_t) order.total_quantity;
370375
}
371376
if (order.limit_price != 0) {
372377
obj[U("limit_price")] = order.limit_price;
@@ -419,7 +424,7 @@ namespace TIGER_API {
419424
return order;
420425
} else {
421426
ucout << U("Exception: order ") << id << U(" not exist, result: ") << res << endl;
422-
exit(-1);
427+
throw std::runtime_error(Utils::str16to8(res.serialize()).c_str());
423428
}
424429
}
425430

0 commit comments

Comments
 (0)