Skip to content

Commit 95103bf

Browse files
author
JiaWen Li
committed
Merge branch 'dev' into 'master'
Dev See merge request server/openapi/openapi-cpp-sdk!2
2 parents c54e837 + 512006a commit 95103bf

37 files changed

+12306
-0
lines changed

.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
.vs
35+
.vscode
36+
*.dSYM
37+
.idea
38+
.DS_store
39+
cmake-build-debug
40+
build
41+
*-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
55+
/output/Release/openapi-cpp-sdk.ipdb
56+
/output/Release/openapi-cpp-sdk.iobj
57+
58+
Debug/
59+
Release/
60+
*.log

CMakeLists.txt

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
23+
# cpprest
24+
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
25+
find_library(CPPREST_LIBRARY NAMES cpprest)
26+
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
27+
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
28+
29+
if(APPLE)
30+
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
31+
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
32+
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/*)
33+
# Prefer the latest (make the latest one first)
34+
list(REVERSE OPENSSL_ROOT_DIR)
35+
36+
find_package(OpenSSL 1.1 REQUIRED)
37+
set(OPENSSL_VERSION "1.1.1q")
38+
39+
40+
else()
41+
find_package(OpenSSL 1.0.1 REQUIRED)
42+
set(OPENSSL_VERSION "1.0.1")
43+
endif()
44+
45+
elseif(WIN32)
46+
message(FATAL_ERROR "-- please compile via Visual Studio ")
47+
else()
48+
message(FATAL_ERROR "-- Unsupported platform sorry! :( ")
49+
endif()
50+
51+
# Configure compiler options ...
52+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
53+
54+
message("-- configuring clang options")
55+
set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
56+
57+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
58+
59+
message("-- configuring gcc options")
60+
61+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -DBOOST_LOG_DYN_LINK")
62+
63+
endif()
64+
65+
# Project construction ...
66+
# src files ...
67+
add_library(${PROJECT_NAME}
68+
src/tiger_client.cpp include/tigerapi/tiger_client.h include/tigerapi/constants.h
69+
include/tigerapi/utils.h src/utils.cpp include/tigerapi/service_types.h include/tigerapi/quote_client.h
70+
src/quote_client.cpp src/trade_client.cpp include/tigerapi/model.h src/order_util.cpp
71+
include/tigerapi/order_util.h src/contract_util.cpp include/tigerapi/contract_util.h
72+
include/tigerapi/client_config.h include/tigerapi/sign_util.h
73+
include/tigerapi/easylogging++.h src/easylogging++.cc)
74+
75+
# headers search paths ...
76+
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
77+
set(HEADER_SEARCH_PATHS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
78+
79+
# library search paths ...
80+
if(APPLE)
81+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
82+
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
83+
84+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY})
85+
else()
86+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
87+
set(LIBRARIES_SEARCH_PATHS ${CPPREST_LIBRARY} ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
88+
endif()
89+
90+
message(BOOST_LIBS " ${Boost_LIBRARIES}")
91+
message(OPENSSL_LIBS " ${OPENSSL_LIBRARIES}")
92+
#message(CPPRESTSDK_LIBRARY " ${CPPRESTSDK_LIBRARY}")
93+
message(ZLIB_LIBRARY " ${ZLIB_LIBRARY}")
94+
message(LIBRARIES_SEARCH_PATHS " ${LIBRARIES_SEARCH_PATHS}")
95+
96+
include_directories(${HEADER_SEARCH_PATHS})
97+
if (APPLE)
98+
target_link_libraries(${PROJECT_NAME} "-framework CoreFoundation")
99+
target_link_libraries(${PROJECT_NAME} "-framework Security")
100+
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
101+
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-W1, -F/Library/Frameworks ")
102+
else()
103+
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
104+
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
105+
106+
endif()
107+
108+
109+
110+
111+
install(DIRECTORY include/
112+
DESTINATION "include"
113+
FILES_MATCHING PATTERN "*.h"
114+
)
115+
116+
install(TARGETS ${PROJECT_NAME}
117+
EXPORT ${PROJECT_NAME}Targets
118+
LIBRARY DESTINATION lib
119+
ARCHIVE DESTINATION lib
120+
RUNTIME DESTINATION bin
121+
INCLUDES DESTINATION include
122+
)
123+
install(EXPORT ${PROJECT_NAME}Targets
124+
FILE ${PROJECT_NAME}Targets.cmake
125+
NAMESPACE ${PROJECT_NAME}::
126+
DESTINATION lib/cmake/${PROJECT_NAME}
127+
)

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# 编译步骤
2+
3+
## Linux/Mac
4+
5+
### 安装 Boost
6+
[参考文档](https://www.boost.org/doc/libs/1_81_0/more/getting_started/unix-variants.html)
7+
8+
安装方式一:使用 homebrew
9+
```shell
10+
brew install boost
11+
```
12+
13+
安装方式二:源码安装
14+
1. 下载源码到任意路径: https://www.boost.org/users/history/version_1_81_0.html,
15+
以 /usr/local/ 为例
16+
```shell
17+
cd /usr/local/
18+
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.bz2
19+
```
20+
2. 解压:
21+
```
22+
tar --bzip2 -xf boost_1_81_0.tar.bz2
23+
```
24+
3. 编译
25+
```shell
26+
cd /usr/local/boost_1_81_0
27+
./bootstrap.sh
28+
./b2 headers
29+
./b2
30+
```
31+
32+
33+
### 编译安装 cpprestsdk
34+
```
35+
cd /tmp # 选择暂存源码的目录,此处用 /tmp,也可根据本机环境指定其他系统路径
36+
git clone https://github.com/microsoft/cpprestsdk.git
37+
cd cpprestsdk
38+
git submodule update --init
39+
mkdir build
40+
cd build
41+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
42+
make -j 8
43+
make install
44+
```
45+
46+
**说明**
47+
[参考文档](https://github.com/Microsoft/cpprestsdk/wiki/Getting-Started-Tutorial)
48+
直接通过包管理软件安装的 cpprestsdk 可能不是最新版本, 可能会有未知问题
49+
50+
### 编译 tigerapi sdk
51+
若使用编译好的sdk,此步骤可跳过
52+
准备工作:根据系统环境调整 CMakeLists.txt 的相关路径
53+
54+
1. 进入源码目录
55+
2. 创建编译目录
56+
```
57+
mkdir build
58+
cd build
59+
```
60+
3. 编译
61+
```
62+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
63+
make -j 6
64+
make install
65+
```
66+
67+
### 安装 tigerapi sdk
68+
将头文件放入头文件路径, 如 /usr/local/include
69+
将库文件放入库文件路径, 如 /usr/local/lib/
70+
71+
72+
### 验证测试
73+
编译运行demo项目
74+
75+
76+
77+
## Windows
78+
依赖:Visual Stodio C++ 开发环境 https://visualstudio.microsoft.com/zh-hans/
79+
下载安装Visual Stodio Installer,勾选 "使用C++的桌面开发"
80+
81+
使用[vcpkg](https://vcpkg.io/en/getting-started.html)
82+
83+
84+
### 安装 boost
85+
如使用sdk自带的库文件,此步骤可跳过
86+
[参考文档](https://www.boost.org/doc/libs/1_81_0/more/getting_started/windows.html)
87+
```
88+
vcpkg install boost
89+
```
90+
91+
### 安装 openssl
92+
如使用sdk自带的库文件,此步骤可跳过
93+
```
94+
vcpkg install openssl
95+
```
96+
97+
### 安装 cpprestsdk
98+
如使用sdk自带的库文件,此步骤可跳过
99+
```
100+
PS> vcpkg install cpprestsdk cpprestsdk:x64-windows
101+
```
102+
103+
### 安装 tigerapi sdk
104+
源码output里的dll或lib为sdk编译后的库,项目配置引入后即可调用sdk
105+
106+
107+
108+
109+
110+
# 快速开始
111+
安装后,可参照demo目录的示例
112+
113+
114+
115+
# 常见编译问题
116+
1. mac系统 dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicudata.70.dylib
117+
```
118+
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicudata.70.dylib
119+
Referenced from: /usr/local/opt/boost/lib/libboost_log-mt.dylib
120+
Reason: image not found
121+
```
122+
Fix:
123+
```
124+
cd /usr/local/opt/icu4c/lib
125+
ln -s libicudata.dylib libicudata.70.dylib
126+
ln -s libicui18n.dylib libicui18n.70.dylib
127+
ln -s libicuuc.dylib libicuuc.70.dylib
128+
```
129+
将环境变量添加到shell配置:(如 ~/.bashrc 或 ~/.zshrc),添加后需重启shell生效
130+
```shell
131+
export LDFLAGS="-L/usr/local/opt/icu4c/lib"
132+
export CPPFLAGS="-I/usr/local/opt/icu4c/include"
133+
```
134+
135+

changlog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 (2023-02-15)
2+
### New
3+
- Beta版本,支持交易、行情接口

0 commit comments

Comments
 (0)