Skip to content

Commit 5ae3ca4

Browse files
committed
support tbus
1 parent 82849ee commit 5ae3ca4

File tree

8 files changed

+82
-13
lines changed

8 files changed

+82
-13
lines changed

changlog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0 (2025-08-08)
2+
### New
3+
- 支持 TBUS 配置
4+
15
## 1.0.4 (2025-05-12)
26
### Breaking
37
- 长连接订阅请求由 bool 改为 unsigned int,表示订阅请求的 id

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class TestTradeClient {
180180
}
181181

182182
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
183-
TestTradeClient::test_price_util(trade_client);
183+
TestTradeClient::test_place_order(trade_client);
184184
}
185185

186186
};
@@ -267,6 +267,7 @@ class TestQuoteClient {
267267
}
268268

269269
static void test_get_kline(std::shared_ptr<QuoteClient> quote_client) {
270+
LOG(DEBUG) << U("test_get_kline");
270271
value symbols = value::array();
271272
symbols[0] = value::string(U("AAPL"));
272273
symbols[1] = value::string(U("JD"));
@@ -406,7 +407,7 @@ class TestQuoteClient {
406407

407408

408409
static void test_quote(const std::shared_ptr<QuoteClient> quote_client) {
409-
TestQuoteClient::test_get_quote_delay(quote_client);
410+
TestQuoteClient::test_get_kline(quote_client);
410411
}
411412
};
412413

@@ -454,7 +455,8 @@ class TestPushClient {
454455
TestPushClient(std::shared_ptr<IPushClient> client) : push_client(client) {
455456
std::vector<std::string> hk_option_symbols = {"TCH.HK 20241230 410.00 CALL"};
456457
std::vector<std::string> future_symbols = {"CL2412"};
457-
symbols = future_symbols;
458+
std::vector<std::string> stock_symbols = {"AAPL", "TSLA"};
459+
symbols = stock_symbols;
458460
}
459461

460462
void connected_callback() {
@@ -620,13 +622,13 @@ int main(int argc, char* argv[]) {
620622
* QuoteClient
621623
*/
622624
// std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
623-
// TestQuoteClient::test_quote(quote_client);
625+
// TestQuoteClient::test_quote(quote_client);
624626

625627
/**
626628
* TradeClient
627629
*/
628-
//std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
629-
//TestTradeClient::test_trade(trade_client);
630+
// std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
631+
// TestTradeClient::test_trade(trade_client);
630632

631633
/**
632634
* TigerApi

include/tigerapi/client_config.h

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

6161
const utility::string_t& get_socket_port();
6262

63+
bool is_us();
64+
6365
private:
6466
bool sandbox_debug = false;
6567
utility::string_t server_url = TIGER_SERVER_URL;

include/tigerapi/constants.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,22 @@ static utility::string_t SANDBOX_TIGER_PUBLIC_KEY = U("MIGfMA0GCSqGSIb3DQEBAQUAA
7373
"MidihTvHHf+tJ0PYD0o3PruI0hl3qhEjHTAxb75T5YD3SGK4IBhHn/Rk6mhqlGgI+bBrBVYaXixm"
7474
"HfRo75RpUUuWACyeqQkZckgR0McxuW9xRMIa2cXZOoL1E4SL4lXKGhKoWbwIDAQAB");
7575

76+
static utility::string_t TIGER_HOST = U("openapi.tigerfintech.com");
77+
static utility::string_t SANDBOX_TIGER_HOST = U("openapi-sandbox.tigerfintech.com");
78+
static utility::string_t US_TIGER_HOST = U("openapi.tradeup.com");
79+
7680
/** HTTP interface service address **/
77-
static utility::string_t TIGER_SERVER_URL = U("https://openapi.tigerfintech.com/gateway");
78-
static utility::string_t SANDBOX_TIGER_SERVER_URL = U("https://openapi-sandbox.tigerfintech.com/gateway");
81+
static utility::string_t TIGER_SERVER_URL = U("https://") + TIGER_HOST + U("/gateway");
82+
static utility::string_t SANDBOX_TIGER_SERVER_URL = U("https://") + SANDBOX_TIGER_HOST + U("/gateway");
83+
static utility::string_t US_TIGER_SERVER_URL = U("https://") + US_TIGER_HOST + U("/gateway");
7984

8085
/** Push service address **/
81-
static utility::string_t TIGER_SOCKET_HOST = U("openapi.tigerfintech.com");
82-
static utility::string_t SANDBOX_TIGER_SOCKET_HOST = U("openapi-sandbox.tigerfintech.com");
86+
static utility::string_t TIGER_SOCKET_HOST = TIGER_HOST;
87+
static utility::string_t SANDBOX_TIGER_SOCKET_HOST = SANDBOX_TIGER_HOST;
88+
static utility::string_t US_TIGER_SOCKET_HOST = US_TIGER_HOST;
8389
static utility::string_t TIGER_SOCKET_PORT = U("9883");
8490
static utility::string_t SANDBOX_TIGER_SOCKET_PORT = U("9885");
91+
static utility::string_t US_TIGER_SOCKET_PORT = U("9983");
8592

8693
#define DEFAULT_TOKEN_FILE U("tiger_openapi_token.properties")
8794
#define DEFAULT_PROPS_FILE U("tiger_openapi_config.properties")

include/tigerapi/enums.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ namespace TIGER_API {
4141
}
4242
}
4343

44+
enum class License {
45+
TBNZ,
46+
TBSG,
47+
TBHK,
48+
TBAU,
49+
TBUS
50+
};
51+
52+
inline utility::string_t enum_to_str(License license) {
53+
switch (license) {
54+
case License::TBNZ:
55+
return U("TBNZ");
56+
case License::TBSG:
57+
return U("TBSG");
58+
case License::TBHK:
59+
return U("TBHK");
60+
case License::TBAU:
61+
return U("TBAU");
62+
case License::TBUS:
63+
return U("TBUS");
64+
default:
65+
return U("");
66+
}
67+
}
4468

4569
enum class TradingSession {
4670
PreMarket, // PreMarket

include/tigerapi/version.h

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

8-
#define PROJECT_VERSION "1.0.4"
8+
#define PROJECT_VERSION "1.1.0"
99

1010
#endif //TIGERAPI_VERSION_H

src/client_config.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../include/tigerapi/client_config.h"
22
#include "../include/tigerapi/properties.h"
3+
#include "../include/tigerapi/enums.h"
34

45
TIGER_API::ClientConfig::ClientConfig(bool sandbox_debug /*= false*/)
56
: sandbox_debug(sandbox_debug) {
@@ -8,13 +9,22 @@ TIGER_API::ClientConfig::ClientConfig(bool sandbox_debug /*= false*/)
89
// server_url = SANDBOX_TIGER_SERVER_URL;
910
// server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
1011
}
12+
if (is_us()) {
13+
server_url = US_TIGER_SERVER_URL;
14+
socket_url = US_TIGER_SOCKET_HOST;
15+
socket_port = US_TIGER_SOCKET_PORT;
16+
}
1117
};
1218

1319
TIGER_API::ClientConfig::ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account)
1420
: tiger_id(std::move(tiger_id)),
1521
private_key(std::move(private_key)),
1622
account(std::move(account)) {
17-
23+
if (is_us()) {
24+
server_url = US_TIGER_SERVER_URL;
25+
socket_url = US_TIGER_SOCKET_HOST;
26+
socket_port = US_TIGER_SOCKET_PORT;
27+
}
1828
};
1929

2030
TIGER_API::ClientConfig::ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account, bool sandbox_debug /*= false*/, utility::string_t lang /*= U("en_US")*/)
@@ -30,13 +40,24 @@ TIGER_API::ClientConfig::ClientConfig(utility::string_t tiger_id, utility::strin
3040
// socket_url = SANDBOX_TIGER_SOCKET_HOST;
3141
// socket_port = SANDBOX_TIGER_SOCKET_PORT;
3242
}
43+
if (is_us()) {
44+
server_url = US_TIGER_SERVER_URL;
45+
socket_url = US_TIGER_SOCKET_HOST;
46+
socket_port = US_TIGER_SOCKET_PORT;
47+
}
3348
};
3449

3550
TIGER_API::ClientConfig::ClientConfig(bool sandbox_debug, const utility::string_t props_path)
3651
: sandbox_debug(sandbox_debug),
3752
props_path(props_path) {
38-
load_props();
53+
load_props();
3954
load_token();
55+
if (is_us()) {
56+
server_url = US_TIGER_SERVER_URL;
57+
socket_url = US_TIGER_SOCKET_HOST;
58+
socket_port = US_TIGER_SOCKET_PORT;
59+
}
60+
LOG(INFO) << U("ClientConfig initialized with props_path: ") << props_path << endl;
4061
};
4162

4263
void TIGER_API::ClientConfig::check()
@@ -176,6 +197,9 @@ void TIGER_API::ClientConfig::load_token()
176197
if (full_path.empty()) {
177198
return;
178199
}
200+
if (!std::filesystem::exists(Utils::str16to8(full_path))) {
201+
return;
202+
}
179203
try {
180204
std::ifstream file(Utils::str16to8(full_path));
181205
if (!file.is_open()) {
@@ -219,3 +243,8 @@ void TIGER_API::ClientConfig::save_token(const utility::string_t& new_token)
219243
LOG(ERROR) << U("Failed to save token file: ") << Utils::str8to16(e.what()) << endl;
220244
}
221245
}
246+
247+
bool TIGER_API::ClientConfig::is_us()
248+
{
249+
return !license.empty() && license == enum_to_str(License::TBUS);
250+
}

src/push_socket/push_client_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ TIGER_API::PushClientImpl::PushClientImpl(const TIGER_API::ClientConfig& client_
3939
void TIGER_API::PushClientImpl::connect()
4040
{
4141
LOG(INFO) << "create a worker thread to perform asynchronous network connections";
42+
LOG(INFO) << "conntect to: " << client_config_.get_socket_url() << " port: " << client_config_.get_socket_port();
4243
// create a worker thread to perform asynchronous network connections
4344
worker_thread_ = std::shared_ptr<std::thread>(new std::thread([this]
4445
{

0 commit comments

Comments
 (0)