Skip to content

Commit 586867b

Browse files
author
JiaWen Li
committed
Merge branch 'feature_tcp_client' into 'dev'
添加win/mac编译生成的库 See merge request server/openapi/openapi-cpp-sdk!40
2 parents 1471586 + 99341f7 commit 586867b

File tree

13 files changed

+608
-254
lines changed

13 files changed

+608
-254
lines changed

CMakeListsBak.txt

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
4+
# Find the source file that contains the version information
5+
find_file(VERSION_FILE include/tigerapi/version.h PATHS ${CMAKE_SOURCE_DIR})
6+
7+
message(version file " ${VERSION_FILE}")
8+
# Extract the version information from the source file
9+
file(READ ${VERSION_FILE} VERSION_FILE_CONTENTS)
10+
string(REGEX MATCH "([0-9]\\.[0-9]\\.[0-9])"
11+
PROJECT_VERSION "${VERSION_FILE_CONTENTS}")
12+
message(PROJECT_VERSION " ${PROJECT_VERSION}")
13+
14+
project(tigerapi VERSION ${PROJECT_VERSION})
15+
16+
17+
# Configure required libraries ...
18+
if(UNIX) # Darwing or Linux
19+
20+
find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
21+
find_package(Threads REQUIRED)
22+
find_package(absl REQUIRED)
23+
24+
# cpprest
25+
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
26+
find_library(CPPREST_LIBRARY NAMES cpprest)
27+
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
28+
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
29+
30+
set(Protobuf_INCLUDE_DIR "/usr/local/opt/protobuf/include")
31+
set(Protobuf_LIBRARY "/usr/local/opt/protobuf/lib/libprotobuf.dylib")
32+
set(Protobuf_PROTOC_LIBRARY "/usr/local/opt/protobuf/lib/libprotoc.dylib")
33+
set(Protobuf_PROTOC_EXECUTABLE "/usr/local/opt/protobuf/bin/protoc")
34+
35+
# 查找 Protobuf 包
36+
find_package(Protobuf REQUIRED)
37+
message(STATUS "Protobuf version: ${Protobuf_VERSION}")
38+
message(STATUS "Protobuf include dir: ${Protobuf_INCLUDE_DIR}")
39+
message(STATUS "Protobuf libraries: ${Protobuf_LIBRARY}")
40+
41+
if(APPLE)
42+
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
43+
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/* /opt/homebrew/Cellar/openssl@3/*)
44+
# Prefer the latest (make the latest one first)
45+
list(REVERSE OPENSSL_ROOT_DIR)
46+
47+
find_package(OpenSSL REQUIRED)
48+
message(OPENSSL_ROOT_DIR " ${OPENSSL_ROOT_DIR}")
49+
message(OPENSSL_LIBRARIES " ${OPENSSL_LIBRARIES}")
50+
51+
# set(OPENSSL_VERSION "1.1.1q")
52+
53+
set(ZLIB_LIBRARY /opt/homebrew/Cellar/zlib/1.2.13/lib/libz.dylib )
54+
message(ZLIB_LIBRARY " ${ZLIB_LIBRARY}")
55+
56+
else()
57+
find_package(OpenSSL 1.0.1 REQUIRED)
58+
set(OPENSSL_VERSION "1.0.1")
59+
endif()
60+
61+
elseif(WIN32)
62+
message(FATAL_ERROR "-- please compile via Visual Studio ")
63+
else()
64+
message(FATAL_ERROR "-- Unsupported platform sorry! :( ")
65+
endif()
66+
67+
# Configure compiler options ...
68+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
69+
70+
message("-- configuring clang options")
71+
# set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
72+
set(CMAKE_CXX_FLAGS "-arch arm64 -std=c++14 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
73+
74+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
75+
76+
message("-- configuring gcc options")
77+
78+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -DBOOST_LOG_DYN_LINK")
79+
80+
endif()
81+
82+
# Project construction ...
83+
# src files ...
84+
file(GLOB MY_SOURCE_FILES "include/cpprest/*.h" "include/cpprest/details/*.h" "include/openapi_pb/pb_source/*.*"
85+
"include/tigerapi/push_socket/*.h" "include/tigerapi/*.h" "src/*.cpp" "src/push_socket/*.cpp")
86+
add_library(${PROJECT_NAME} cpprest/ ${MY_SOURCE_FILES})
87+
message(MY_SOURCE_FILES " ${MY_SOURCE_FILES}")
88+
# 确保生成动态库
89+
set_target_properties(${PROJECT_NAME} PROPERTIES
90+
SOVERSION ${PROJECT_VERSION}
91+
VERSION ${PROJECT_VERSION}
92+
)
93+
94+
# headers search paths ...
95+
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
96+
set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${PROTOBUF_INCLUDE_DIR})
97+
98+
99+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
100+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY} ${Protobuf_LIBRARY} ${Protobuf_PROTOC_LIBRARY})
101+
102+
103+
message(BOOST_LIBS " ${Boost_LIBRARIES}")
104+
message(OPENSSL_LIBS " ${OPENSSL_LIBRARIES}")
105+
#message(CPPRESTSDK_LIBRARY " ${CPPRESTSDK_LIBRARY}")
106+
message(ZLIB_LIBRARY " ${ZLIB_LIBRARY}")
107+
message(LIBRARIES_SEARCH_PATHS " ${LIBRARIES_SEARCH_PATHS}")
108+
109+
include_directories(${HEADER_SEARCH_PATHS})
110+
if (APPLE)
111+
target_link_libraries(${PROJECT_NAME} PRIVATE
112+
"-framework CoreFoundation"
113+
"-framework Security"
114+
${LIBRARIES_SEARCH_PATHS}
115+
absl::base
116+
absl::utility
117+
)
118+
set_target_properties(${PROJECT_NAME} PROPERTIES
119+
LINK_FLAGS "-W1, -F/Library/Frameworks"
120+
)
121+
else()
122+
target_link_libraries(${PROJECT_NAME} PRIVATE
123+
${LIBRARIES_SEARCH_PATHS}
124+
OpenSSL::SSL
125+
OpenSSL::Crypto
126+
)
127+
endif()
128+
129+
130+
131+
132+
install(DIRECTORY include/
133+
DESTINATION "include"
134+
FILES_MATCHING
135+
PATTERN "*.h"
136+
# PATTERN "*.cc"
137+
)
138+
139+
install(TARGETS ${PROJECT_NAME}
140+
EXPORT ${PROJECT_NAME}Targets
141+
LIBRARY DESTINATION lib
142+
ARCHIVE DESTINATION lib
143+
RUNTIME DESTINATION bin
144+
INCLUDES DESTINATION include
145+
)
146+
install(EXPORT ${PROJECT_NAME}Targets
147+
FILE ${PROJECT_NAME}Targets.cmake
148+
NAMESPACE ${PROJECT_NAME}::
149+
DESTINATION lib/cmake/${PROJECT_NAME}
150+
)

changlog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0 (2024-11-28)
2+
### New
3+
- 支持长连接推送
4+
15
## 0.1.6 (2024-03-08)
26
### New
37
- 新增根据ticksize调整下单价格的工具 PriceUtil

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <chrono>
1515
#include <thread>
1616

17-
1817
using namespace std;
1918
using namespace web;
2019
using namespace web::json;
@@ -116,18 +115,17 @@ class TestTradeClient {
116115
//Contract contract = ContractUtil::option_contract(U("AAPL 230721C00185000"));
117116
//Contract contract = ContractUtil::option_contract(U("AAPL 230721P00185000"));
118117
Order order = OrderUtil::limit_order(contract, U("BUY"), 3, U("0.18"));
119-
// order.adjust_limit = 0.01;
118+
//order.adjust_limit = 0.01;
120119
value res = trade_client->place_order(order);
121120
//unsigned long long id = res[U("id")].as_number().to_uint64();
122121
ucout << U("order id: ") << order.id << endl;
123122
ucout << U("place order result: ") << res << endl;
124123
}
125-
126-
124+
127125
static void test_get_order(const std::shared_ptr<TradeClient>& trade_client) {
128-
// Contract contract = stock_contract(U("AAPL"), U("USD"));
129-
// Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
130-
// trade_client->place_order(order);
126+
//Contract contract = stock_contract(U("AAPL"), U("USD"));
127+
//Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 100.0);
128+
//trade_client->place_order(order);
131129
Order my_order = trade_client->get_order(31318009878020096);
132130
ucout << U("order id ") << my_order.id << endl;
133131
ucout << U("order : ") << my_order.to_string() << endl;
@@ -187,11 +185,9 @@ class TestTradeClient {
187185

188186
};
189187

190-
191188
/**
192189
* Test Quote Client
193190
*/
194-
195191
class TestQuoteClient {
196192
public:
197193
static void test_grab_quote_permission(std::shared_ptr<QuoteClient> quote_client) {
@@ -236,8 +232,7 @@ class TestQuoteClient {
236232
value result = quote_client->get_history_timeline(symbols, U("2023-01-10"));
237233
ucout << U("result: ") << result << endl;
238234
}
239-
240-
235+
241236
static void test_get_quote_real_time(const std::shared_ptr<QuoteClient> quote_client) {
242237
value symbols = value::array();
243238
symbols[0] = value::string(U("AAPL"));
@@ -276,7 +271,7 @@ class TestQuoteClient {
276271
symbols[0] = value::string(U("AAPL"));
277272
symbols[1] = value::string(U("JD"));
278273
//ucout << U("symbols ") << symbols << endl;
279-
// value result = quote_client->get_kline(symbols, U("day"), -1, -1, U("br"), 5);
274+
//value result = quote_client->get_kline(symbols, U("day"), -1, -1, U("br"), 5);
280275
vector<Kline> result = quote_client->get_kline(symbols, U("day"), -1, -1, 5);
281276
ucout << result.at(0).to_string() << endl;
282277
}
@@ -355,7 +350,7 @@ class TestQuoteClient {
355350
value symbols = value::array();
356351
symbols[0] = value::string(U("CL2303"));
357352
ucout << U("symbols ") << symbols << endl;
358-
// value result = quote_client->get_future_real_time_quote(symbols);
353+
//value result = quote_client->get_future_real_time_quote(symbols);
359354
auto result = quote_client->get_future_real_time_quote(symbols);
360355
ucout << U("result: ") << result.at(0).to_string() << endl;
361356
}
@@ -382,7 +377,7 @@ class TestQuoteClient {
382377
static void test_get_option_kline(std::shared_ptr<QuoteClient> quote_client) {
383378
value identifiers = value::array();
384379
identifiers[0] = value::string(U("AAPL 230224C000150000"));
385-
// value result = quote_client->get_option_kline(identifiers, 1639026000000, 1649026000000);
380+
//value result = quote_client->get_option_kline(identifiers, 1639026000000, 1649026000000);
386381
vector<Kline> result = quote_client->get_option_kline(identifiers, 1639026000000, 1649026000000);
387382
ucout << U("result: ") << result.at(0).to_string() << endl;
388383
}
@@ -441,9 +436,7 @@ class TestTigerApi {
441436
}
442437
};
443438

444-
445439
std::atomic<bool> keep_running(true);
446-
447440
void signal_handler(int signal)
448441
{
449442
if (signal == SIGINT || signal == SIGTERM)
@@ -452,7 +445,6 @@ void signal_handler(int signal)
452445
}
453446
}
454447

455-
456448
class TestPushClient {
457449
private:
458450
std::shared_ptr<IPushClient> push_client;
@@ -587,27 +579,22 @@ class TestPushClient {
587579
}
588580
};
589581

590-
591582
int main()
592583
{
593-
/************************** set config **********************/
594-
ClientConfig config = ClientConfig();
595-
#if 1
596-
// config.private_key = U("");
597-
// config.tiger_id = U("");
598-
// config.account = U("");
599-
config.use_full_tick = true;
600-
601-
#else
584+
//Set Tiger OpenAPI SDK configuration
585+
bool sand_box = false;
586+
ClientConfig config = ClientConfig(sand_box);
602587
config.private_key = U("");
603588
config.tiger_id = U("");
604589
config.account = U("");
605-
#endif
606-
590+
config.use_full_tick = true;
607591
//config.lang = U("en_US");
608592

593+
//Create a push client instance
609594
auto push_client = IPushClient::create_push_client(config);
595+
//Run some push test cases
610596
TestPushClient::test_push_client(push_client, config);
597+
611598
/**
612599
* QuoteClient
613600
*/
@@ -617,16 +604,14 @@ int main()
617604
/**
618605
* TradeClient
619606
*/
620-
//std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
621-
//TestTradeClient::test_trade(trade_client);
622-
623-
/**
624-
* TigerApi
625-
*/
626-
// std::shared_ptr<TigerClient> tigerapi = std::make_shared<TigerClient>(config);
627-
// TestTigerApi::test_grab_quote_permission(tigerapi);
628-
607+
//std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
608+
//TestTradeClient::test_trade(trade_client);
629609

610+
/**
611+
* TigerApi
612+
*/
613+
//std::shared_ptr<TigerClient> tigerapi = std::make_shared<TigerClient>(config);
614+
//TestTigerApi::test_grab_quote_permission(tigerapi);
630615

631616
return 0;
632617
}

0 commit comments

Comments
 (0)