更新
This commit is contained in:
parent
145bfa55c3
commit
bd78353ee5
@ -1,117 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(vn_ctp_api)
|
||||
|
||||
# 设置使用的编译器
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
if (CMAKE_COMPILER_IS_GNUC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11")
|
||||
endif ()
|
||||
|
||||
# 设置输出目录
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
# 使用64位编译
|
||||
option(USE_64BITS "comiple 64bits" ON)
|
||||
if (USE_64BITS)
|
||||
add_definitions(-DUSE_64BITS)
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
|
||||
endif()
|
||||
|
||||
# 设置C++ API源文件的所在目录
|
||||
if (WIN32)
|
||||
set(CTPAPI_PATH ctpapi)
|
||||
elseif (UNIX)
|
||||
message("Under unix: " ${CMAKE_SIZEOF_VOID_P})
|
||||
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(CTPAPI_PATH ctpapi/x64_linux)
|
||||
endif()
|
||||
endif()
|
||||
include_directories(${CTPAPI_PATH})
|
||||
set(CTPAPI_LIBRARY )
|
||||
find_library(CTPAPI_MD_LIBRARY
|
||||
NAMES thostmduserapi_se
|
||||
PATHS ${CTPAPI_PATH})
|
||||
find_library(CTPAPI_TD_LIBRARY
|
||||
NAMES thosttraderapi_se
|
||||
PATHS ${CTPAPI_PATH})
|
||||
|
||||
message("CTPAPI_MD_LIBRARY:" ${CTPAPI_MD_LIBRARY})
|
||||
message("CTPAPI_TD_LIBRARY:" ${CTPAPI_TD_LIBRARY})
|
||||
|
||||
# 设置编译源文件
|
||||
set (vnctpmd )
|
||||
set (vnctptd )
|
||||
|
||||
option(BUILD_CTP_MD "build ctp md" ON)
|
||||
if (BUILD_CTP_MD)
|
||||
add_definitions(-DBUILD_CTP_MD)
|
||||
set(CTP_MD_PATH vnctpmd/vnctpmd)
|
||||
include_directories(${CTP_MD_PATH})
|
||||
set(VN_CTP_MD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctpmd/vnctpmd/vnctpmd.cpp)
|
||||
add_library(vnctpmd SHARED ${VN_CTP_MD_SOURCE})
|
||||
endif()
|
||||
option(BUILD_CTP_TD "build ctp td" ON)
|
||||
if (BUILD_CTP_TD)
|
||||
add_definitions(-DBUILD_CTP_TD)
|
||||
set(CTP_TD_PATH vnctptd/vnctptd)
|
||||
include_directories(${CTP_TD_PATH})
|
||||
set(VN_CTP_TD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctptd/vnctptd/vnctptd.cpp)
|
||||
add_library(vnctptd SHARED ${VN_CTP_TD_SOURCE})
|
||||
endif()
|
||||
|
||||
|
||||
# 设置Python所在的目录
|
||||
set(PYTHON_LIBRARY )
|
||||
if (WIN32)
|
||||
set(PYTHON_INCLUDE_PATH C:/Python27/include)
|
||||
find_library(PYTHON_LIBRARY
|
||||
NAMES python27
|
||||
PATHS C:/Python27/libs)
|
||||
include_directories(${PYTHON_INCLUDE_PATH})
|
||||
else()
|
||||
set(PYTHON_INCLUDE_PATH /home/trade/anaconda3/envs/py35/include/python3.5m)
|
||||
find_library(PYTHON_LIBRARY
|
||||
NAMES python3.5
|
||||
PATHS /home/trade/anaconda3/envs/py35/lib/)
|
||||
include_directories(${PYTHON_INCLUDE_PATH})
|
||||
endif()
|
||||
|
||||
# hard code virtual environment
|
||||
set (PYTHON_LIBRARY /home/trade/anaconda3/envs/py35/lib/libpython3.so)
|
||||
|
||||
# 链接boost库,anaconda
|
||||
if (WIN32)
|
||||
set(Boost_USE_STATIC_LIBS ON) #链接boost静态库
|
||||
endif()
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
find_package(Boost 1.66.0 COMPONENTS locale thread date_time system chrono python3 REQUIRED) # 如果boost库没有完全编译,需要将编译的库明确地指出,否者message(${Boost_LIBRARIES})会出错
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# hard code boost include folder
|
||||
set(MY_BOOST_INCLUDE /usr/local/include/boost)
|
||||
include_directories(${MY_BOOST_INCLUDE})
|
||||
|
||||
# 去掉生成的so文件名中前缀的lib
|
||||
set_target_properties(vnctpmd PROPERTIES PREFIX "")
|
||||
|
||||
set(MY_BOOST /usr/local/lib)
|
||||
# 链接生成.so文件
|
||||
target_link_libraries(vnctpmd ${MY_BOOST} ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY})
|
||||
|
||||
# 将生成的dll文件后缀名修改为pyd(仅在windows下)
|
||||
set(MD_DLL "${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.dll")
|
||||
if (EXISTS ${MD_DLL})
|
||||
file(RENAME ${MD_DLL} ${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.pyd)
|
||||
endif()
|
||||
|
||||
# 和上面的MD相同
|
||||
set_target_properties(vnctptd PROPERTIES PREFIX "")
|
||||
target_link_libraries(vnctptd ${MY_BOOST} ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY})
|
||||
set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll)
|
||||
if (EXISTS ${TD_DLL})
|
||||
file(RENAME ${TD_DLL} ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.pyd)
|
||||
endif()
|
@ -1,5 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.api.ctp_se.vnctpmd import MdApi
|
||||
from vnpy.api.ctp_se.vnctptd import TdApi
|
||||
from vnpy.api.ctp_se.ctp_data_type import defineDict
|
@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Written by Suzhengchun on 20160213
|
||||
# updated by Incenselee on 20180226, support PY3 in Linux
|
||||
set -e
|
||||
BUILDDIR=build
|
||||
rm -rf $BUILDDIR
|
||||
if [ ! -f $BUILDDIR ]; then
|
||||
mkdir -p $BUILDDIR
|
||||
fi
|
||||
pushd $BUILDDIR
|
||||
cmake ..
|
||||
make VERBOSE=1 -j 1
|
||||
ln -fs `pwd`/lib/vnctpmd.so ../vnctpmd.so
|
||||
ln -fs `pwd`/lib/vnctptd.so ../vnctptd.so
|
||||
cp ../vnctpmd.* ../../../trader/gateway/ctpseGateway/
|
||||
cp ../vnctptd.* ../../../trader/gateway/ctpseGateway/
|
||||
popd
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -1,70 +0,0 @@
|
||||
# vn.ctp
|
||||
|
||||
|
||||
### 简介
|
||||
CTP柜台API接口的Python封装,基于pyscript目录下的脚本自动分析头文件生成封装代码模块,提供原生C++ API中的全部功能。
|
||||
|
||||
|
||||
### 目录说明
|
||||
* py3: Windows下编译
|
||||
* vnctpmd: 行情API(py3)
|
||||
* vnctptd: 交易API(py3)
|
||||
* pyscript: 自动封装脚本
|
||||
* ctpapi:C++ API文件
|
||||
|
||||
### 使用CMake编译
|
||||
|
||||
**Windows 7/10**
|
||||
|
||||
环境配置:
|
||||
|
||||
* Anaconda使用64bit,python 3, 如 python 3.5 3.6
|
||||
|
||||
* Boost 使用 1.57 以上
|
||||
boost 安装后,有一个stage的版本,对应include & lib的路径。
|
||||
* cmake:安装最新版本的cmake,用于配置编译环境
|
||||
|
||||
* 设置环境变量:BOOST_ROOT = C:\boost_1_57_0
|
||||
|
||||
* 编译工具:Visual Studio 2017
|
||||
|
||||
|
||||
编译过程:
|
||||
|
||||
* 使用 Visual Studio 2017, 打开 py3/vnctpmd下解决方案vnctpmd.sln
|
||||
|
||||
* 检查“项目”配置中,对应的include和ib目录,均要包含python 3.x 和boost的include & lib路径
|
||||
|
||||
* 点击编译按钮,建议编译release库
|
||||
|
||||
* vnctptd的编译同上。
|
||||
|
||||
|
||||
**Linux (Debian jessie, Ubuntu 16.04)**
|
||||
|
||||
环境配置:
|
||||
|
||||
* 参考[这里](http://www.continuum.io/downloads)的教程下载并安装Anaconda的Linux 64位版本
|
||||
|
||||
* 使用apt-get安装编译相关的工具,注意某些老的Ubuntu必须指定使用boost 1.58.0版本:
|
||||
|
||||
- apt-get install build-essential
|
||||
|
||||
- apt-get install libboost-all-dev
|
||||
|
||||
- apt-get install python-dev
|
||||
|
||||
- apt-get install cmake
|
||||
|
||||
* 如果从官网下载新的ctp api tar包,比如v6.3.5_20150803_tradeapi_linux64.tar,需要重命名ctp api so文件名(否则可以忽略该步骤):
|
||||
|
||||
- thostmduserapi.so --> libthostmduserapi.so
|
||||
|
||||
- thosttraderapi.so --> libthosttraderapi.so
|
||||
|
||||
|
||||
编译过程:
|
||||
|
||||
* 当前目录运行build.sh,完成编译
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user