Skip to content

Commit aeb67bc

Browse files
author
JiaWen Li
committed
modify win build
1 parent a4cd662 commit aeb67bc

File tree

11 files changed

+510
-136
lines changed

11 files changed

+510
-136
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
*.out
3232
*.app
3333

34+
.vs
3435
.vscode
3536
*.dSYM
3637
.idea
3738

3839
cmake-build-debug
3940
build
41+

CMakeLists.txt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,41 @@ if(UNIX) # Darwing or Linux
4343
endif()
4444

4545
elseif(WIN32) # Windows systems including Win64.
46-
message(FATAL_ERROR "-- Windows is not supported for now.")
46+
#set(CMAKE_PREFIX_PATH "D:/projects/vcpkg/packages/")
47+
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/projects/boost_1_81_0")
48+
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/projects/boost_1_81_0/lib")
49+
FIND_PACKAGE(Boost)
50+
IF (Boost_FOUND)
51+
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
52+
ADD_DEFINITIONS( "-DHAS_BOOST" )
53+
ENDIF()
54+
55+
#find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
56+
#find_package(Threads REQUIRED)
57+
58+
59+
file(GLOB OPENSSL_ROOT_DIR D:/projects/vcpkg/packages/openssl_x86-windows/*)
60+
# Prefer the latest (make the latest one first)
61+
list(REVERSE OPENSSL_ROOT_DIR)
62+
find_package(OpenSSL REQUIRED)
63+
64+
#file(GLOB cpprestsdk_DIR D:/projects/vcpkg/packages/cpprestsdk_x86-windows/share/*)
65+
#list(REVERSE cpprestsdk_DIR)
66+
# find_package(cpprestsdk CONFIG REQUIRED)
67+
# cpprest
68+
#find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
69+
#find_library(CPPREST_LIBRARY NAMES cpprest)
70+
71+
72+
73+
#file(GLOB ZLIB_ROOT D:/projects/vcpkg/packages/zlib_x86-windows/*)
74+
#(REVERSE ZLIB_ROOT)
75+
#find_package(ZLIB REQUIRED)
76+
77+
#set(CMAKE_PREFIX_PATH "D:/projects/vcpkg/packages/brotli_x86-windows/share/unofficial-brotli")
78+
#file(GLOB unofficial-brotli_DIR D:/projects/vcpkg/packages/brotli_x86-windows/*)
79+
#list(REVERSE unofficial-brotli_DIR)
80+
#find_package(unofficial-brotli CONFIG REQUIRED)
4781
else()
4882
message(FATAL_ERROR "-- Unsupported platform sorry! :( ")
4983
endif()
@@ -71,22 +105,27 @@ add_executable(${PROJECT_NAME} src/main.cpp src/base64.h
71105
include/tigerapi/utils.h src/utils.cpp include/tigerapi/service_types.h include/tigerapi/quote_client.h src/quote_client.cpp src/trade_client.cpp include/tigerapi/model.h src/order_util.cpp include/tigerapi/order_util.h src/contract_util.cpp include/tigerapi/contract_util.h include/tigerapi/client_config.h include/tigerapi/log.h src/common/sign_util.h)
72106

73107
# headers search paths ...
74-
set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
108+
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
109+
set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
75110

76111
# library search paths ...
77112
if(APPLE)
78113
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
79114
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
80115

81116
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY})
117+
elseif(WIN32)
118+
set(ZIP_LIBRARY "D:/projects/vcpkg/packages/zlib_x86-windows/zlib_x86-windows/lib/zlib.lib")
119+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
120+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
82121
else()
83122
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
84-
set(LIBRARIES_SEARCH_PATHS ${CPPREST_LIBRARY} ${OPENSSL_LIBS} ${Boost_LIBRARIES})
123+
set(LIBRARIES_SEARCH_PATHS ${CPPREST_LIBRARY} ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
85124
endif()
86125

87126
message(BOOST_LIBS " ${Boost_LIBRARIES}")
88127
message(OPENSSL_LIBS " ${OPENSSL_LIBRARIES}")
89-
message(CPPRESTSDK_LIBRARY " ${CPPRESTSDK_LIBRARY}")
128+
#message(CPPRESTSDK_LIBRARY " ${CPPRESTSDK_LIBRARY}")
90129
message(ZLIB_LIBRARY " ${ZLIB_LIBRARY}")
91130
message(LIBRARIES_SEARCH_PATHS " ${LIBRARIES_SEARCH_PATHS}")
92131

@@ -98,6 +137,8 @@ if (APPLE)
98137
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-W1, -F/Library/Frameworks ")
99138
else()
100139
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
140+
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
141+
101142
endif()
102143

103144
#set(CMAKE_INSTALL_PREFIX "./")

OpenApiCppSdk.sln

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/common/sign_util.h

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,12 @@ using namespace std;
1616

1717
#include <bcrypt.h>
1818
#include <winternl.h>
19-
20-
// Code analysis complains even though there is no bug.
21-
#pragma warning(push)
22-
#pragma warning(disable : 6102)
23-
std::vector<unsigned char> hmac_sha1(const utility::string_t& key, const utility::string_t& data)
24-
{
25-
NTSTATUS status;
26-
BCRYPT_ALG_HANDLE alg_handle = nullptr;
27-
BCRYPT_HASH_HANDLE hash_handle = nullptr;
28-
29-
std::vector<unsigned char> hash;
30-
DWORD hash_len = 0;
31-
ULONG result_len = 0;
32-
33-
const auto& key_c = conversions::utf16_to_utf8(key);
34-
const auto& data_c = conversions::utf16_to_utf8(data);
35-
36-
status = BCryptOpenAlgorithmProvider(&alg_handle, BCRYPT_SHA1_ALGORITHM, nullptr, BCRYPT_ALG_HANDLE_HMAC_FLAG);
37-
if (!NT_SUCCESS(status))
38-
{
39-
goto cleanup;
40-
}
41-
status = BCryptGetProperty(alg_handle, BCRYPT_HASH_LENGTH, (PBYTE)&hash_len, sizeof(hash_len), &result_len, 0);
42-
if (!NT_SUCCESS(status))
43-
{
44-
goto cleanup;
45-
}
46-
hash.resize(hash_len);
47-
48-
status = BCryptCreateHash(alg_handle, &hash_handle, nullptr, 0, (PBYTE)key_c.c_str(), (ULONG)key_c.length(), 0);
49-
if (!NT_SUCCESS(status))
50-
{
51-
goto cleanup;
52-
}
53-
status = BCryptHashData(hash_handle, (PBYTE)data_c.c_str(), (ULONG)data_c.length(), 0);
54-
if (!NT_SUCCESS(status))
55-
{
56-
goto cleanup;
57-
}
58-
status = BCryptFinishHash(hash_handle, hash.data(), hash_len, 0);
59-
if (!NT_SUCCESS(status))
60-
{
61-
goto cleanup;
62-
}
63-
64-
cleanup:
65-
if (hash_handle)
66-
{
67-
BCryptDestroyHash(hash_handle);
68-
}
69-
if (alg_handle)
70-
{
71-
BCryptCloseAlgorithmProvider(alg_handle, 0);
72-
}
73-
74-
return hash;
75-
}
76-
#pragma warning(pop)
19+
#include <Windows.h>
20+
#include <openssl/hmac.h>
21+
#include <openssl/pem.h>
22+
#include <openssl/rsa.h>
23+
#include <openssl/bio.h>
24+
#include <openssl/err.h>
7725

7826

7927
RSA * create_rsa(utility::char_t *key, bool is_private) {
@@ -100,17 +48,17 @@ RSA * create_rsa(utility::char_t *key, bool is_private) {
10048
utility::string_t sha1_sign(const utility::string_t& context, const utility::string_t& key) {
10149
unsigned char encrypted[8196 * 16] = {};
10250
unsigned int encrypted_length;
103-
unsigned char hash[SHA_DIGEST_LENGTH] = U("");
51+
unsigned char hash[SHA_DIGEST_LENGTH] = "";
10452

10553
SHA1((const unsigned char*)context.c_str(), context.size(), hash);
10654
RSA *rsa = create_rsa((utility::char_t *)key.c_str(), true);
10755
int ret = RSA_sign(NID_sha1, hash, SHA_DIGEST_LENGTH,
10856
encrypted, &encrypted_length, rsa);
10957
if (ret == 1) {
110-
utility::string_t s(reinterpret_cast<char*>(encrypted));
58+
utility::string_t s(reinterpret_cast<wchar_t*>(encrypted));
11159
return s;
11260
}
113-
return "";
61+
return U("");
11462
}
11563

11664
int sha1_verify(const utility::string_t& context, const utility::string_t& sign, const utility::string_t& key) {
@@ -122,7 +70,7 @@ int sha1_verify(const utility::string_t& context, const utility::string_t& sign,
12270
memcpy(sigbuf, decoded.data(), decoded.size());
12371
siglen = decoded.size();
12472

125-
unsigned char hash[SHA_DIGEST_LENGTH] = U("");
73+
unsigned char hash[SHA_DIGEST_LENGTH] = "";
12674

12775
SHA1((const unsigned char*)context.c_str(), context.size(), hash);
12876

src/contract_util.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,9 @@ Contract future_contract(const utility::string_t symbol, const utility::string_t
3636

3737

3838
std::tuple<utility::string_t , utility::string_t , utility::string_t , double> extract_option_info(const utility::string_t identifier) {
39-
if (!identifier.empty()) {
40-
std::smatch tokens;
41-
std::regex re(R"((\w+)\s*(\d{6})([CP])(\d+))");
42-
if (std::regex_match(identifier, tokens, re)) {
43-
utility::string_t underlying_symbol = tokens[1];
44-
utility::string_t expiry = tokens[2];
45-
expiry = U("20") + expiry;
46-
if (expiry.size() == 8) {
47-
expiry = expiry.substr(0, 4) + U("-") + expiry.substr(4, 2) + U("-") + expiry.substr(6);
48-
}
49-
utility::string_t put_call = (tokens[3] == U("C")) ? U("CALL") : U("PUT");
50-
double strike = std::stod(tokens[4]) / 1000;
51-
return std::make_tuple(underlying_symbol, expiry, put_call, strike);
52-
} else {
53-
return std::make_tuple(U(""), U(""), U(""), 0.0);
54-
}
55-
} else {
39+
5640
return std::make_tuple(U(""), U(""), U(""), 0.0);
57-
}
41+
5842
}
5943

6044

src/quote_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ namespace TIGER_API {
216216
value options = value::array();
217217
for (size_t i = 0; i < identifiers.size(); ++i) {
218218
auto identifier = identifiers[i];
219-
std::string symbol, expiry, right;
219+
utility::string_t symbol, expiry, right;
220220
double strike;
221221
std::tie(symbol, expiry, right, strike) = extract_option_info(identifier.as_string());
222222
if (symbol.empty() || expiry.empty() || right.empty()) {

src/tiger_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace TIGER_API {
6060
request.headers().clear();
6161
request.headers().add(U("Accept"), U("application/json"));
6262
request.headers().set_content_type(U("application/json; charset=UTF-8"));
63-
request.headers().add(P_USER_AGENT, P_SDK_VERSION_PREFIX + PROJECT_VERSION);
63+
request.headers().add(P_USER_AGENT, P_SDK_VERSION_PREFIX + U(PROJECT_VERSION));
6464

6565
/************************** set request body ***************************/
6666

src/trade_client.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace TIGER_API {
4040
return portfolio;
4141
}
4242

43-
value TradeClient::get_asset(string account, const value &sub_accounts, bool segment, bool market_value) {
43+
value TradeClient::get_asset(utility::string_t account, const value &sub_accounts, bool segment, bool market_value) {
4444
value obj = value::object(true);
4545
obj[P_ACCOUNT] = get_account_param(account);
4646
obj[U("segment")] = segment;
@@ -87,15 +87,15 @@ namespace TIGER_API {
8787
return post(POSITIONS, obj)[P_ITEMS];
8888
}
8989

90-
value TradeClient::get_positions(string account, SecType sec_type, Currency currency, Market market, utility::string_t symbol,
90+
value TradeClient::get_positions(utility::string_t account, SecType sec_type, Currency currency, Market market, utility::string_t symbol,
9191
const value &sub_accounts, long expiry, double strike, Right right) {
9292
return get_positions(account, enum_to_str(sec_type), enum_to_str(currency), enum_to_str(market),
9393
symbol, sub_accounts, expiry, strike, enum_to_str(right));
9494
}
9595

9696

9797
vector<Position>
98-
TradeClient::get_position_list(string account, utility::string_t sec_type, utility::string_t currency, utility::string_t market, utility::string_t symbol,
98+
TradeClient::get_position_list(utility::string_t account, utility::string_t sec_type, utility::string_t currency, utility::string_t market, utility::string_t symbol,
9999
const value &sub_accounts, long expiry, double strike, utility::string_t right) {
100100
std::vector<Position> vec;
101101
value positions = get_positions(account, sec_type, currency, market, symbol,
@@ -145,14 +145,14 @@ namespace TIGER_API {
145145
return post(ORDERS, obj)[P_ITEMS];
146146
}
147147

148-
value TradeClient::get_orders(string account, SecType sec_type, Market market, utility::string_t symbol, long start_time,
148+
value TradeClient::get_orders(utility::string_t account, SecType sec_type, Market market, utility::string_t symbol, long start_time,
149149
long end_time, int limit, bool is_brief, const value &states, OrderSortBy sort_by,
150150
SegmentType seg_type) {
151151
return get_orders(account, enum_to_str(sec_type), enum_to_str(market), symbol, start_time, end_time, limit,
152152
is_brief, states, enum_to_str(sort_by), enum_to_str(seg_type));
153153
}
154154

155-
value TradeClient::get_active_orders(string account, utility::string_t sec_type, utility::string_t market, utility::string_t symbol, long start_time,
155+
value TradeClient::get_active_orders(utility::string_t account, utility::string_t sec_type, utility::string_t market, utility::string_t symbol, long start_time,
156156
long end_time, long parent_id, utility::string_t sort_by, utility::string_t seg_type) {
157157
value obj = value::object(true);
158158
obj[P_ACCOUNT] = get_account_param(account);
@@ -184,14 +184,14 @@ namespace TIGER_API {
184184
}
185185

186186
value
187-
TradeClient::get_active_orders(string account, SecType sec_type, Market market, utility::string_t symbol, long start_time,
187+
TradeClient::get_active_orders(utility::string_t account, SecType sec_type, Market market, utility::string_t symbol, long start_time,
188188
long end_time, long parent_id, OrderSortBy sort_by, SegmentType seg_type) {
189189
return get_active_orders(account, enum_to_str(sec_type), enum_to_str(market), symbol, start_time, end_time,
190190
parent_id, enum_to_str(sort_by), enum_to_str(seg_type));
191191
}
192192

193193

194-
value TradeClient::get_contract(string symbol, utility::string_t sec_type, utility::string_t currency, utility::string_t exchange, long expiry,
194+
value TradeClient::get_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t currency, utility::string_t exchange, long expiry,
195195
double strike, utility::string_t right) {
196196
value obj = value::object(true);
197197
obj[P_ACCOUNT] = get_account_param();
@@ -219,7 +219,7 @@ namespace TIGER_API {
219219
return post(CONTRACT, obj);
220220
}
221221

222-
value TradeClient::get_contract(string symbol, SecType sec_type, Currency currency, utility::string_t exchange, long expiry,
222+
value TradeClient::get_contract(utility::string_t symbol, SecType sec_type, Currency currency, utility::string_t exchange, long expiry,
223223
double strike, Right right) {
224224
return get_contract(symbol, enum_to_str(sec_type), enum_to_str(currency), exchange, expiry, strike,
225225
enum_to_str(right));

0 commit comments

Comments
 (0)