Skip to content

Commit 32df22c

Browse files
author
JiaWen Li
committed
Merge branch 'feat_dependency_optimization' into 'master'
补充接口 See merge request server/openapi/openapi-cpp-sdk!7
2 parents ee3404d + 523697b commit 32df22c

File tree

11 files changed

+423
-67
lines changed

11 files changed

+423
-67
lines changed

.gitignore

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,23 @@
3939
cmake-build-debug
4040
build
4141
*-build
42-
demo/openapi_cpp_test/Debug/
43-
demo/openapi_cpp_test/Release/
44-
demo/openapi_cpp_test/myeasylog.log
45-
output/Debug/openapi-cpp-sdk.exp
46-
output/Debug/openapi-cpp-sdk.ilk
47-
output/Debug/openapi-cpp-sdk.pdb
48-
output/Debug/openapi_cpp_test.ilk
49-
output/Debug/openapi_cpp_test.pdb
50-
output/Release/openapi-cpp-sdk.exp
51-
output/Release/openapi-cpp-sdk.pdb
52-
output/Release/openapi_cpp_test.iobj
53-
output/Release/openapi_cpp_test.ipdb
54-
output/Release/openapi_cpp_test.pdb
42+
demo/openapi_cpp_test/Debug/
43+
demo/openapi_cpp_test/Release/
44+
demo/openapi_cpp_test/myeasylog.log
45+
demo/openapi_cpp_test/CMakeCache.txt
46+
demo/openapi_cpp_test/CMakeFiles
47+
demo/openapi_cpp_test/Makefile
48+
demo/openapi_cpp_test/cmake_install.cmake
49+
output/Debug/openapi-cpp-sdk.exp
50+
output/Debug/openapi-cpp-sdk.ilk
51+
output/Debug/openapi-cpp-sdk.pdb
52+
output/Debug/openapi_cpp_test.ilk
53+
output/Debug/openapi_cpp_test.pdb
54+
output/Release/openapi-cpp-sdk.exp
55+
output/Release/openapi-cpp-sdk.pdb
56+
output/Release/openapi_cpp_test.iobj
57+
output/Release/openapi_cpp_test.ipdb
58+
output/Release/openapi_cpp_test.pdb
5559
/output/Release/openapi-cpp-sdk.ipdb
5660
/output/Release/openapi-cpp-sdk.iobj
5761

CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ if(UNIX) # Darwing or Linux
2626
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
2727
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
2828

29+
30+
2931
if(APPLE)
3032
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
3133
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
32-
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/*)
34+
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/* /opt/homebrew/Cellar/openssl@3/*)
3335
# Prefer the latest (make the latest one first)
3436
list(REVERSE OPENSSL_ROOT_DIR)
3537

36-
find_package(OpenSSL 1.1 REQUIRED)
37-
set(OPENSSL_VERSION "1.1.1q")
38+
find_package(OpenSSL REQUIRED)
39+
# set(OPENSSL_VERSION "1.1.1q")
3840

41+
set(ZLIB_LIBRARY /opt/homebrew/Cellar/zlib/1.2.13/lib/libz.dylib )
42+
message(ZLIB_LIBRARY " ${ZLIB_LIBRARY}")
3943

4044
else()
4145
find_package(OpenSSL 1.0.1 REQUIRED)
@@ -52,7 +56,8 @@ endif()
5256
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5357

5458
message("-- configuring clang options")
55-
set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
59+
# set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
60+
set(CMAKE_CXX_FLAGS "-arch arm64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
5661

5762
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
5863

@@ -64,13 +69,14 @@ endif()
6469

6570
# Project construction ...
6671
# src files ...
72+
file(GLOB MY_SOURCE_FILES "include/cpprest/*.h" "include/cpprest/details/*.h")
6773
add_library(${PROJECT_NAME}
6874
src/tiger_client.cpp include/tigerapi/tiger_client.h include/tigerapi/constants.h
6975
include/tigerapi/utils.h src/utils.cpp include/tigerapi/service_types.h include/tigerapi/quote_client.h
7076
src/quote_client.cpp src/trade_client.cpp include/tigerapi/model.h src/order_util.cpp
7177
include/tigerapi/order_util.h src/contract_util.cpp include/tigerapi/contract_util.h
7278
include/tigerapi/client_config.h include/tigerapi/sign_util.h
73-
include/tigerapi/easylogging++.h src/easylogging++.cc)
79+
include/tigerapi/easylogging++.h cpprest/ src/easylogging++.cc ${MY_SOURCE_FILES})
7480

7581
# headers search paths ...
7682
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
@@ -79,7 +85,7 @@ set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
7985
# library search paths ...
8086
if(APPLE)
8187
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
82-
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
88+
# set(ZIP_LIBRARY ZLIB::ZLIB)
8389

8490
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY})
8591
else()

demo/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ if(UNIX) # Darwing or Linux
2323
if(APPLE)
2424
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
2525
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
26-
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/*)
26+
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/* /opt/homebrew/Cellar/openssl@3/*)
2727
# Prefer the latest (make the latest one first)
2828
list(REVERSE OPENSSL_ROOT_DIR)
2929

30-
find_package(OpenSSL 1.1 REQUIRED)
31-
set(OPENSSL_VERSION "1.1.1q")
30+
find_package(OpenSSL REQUIRED)
31+
# set(OPENSSL_VERSION "1.1.1q")
3232

3333

3434
else()
@@ -46,7 +46,8 @@ endif()
4646
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4747

4848
message("-- configuring clang options")
49-
set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
49+
# set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
50+
set(CMAKE_CXX_FLAGS "-arch arm64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
5051

5152
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
5253

@@ -65,7 +66,7 @@ set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_IN
6566
# library search paths ...
6667
if(APPLE)
6768
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
68-
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
69+
# set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
6970
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY} ${CPPREST_LIBRARY} ${TIGERAPI_LIBRARY})
7071
else()
7172
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,36 @@ class TestTradeClient {
5353
ucout << U("active orders: ") << res << endl;
5454
}
5555

56+
static void test_get_transactions(const std::shared_ptr<TradeClient>& trade_client) {
57+
value res = trade_client->get_transactions(trade_client->client_config.account, U("AAPL"));
58+
ucout << U("transactions: ") << res << endl;
59+
}
60+
5661
static void test_get_contract(const std::shared_ptr<TradeClient>& trade_client) {
5762
value res = trade_client->get_contract(U("AAPL"));
5863
ucout << U("contract: ") << res << endl;
5964
}
6065

66+
static void test_get_contracts(const std::shared_ptr<TradeClient>& trade_client) {
67+
value symbols = value::array();
68+
symbols[0] = value::string(U("AAPL"));
69+
symbols[1] = value::string(U("JD"));
70+
value res = trade_client->get_contracts(symbols, U("STK"));
71+
ucout << U("contracts: ") << res << endl;
72+
}
73+
74+
static void test_get_quote_contract(const std::shared_ptr<TradeClient>& trade_client) {
75+
value res = trade_client->get_quote_contract(U("00700"), U("IOPT"), U("20230728"));
76+
ucout << U("quote contract: ") << res << endl;
77+
}
78+
79+
static void test_get_estimate_tradable_quantity(const std::shared_ptr<TradeClient>& trade_client) {
80+
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
81+
Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
82+
value res = trade_client->get_estimate_tradable_quantity(order);
83+
ucout << U("estimate tradable quantity: ") << res << endl;
84+
}
85+
6186
static void test_place_order(const std::shared_ptr<TradeClient>& trade_client) {
6287
Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
6388
Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
@@ -115,9 +140,35 @@ class TestTradeClient {
115140
ucout << U("modified order: ") << mod_order.to_string() << endl;
116141
}
117142

143+
static void test_get_analytics_asset(const std::shared_ptr<TradeClient>& trade_client) {
144+
value res = trade_client->get_analytics_asset(trade_client->client_config.account, U("2023-11-01"),
145+
U("2023-12-31"));
146+
ucout << U("analytics asset: ") << res << endl;
147+
}
148+
149+
static void test_get_segment_fund_history(const std::shared_ptr<TradeClient>& trade_client) {
150+
value res = trade_client->get_segment_fund_history();
151+
ucout << U("segment fund history: ") << res << endl;
152+
}
153+
154+
static void test_get_segment_fund_available(const std::shared_ptr<TradeClient>& trade_client) {
155+
value res = trade_client->get_segment_fund_available(U("SEC"));
156+
ucout << U("segment fund available: ") << res << endl;
157+
}
158+
159+
static void test_transfer_segment_fund(const std::shared_ptr<TradeClient>& trade_client) {
160+
value res = trade_client->transfer_segment_fund(U("SEC"), U("FUT"), 10.0);
161+
ucout << U("transfer segment fund: ") << res << endl;
162+
}
163+
164+
static void test_place_forex_order(const std::shared_ptr<TradeClient>& trade_client) {
165+
value res = trade_client->place_forex_order(U("SEC"), U("USD"), U("HKD"), 1.0);
166+
ucout << U("place forex order: ") << res << endl;
167+
}
168+
118169

119170
static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
120-
TestTradeClient::test_get_orders(trade_client);
171+
TestTradeClient::test_get_contract(trade_client);
121172
}
122173
};
123174

@@ -327,8 +378,24 @@ class TestQuoteClient {
327378
ucout << U("result: ") << result << endl;
328379
}
329380

381+
static void test_get_warrant_real_time_quote(std::shared_ptr<QuoteClient> quote_client) {
382+
value result = quote_client->get_warrant_real_time_quote(U("15792"));
383+
ucout << U("result: ") << result << endl;
384+
}
385+
386+
static void test_get_warrant_filter(std::shared_ptr<QuoteClient> quote_client) {
387+
value result = quote_client->get_warrant_filter(U("00700"));
388+
ucout << U("result: ") << result << endl;
389+
}
390+
391+
static void test_get_kline_quota(std::shared_ptr<QuoteClient> quote_client) {
392+
value result = quote_client->get_kline_quota();
393+
ucout << U("result: ") << result << endl;
394+
}
395+
396+
330397
static void test_quote(const std::shared_ptr<QuoteClient> quote_client) {
331-
TestQuoteClient::test_get_quote_real_time(quote_client);
398+
TestQuoteClient::test_get_kline_quota(quote_client);
332399
}
333400
};
334401

@@ -361,10 +428,11 @@ class TestTigerApi {
361428
int main()
362429
{
363430
/************************** set config **********************/
364-
ClientConfig config = ClientConfig();
365-
config.private_key = U("");
366-
config.tiger_id = U("");
367-
config.account = U("");
431+
ClientConfig config = ClientConfig(true);
432+
config.private_key = U("MIICXQIBAAKBgQC1amZa5YsGTklry7DAsUBOwXJCgrsZZtB21PImw/yLmrbqRfsS3vawvMigLWcCwIDnHa+hpdpeze0eHIwbZzJzUDGvRALYK9t3D8pwPVxpwX1OF8RfHCM7YQvSOvPPnHHuVQvKaR7NNm1/WmvGXC9kVJdkYQ7kCmh52siFoy1MLQIDAQABAoGAVabcmIHTt7ByncBXvUJymDxhE+HhMEcImXJEueTCca8kOUu9FNXMJvmax3VoMzZsJbIwX+OMTEJxd0wHIlEA0gECjDwFK4Q42q+ptO4QABJQVSC6I+dOt2OIY28uvT3rkenOO8KRIDt4F52PFd71ZdB1aaXixORORq1MdSLi8EkCQQDiviAB+L5R/HVxwxvqZfJ530OtFd5IipZC9YZlY1CtXWCmu89LK7UUlEuNXyGsOxyz5jLqFuNRsie5AC23tfEPAkEAzNMCa8axJWfPZIH4tGrbZ1F3I41BQdgp2zBmR7AyUMBDkli86OzmJ7QUCJA/PJxK43/IYUWm4OU5Q+SvXCr3AwJBAJTBj1Y7zwES1CpSitn5EF+MbmX71t1YrsQ3OHkD80YJ4QMCbDkw75gUwox5QSoxjd8ow3Z4laJfc1gYGeZQ41kCQQCCiQwm8cceBq3W6To+iUdw7itWngRz2Ta7uXnFwFYgvpeR4jnq3GfF7+9AkeWrVBQqLtrem0xCUfQP/+N+gudPAkBFLbt78/MpQGEDc7jyu/KE5Mp4wMMDQQwch9VLvsAZwWLysB6rZWpo3jIfp9zZ7c3zOYGNMWAZjtMmNkRJ8COH");
433+
config.tiger_id = U("1");
434+
config.account = U("402901");
435+
368436

369437

370438

@@ -374,14 +442,14 @@ int main()
374442
/**
375443
* ʹ�÷�װ�������ӿ� QuoteClient
376444
*/
377-
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
378-
TestQuoteClient::test_quote(quote_client);
445+
//std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
446+
//TestQuoteClient::test_quote(quote_client);
379447

380448
/**
381449
* ʹ�÷�װ��Ľ��׽ӿ� TradeClient
382450
*/
383-
//std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
384-
//TestTradeClient::test_trade(trade_client);
451+
std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
452+
TestTradeClient::test_trade(trade_client);
385453

386454
/**
387455
* ֱ��ʹ��δ��װ�� TigerApi

include/tigerapi/constants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static utility::string_t P_CURRENCY = U("currency");
5151
static utility::string_t P_EXCHANGE = U("exchange");
5252
static utility::string_t P_TYPE = U("type");
5353
static utility::string_t P_EXCHANGE_CODE = U("exchange_code");
54+
static utility::string_t P_PAGE = U("page");
55+
static utility::string_t P_PAGE_SIZE = U("page_size");
56+
static utility::string_t P_SORT_DIR = U("sort_dir");
57+
static utility::string_t P_SORT_FIELD_NAME = U("sort_field_name");
58+
static utility::string_t P_WITH_DETAILS = U("with_details");
59+
5460

5561
static utility::string_t OPEN_API_SERVICE_VERSION = U("3.0");
5662

include/tigerapi/quote_client.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ namespace TIGER_API {
6262
value get_option_kline_value(value identifiers, time_t begin_time, time_t end_time=4070880000000);
6363
vector<Kline> get_option_kline(value identifiers, time_t begin_time, time_t end_time=4070880000000);
6464
value get_option_trade_tick(value identifiers);
65+
value get_warrant_real_time_quote(const value &symbols);
66+
value get_warrant_real_time_quote(const utility::string_t symbol);
67+
value get_warrant_filter(const utility::string_t symbol, int page_size = 100, int page = 0,
68+
utility::string_t sort_field_name = U(""), utility::string_t sort_dir = U("SortDir_Ascend"));
69+
6570

6671
/** 期货行情 Future quote related api **/
6772
value get_future_exchange(SecType sec_type=SecType::FUT);
@@ -91,6 +96,9 @@ namespace TIGER_API {
9196
// 选股
9297
value get_market_scanner();
9398

99+
// 通用
100+
value get_kline_quota(bool with_details = false);
101+
94102
};
95103
}
96104
#endif //TIGERAPI_QUOTE_CLIENT_H

include/tigerapi/service_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ static utility::string_t FILLED_ORDERS = U("filled_orders"); // 已成交订
2424
static utility::string_t ORDER_TRANSACTIONS = U("order_transactions"); // 订单成交记录
2525
static utility::string_t ANALYTICS_ASSET = U("analytics_asset");
2626
static utility::string_t USER_LICENSE = U("user_license");
27+
static utility::string_t ESTIMATE_TRADABLE_QUANTITY = U("estimate_tradable_quantity");
28+
static utility::string_t SEGMENT_FUND_HISTORY = U("segment_fund_history");
29+
static utility::string_t SEGMENT_FUND_AVAILABLE = U("segment_fund_available");
30+
static utility::string_t TRANSFER_SEGMENT_FUND = U("transfer_segment_fund");
31+
static utility::string_t PLACE_FOREX_ORDER = U("place_forex_order");
2732

2833
//合约
2934
static utility::string_t CONTRACT = U("contract");
@@ -53,13 +58,16 @@ static utility::string_t TRADING_CALENDAR = U("trading_calendar");
5358
static utility::string_t STOCK_BROKER = U("stock_broker"); // 港股股票实时经纪队列
5459
static utility::string_t CAPITAL_DISTRIBUTION = U("capital_distribution"); // 股票当日资金分布
5560
static utility::string_t CAPITAL_FLOW = U("capital_flow"); // 股票资金流向
61+
static utility::string_t KLINE_QUOTA = U("kline_quota"); // 历史k线额度
5662

5763
// 期权行情
5864
static utility::string_t OPTION_EXPIRATION = U("option_expiration");
5965
static utility::string_t OPTION_CHAIN = U("option_chain");
6066
static utility::string_t OPTION_BRIEF = U("option_brief");
6167
static utility::string_t OPTION_KLINE = U("option_kline");
6268
static utility::string_t OPTION_TRADE_TICK = U("option_trade_tick");
69+
static utility::string_t WARRANT_FILTER = U("warrant_filter");
70+
static utility::string_t WARRANT_REAL_TIME_QUOTE = U("warrant_real_time_quote");
6371

6472
// 期货行情
6573
static utility::string_t FUTURE_EXCHANGE = U("future_exchange");

include/tigerapi/trade_client.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ namespace TIGER_API {
135135
SegmentType seg_type = SegmentType::SEC);
136136

137137
Order get_order(unsigned long long id, bool is_brief=false);
138-
Order get_transactions(utility::string_t account = U(""), long order_id = 0, utility::string_t sec_type = U(""),
139-
utility::string_t symbol = U(""), long start_time = -1, time_t end_time = -1,
140-
int limit = 100, utility::string_t expiry = U(""), double strike = 0, utility::string_t right = U(""));
138+
value get_transactions(utility::string_t account, long order_id);
139+
value get_transactions(utility::string_t account, utility::string_t symbol, utility::string_t sec_type = U(""),
140+
long start_time = -1, time_t end_time = -1,
141+
int limit = 100, utility::string_t expiry = U(""), utility::string_t strike = U(""), utility::string_t right = U(""),
142+
long order_id = 0);
143+
141144
value cancel_order(unsigned long long id);
142145
value place_order(value &order);
143146
value place_order(Order &order);
@@ -152,8 +155,19 @@ namespace TIGER_API {
152155
value
153156
get_contract(utility::string_t symbol, SecType sec_type = SecType::STK, Currency currency = Currency::ALL, utility::string_t exchange = U(""), time_t expiry = -1,
154157
utility::string_t strike = U(""), Right right = Right::ALL);
155-
156-
158+
value get_contracts(const value &symbols, utility::string_t sec_type, utility::string_t currency = U(""), utility::string_t exchange = U(""), time_t expiry = -1,
159+
utility::string_t strike = U(""), utility::string_t right = U(""));
160+
value get_quote_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t expiry);
161+
162+
value get_estimate_tradable_quantity(Order &order, utility::string_t seg_type = U("SEC"));
163+
value get_analytics_asset(utility::string_t account, utility::string_t start_date, utility::string_t end_date,
164+
utility::string_t seg_type = U("SEC"), utility::string_t currency = U("USD"),
165+
utility::string_t sub_account = U(""));
166+
167+
value get_segment_fund_history(int limit = 0);
168+
value get_segment_fund_available(utility::string_t from_segment, utility::string_t currency = U("USD"));
169+
value transfer_segment_fund(utility::string_t from_segment, utility::string_t to_segment, double amount, utility::string_t currency = U("USD"));
170+
value place_forex_order(utility::string_t seg_type, utility::string_t source_currency, utility::string_t target_currency, double source_amount);
157171

158172

159173
private:

0 commit comments

Comments
 (0)