Skip to content

Commit e253514

Browse files
committed
fix compile
1 parent 1244880 commit e253514

File tree

3 files changed

+66
-27
lines changed

3 files changed

+66
-27
lines changed

CMakeLists.txt

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,24 @@ if(UNIX) # Darwing or Linux
2121
find_package(Threads REQUIRED)
2222
find_package(absl REQUIRED)
2323

24-
2524
# cpprest
2625
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
2726
find_library(CPPREST_LIBRARY NAMES cpprest)
2827
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
2928
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
30-
31-
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}")
3240

3341
if(APPLE)
34-
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
3542
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
3643
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/* /opt/homebrew/Cellar/openssl@3/*)
3744
# Prefer the latest (make the latest one first)
@@ -71,22 +78,18 @@ endif()
7178

7279
# Project construction ...
7380
# src files ...
74-
file(GLOB MY_SOURCE_FILES "include/cpprest/*.h" "include/cpprest/details/*.h" "include/tigerapi/push_socket/*.h" "include/tigerapi/*.h" "src/*.cpp" "src/push_socket/*.cpp")
81+
file(GLOB MY_SOURCE_FILES "include/cpprest/*.h" "include/cpprest/details/*.h"
82+
"include/tigerapi/push_socket/*.h" "include/tigerapi/*.h" "src/*.cpp" "src/push_socket/*.cpp")
7583
add_library(${PROJECT_NAME} cpprest/ ${MY_SOURCE_FILES})
7684

7785
# headers search paths ...
7886
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
79-
set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${Protobuf_INCLUDE_DIRS})
87+
set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${PROTOBUF_INCLUDE_DIR})
88+
8089

81-
# library search paths ...
82-
#if(APPLE)
8390
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
84-
# set(ZIP_LIBRARY ZLIB::ZLIB)
85-
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY} ${Protobuf_LIBRARIES})
86-
#else()
87-
# set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
88-
# set(LIBRARIES_SEARCH_PATHS ${CPPREST_LIBRARY} ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
89-
#endif()
91+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY} ${Protobuf_LIBRARY} ${Protobuf_PROTOC_LIBRARY})
92+
9093

9194
message(BOOST_LIBS " ${Boost_LIBRARIES}")
9295
message(OPENSSL_LIBS " ${OPENSSL_LIBRARIES}")
@@ -96,19 +99,22 @@ message(LIBRARIES_SEARCH_PATHS " ${LIBRARIES_SEARCH_PATHS}")
9699

97100
include_directories(${HEADER_SEARCH_PATHS})
98101
if (APPLE)
99-
target_link_libraries(${PROJECT_NAME} "-framework CoreFoundation")
100-
target_link_libraries(${PROJECT_NAME} "-framework Security")
101-
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
102-
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-W1, -F/Library/Frameworks ")
103-
target_link_libraries(${PROJECT_NAME}
104-
absl::base
105-
absl::utility
106-
protobuf::libprotobuf
102+
target_link_libraries(${PROJECT_NAME} PRIVATE
103+
"-framework CoreFoundation"
104+
"-framework Security"
105+
${LIBRARIES_SEARCH_PATHS}
106+
absl::base
107+
absl::utility
108+
)
109+
set_target_properties(${PROJECT_NAME} PROPERTIES
110+
LINK_FLAGS "-W1, -F/Library/Frameworks"
107111
)
108112
else()
109-
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
110-
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
111-
113+
target_link_libraries(${PROJECT_NAME} PRIVATE
114+
${LIBRARIES_SEARCH_PATHS}
115+
OpenSSL::SSL
116+
OpenSSL::Crypto
117+
)
112118
endif()
113119

114120

include/tigerapi/push_socket/push_client_impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../include/tigerapi/client_config.h"
77
#include "../include/openapi_pb/pb_source/Request.pb.h"
88
#include "../include/openapi_pb/pb_source/Response.pb.h"
9+
#include "../include/openapi_pb/pb_source/SocketCommon.pb.h"
910

1011
namespace TIGER_API
1112
{
@@ -27,6 +28,10 @@ namespace TIGER_API
2728
virtual void set_connected_callback(const std::function<void()>& cb) override;
2829
virtual void set_disconnected_callback(const std::function<void()>& cb) override;
2930
virtual void set_inner_error_callback(const std::function<void(std::string)>& cb) override;
31+
32+
virtual void set_subscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
33+
virtual void set_unsubscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
34+
virtual void set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
3035

3136
virtual void set_asset_changed_callback(const std::function<void(const tigeropen::push::pb::AssetData&)>& cb) override;
3237
virtual bool subscribe_asset(const std::string& account) override;
@@ -88,6 +93,9 @@ namespace TIGER_API
8893
bool send_trade_request(tigeropen::push::pb::SocketCommon_Command command, tigeropen::push::pb::SocketCommon_DataType datatype, const std::string& account);
8994
bool send_quote_request(tigeropen::push::pb::SocketCommon_Command command, tigeropen::push::pb::SocketCommon_DataType datatype, std::vector<std::string> symbols, const std::string& market);
9095
private:
96+
std::function<void(const tigeropen::push::pb::Response& subscribe_response)> subscribe_callback_;
97+
std::function<void(const tigeropen::push::pb::Response& unsubscribe_response)> unsubscribe_callback_;
98+
std::function<void(const tigeropen::push::pb::Response& error_response)> error_callback_;
9199
std::function<void(const tigeropen::push::pb::AssetData& asset_data)> asset_changed_;
92100
std::function<void(const tigeropen::push::pb::PositionData& position_data)> position_changed_;
93101
std::function<void(const tigeropen::push::pb::OrderStatusData& order_status_data)> order_changed_;

src/push_socket/push_client_impl.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ void TIGER_API::PushClientImpl::set_inner_error_callback(const std::function<voi
6767
}
6868
}
6969

70+
void TIGER_API::PushClientImpl::set_subscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb)
71+
{
72+
subscribe_callback_ = cb;
73+
}
74+
75+
void TIGER_API::PushClientImpl::set_unsubscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb)
76+
{
77+
unsubscribe_callback_ = cb;
78+
}
79+
80+
void TIGER_API::PushClientImpl::set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb)
81+
{
82+
error_callback_ = cb;
83+
}
84+
7085
void TIGER_API::PushClientImpl::query_subscribed_symbols()
7186
{
7287
tigeropen::push::pb::Request request;
@@ -135,6 +150,16 @@ bool TIGER_API::PushClientImpl::subscribe_quote(const std::vector<std::string>&
135150
return send_quote_request(tigeropen::push::pb::SocketCommon_Command_SUBSCRIBE, tigeropen::push::pb::SocketCommon_DataType::SocketCommon_DataType_Quote, symbols);
136151
}
137152

153+
bool TIGER_API::PushClientImpl::subscribe_future_quote(const std::vector<std::string>& symbols)
154+
{
155+
return send_quote_request(tigeropen::push::pb::SocketCommon_Command_SUBSCRIBE, tigeropen::push::pb::SocketCommon_DataType::SocketCommon_DataType_Future, symbols);
156+
}
157+
158+
bool TIGER_API::PushClientImpl::subscribe_option_quote(const std::vector<std::string>& symbols)
159+
{
160+
return send_quote_request(tigeropen::push::pb::SocketCommon_Command_SUBSCRIBE, tigeropen::push::pb::SocketCommon_DataType::SocketCommon_DataType_Option, symbols);
161+
}
162+
138163

139164
bool TIGER_API::PushClientImpl::unsubscribe_quote(const std::vector<std::string>& symbols)
140165
{
@@ -344,8 +369,8 @@ void TIGER_API::PushClientImpl::on_message(const std::shared_ptr<tigeropen::push
344369
{
345370
try {
346371
if (frame->code() == ResponseType::GET_SUB_SYMBOLS_END) {
347-
if (query_subscribed_callback_) {
348-
query_subscribed_callback_(frame->msg());
372+
if (query_subscribed_symbols_changed_) {
373+
query_subscribed_symbols_changed_(frame->msg());
349374
}
350375
}
351376
else if (frame->code() == ResponseType::GET_SUBSCRIBE_END) {

0 commit comments

Comments
 (0)