├── .gitattributes ├── .gitignore ├── readme.md └── vnpy ├── CMakeLists.txt ├── api ├── ctp │ ├── CMakeLists.txt │ ├── __init__.py │ ├── ctp_data_type.py │ ├── ctpapi │ │ ├── dll_win32 │ │ │ ├── ThostFtdcMdApi.h │ │ │ ├── ThostFtdcTraderApi.h │ │ │ ├── ThostFtdcUserApiDataType.h │ │ │ ├── ThostFtdcUserApiStruct.h │ │ │ ├── error.dtd │ │ │ ├── error.xml │ │ │ ├── md5.txt │ │ │ ├── thostmduserapi.dll │ │ │ ├── thostmduserapi.lib │ │ │ ├── thosttraderapi.dll │ │ │ └── thosttraderapi.lib │ │ └── x64_linux │ │ │ ├── ThostFtdcMdApi.h │ │ │ ├── ThostFtdcTraderApi.h │ │ │ ├── ThostFtdcUserApiDataType.h │ │ │ ├── ThostFtdcUserApiStruct.h │ │ │ ├── error.dtd │ │ │ ├── error.xml │ │ │ ├── libthostmduserapi.so │ │ │ └── libthosttraderapi.so │ ├── readme.md │ ├── vnctpmd │ │ ├── CMakeLists.txt │ │ ├── vnctpmd.cpp │ │ └── vnctpmd.h │ └── vnctptd │ │ ├── CMakeLists.txt │ │ ├── vnctptd.cpp │ │ └── vnctptd.h └── xtp │ ├── CMakeLists.txt │ ├── __init__.py │ ├── readme.md │ ├── vnxtpquote │ ├── CMakeLists.txt │ ├── vnxtpquote.cpp │ └── vnxtpquote.h │ ├── vnxtptrader │ ├── CMakeLists.txt │ ├── vnxtptrader.cpp │ └── vnxtptrader.h │ ├── xtpGateway.py │ ├── xtpGateway_md.py │ ├── xtpGateway_td.py │ ├── xtp_data_type.py │ └── xtpapi-1.1.16 │ ├── include │ ├── xoms_api_fund_struct.h │ ├── xoms_api_struct.h │ ├── xquote_api_struct.h │ ├── xtp_api_data_type.h │ ├── xtp_api_struct.h │ ├── xtp_api_struct_common.h │ ├── xtp_quote_api.h │ └── xtp_trader_api.h │ ├── linux │ ├── libsodium.so │ ├── libsodium.so.18 │ ├── libxtpquoteapi.so │ └── libxtptraderapi.so │ ├── win32 │ └── dll │ │ ├── libsodium.dll │ │ ├── xtpquoteapi.dll │ │ ├── xtpquoteapi.lib │ │ ├── xtptraderapi.dll │ │ └── xtptraderapi.lib │ └── win64 │ └── dll │ ├── libsodium.dll │ ├── xtpquoteapi.dll │ ├── xtpquoteapi.lib │ ├── xtptraderapi.dll │ └── xtptraderapi.lib ├── cmake ├── configuration.cmake └── vnpy3common.cmake ├── compile.bat └── compile.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ### Introduction: 2 | vnpy3 is a simplified vn.py running in python3. 3 | The core code is borrowed from vnpy: https://github.com/vnpy/vnpy 4 | We are still in development. 5 | Currently, this project targets experienced users. 6 | 7 | ### Contribution: 8 | - simplified the building process with cmake 9 | - supporting python3, theoretically, it also supports python2 (not tested) 10 | 11 | ### Supporting Interface: 12 | - ctp 13 | - xtp 14 | 15 | ### Dependency: 16 | 1. boost (1.57 or later) [tested: 1.65] 17 | 2. cmake (3.0 or later) [tested: 3.9] 18 | 3. visual studio (2011 or later) [tested: 2013] 19 | 20 | Please let me know if you have any question and if you want to add more tested enviroments. 21 | 22 | ### Compiling: 23 | 1. edit configuration file: vnpy/cmake/configuration.cmake to set proper path for boost and python; 24 | 25 | 1.1 We currently use shared-lib for python/boost.python and static-lib for other boost-libraries, 26 | 27 | 1.2 you may want to do some changes (see Line 20-31, 40-42 in vnpy/CMakeLists.txt). 28 | 2. On windows: edit compile.bat by setting proper location for MSBuild.exe and cmake.exe; 29 | 3. run compile.bat or compile.sh depending on your system. 30 | 31 | --- 32 | ### Belief 33 | Write once, use everywhere. 34 | 35 | ### License 36 | MIT -------------------------------------------------------------------------------- /vnpy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(vnpy_apis) 3 | 4 | 5 | set(BUILD_SHARED_LIBS OFF) 6 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 7 | 8 | # # load configuration 9 | include(configuration) 10 | 11 | if(NOT (BOOST_ROOT AND IS_DIRECTORY ${BOOST_ROOT})) 12 | message(FATAL_ERROR "BOOST_ROOT:" ${BOOST_ROOT} " DOES NOT EXIST! Please edit file cmake/configuration.cmake") 13 | endif() 14 | if(NOT (PYTHON_INCLUDE_DIR AND IS_DIRECTORY ${PYTHON_INCLUDE_DIR})) 15 | message(FATAL_ERROR "PYTHON_INCLUDE_DIR:" ${PYTHON_INCLUDE_DIR} " DOES NOT EXIST! Please edit file cmake/configuration.cmake") 16 | endif() 17 | 18 | include(vnpy3common) 19 | init_compiler_system() 20 | 21 | 22 | FIND_PACKAGE(PythonInterp) 23 | FIND_PACKAGE(PythonLibs) 24 | message(STATUS "PYTHON_INCLUDE_DIRS: " ${PYTHON_INCLUDE_DIRS}) 25 | message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES}) 26 | message(STATUS "PYTHON_LIB_VERSION: " ${PYTHONLIBS_VERSION_STRING}) 27 | 28 | # # build python extension dynamically 29 | set(Boost_USE_STATIC_LIBS OFF) 30 | set(Boost_USE_MULTITHREADED ON) 31 | set(Boost_USE_STATIC_RUNTIME OFF) 32 | 33 | find_package(Boost 1.57 COMPONENTS python) 34 | if(NOT Boost_FOUND) 35 | find_package(Boost 1.57 COMPONENTS python3 REQUIRED) 36 | endif() 37 | set(Boost_PY_LIBRARIES ${Boost_LIBRARIES}) 38 | message(status "** Boost_PY_Libraries: ${Boost_PY_LIBRARIES}") 39 | 40 | set(Boost_USE_STATIC_LIBS ON) 41 | set(Boost_USE_MULTITHREADED ON) 42 | set(Boost_USE_STATIC_RUNTIME OFF) 43 | find_package(Boost 1.57 COMPONENTS thread system atomic date_time chrono REQUIRED) 44 | 45 | message(status "**Boost_LIBRARIES: ${Boost_LIBRARIES}") 46 | INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) 47 | 48 | add_subdirectory(api/xtp) 49 | add_subdirectory(api/ctp) 50 | 51 | 52 | -------------------------------------------------------------------------------- /vnpy/api/ctp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(vn_ctp_api) 3 | 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}) 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | set(CTPAPI_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ctpapi) 8 | 9 | if(WIN32) 10 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 11 | message(FATAL_ERROR "CTP API Currently does not support Win64") 12 | else() 13 | set(CTPAPI_PATH_LIB ${CTPAPI_PATH}/dll_win32) 14 | endif() 15 | 16 | file(GLOB CTPAPI_LIB_DLL ${CTPAPI_PATH_LIB}/*.dll) 17 | 18 | else() 19 | set(CTPAPI_PATH_LIB ${CTPAPI_PATH}/x64_linux) 20 | file(GLOB CTPAPI_LIB_DLL ${CTPAPI_PATH_LIB}/*.so) 21 | endif() 22 | 23 | include_directories(${CTPAPI_PATH_LIB}) 24 | unset(CTPAPI_MD_LIBRARY CACHE) 25 | unset(CTPAPI_TD_LIBRARY CACHE) 26 | find_library(CTPAPI_MD_LIBRARY NAMES thostmduserapi PATHS ${CTPAPI_PATH_LIB}) 27 | find_library(CTPAPI_TD_LIBRARY NAMES thosttraderapi PATHS ${CTPAPI_PATH_LIB}) 28 | 29 | 30 | message(STATUS "CTPAPI_LIB_DLL: " ${CTPAPI_LIB_DLL}) 31 | message(STATUS "CTPAPI_MD_LIBRARY: " ${CTPAPI_MD_LIBRARY}) 32 | message(STATUS "CTPAPI_TD_LIBRARY: " ${CTPAPI_TD_LIBRARY}) 33 | 34 | add_subdirectory(vnctpmd) 35 | add_subdirectory(vnctptd) 36 | 37 | -------------------------------------------------------------------------------- /vnpy/api/ctp/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | from vnctpmd import MdApi 4 | from vnctptd import TdApi 5 | from ctp_data_type import defineDict -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/error.xml -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/md5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/md5.txt -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/thostmduserapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/thostmduserapi.dll -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/thostmduserapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/thostmduserapi.lib -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/thosttraderapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/thosttraderapi.dll -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/dll_win32/thosttraderapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/dll_win32/thosttraderapi.lib -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/error.xml -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/libthostmduserapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/libthostmduserapi.so -------------------------------------------------------------------------------- /vnpy/api/ctp/ctpapi/x64_linux/libthosttraderapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/ctpapi/x64_linux/libthosttraderapi.so -------------------------------------------------------------------------------- /vnpy/api/ctp/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/readme.md -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctpmd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(source_dir ${CMAKE_CURRENT_SOURCE_DIR}) 3 | 4 | set(headers 5 | ${source_dir}/vnctpmd.h 6 | ) 7 | set(sources 8 | ${source_dir}/vnctpmd.cpp 9 | ) 10 | 11 | PYTHON_ADD_MODULE(vnctpmd ${headers} ${sources}) 12 | TARGET_include_directories(vnctpmd PUBLIC ${PYTHON_INCLUDE_DIRS}) 13 | TARGET_LINK_LIBRARIES(vnctpmd ${Boost_LIBRARIES} ${Boost_PY_LIBRARIES} ${PYTHON_LIBRARIES} ${CTPAPI_MD_LIBRARY}) 14 | 15 | add_custom_command(TARGET vnctpmd POST_BUILD 16 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CTPAPI_LIB_DLL} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE}) -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctpmd/vnctpmd.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/vnctpmd/vnctpmd.cpp -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctpmd/vnctpmd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/vnctpmd/vnctpmd.h -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctptd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(source_dir ${CMAKE_CURRENT_SOURCE_DIR}) 3 | 4 | set(headers 5 | ${source_dir}/vnctptd.h 6 | ) 7 | set(sources 8 | ${source_dir}/vnctptd.cpp 9 | ) 10 | 11 | PYTHON_ADD_MODULE(vnctptd ${headers} ${sources}) 12 | TARGET_include_directories(vnctptd PUBLIC ${PYTHON_INCLUDE_DIRS}) 13 | TARGET_LINK_LIBRARIES(vnctptd ${Boost_LIBRARIES} ${Boost_PY_LIBRARIES} ${PYTHON_LIBRARIES} ${CTPAPI_TD_LIBRARY}) 14 | 15 | 16 | add_custom_command(TARGET vnctptd POST_BUILD 17 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CTPAPI_LIB_DLL} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE}) 18 | -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctptd/vnctptd.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/vnctptd/vnctptd.cpp -------------------------------------------------------------------------------- /vnpy/api/ctp/vnctptd/vnctptd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/ctp/vnctptd/vnctptd.h -------------------------------------------------------------------------------- /vnpy/api/xtp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(vn_xtp_api) 3 | 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}) 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | set(XTPAPI_PATH ${CMAKE_CURRENT_SOURCE_DIR}/xtpapi-1.1.16) 8 | 9 | 10 | if(WIN32) 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | set(XTPAPI_PATH_LIB ${XTPAPI_PATH}/win64/dll) 13 | else() 14 | set(XTPAPI_PATH_LIB ${XTPAPI_PATH}/win32/dll) 15 | endif() 16 | 17 | file(GLOB XTPAPI_LIB_DLL ${XTPAPI_PATH_LIB}/*.dll) 18 | else() 19 | set(XTPAPI_PATH_LIB ${XTPAPI_PATH}/linux) 20 | 21 | file(GLOB XTPAPI_LIB_DLL ${XTPAPI_PATH_LIB}/*.so) 22 | endif() 23 | 24 | include_directories(${XTPAPI_PATH}/include) 25 | find_library(XTPAPI_MD_LIBRARY NAMES xtpquoteapi PATHS ${XTPAPI_PATH_LIB}) 26 | find_library(XTPAPI_TD_LIBRARY NAMES xtptraderapi PATHS ${XTPAPI_PATH_LIB}) 27 | 28 | message(STATUS "XTPAPI_LIB_DLL: " ${XTPAPI_LIB_DLL}) 29 | message(STATUS "XTPAPI_MD_LIBRARY: " ${XTPAPI_MD_LIBRARY}) 30 | message(STATUS "XTPAPI_TD_LIBRARY: " ${XTPAPI_TD_LIBRARY}) 31 | 32 | add_subdirectory(vnxtpquote) 33 | add_subdirectory(vnxtptrader) 34 | 35 | -------------------------------------------------------------------------------- /vnpy/api/xtp/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | from .vnxtpquote import QuoteApi 4 | from .vnxtptrader import TraderApi 5 | from .xtp_data_type import * 6 | from .xtpGateway import XtpGateway 7 | from .xtpGateway_md import XtpMdApi 8 | from .xtpGateway_td import XtpTdApi 9 | -------------------------------------------------------------------------------- /vnpy/api/xtp/readme.md: -------------------------------------------------------------------------------- 1 | # vn.xtp 2 | 3 | ### Introduction 4 | 5 | [English] python2/python3 wrapper for Xtp interface. 6 | 7 | [Chinese] 中泰证券XTP柜台接口的Python2/Python3封装 8 | 9 | Supporting Windows 32(beta) / Windows x64 / Linux x64. 10 | 11 | ### Python Usage 12 | Please take a look at xtpGateway.py files. 13 | 14 | ### API Version 15 | Date: 2017.12.04 16 | 17 | Name: xtp_api_v1.1.16.09 18 | 19 | Link: [https://xtp.zts.com.cn/] 20 | -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtpquote/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_definitions(-DBUILD_XTP_MD) 3 | set(source_dir ${CMAKE_CURRENT_SOURCE_DIR}) 4 | 5 | set(headers 6 | ${source_dir}/vnxtpquote.h 7 | ) 8 | set(sources 9 | ${source_dir}/vnxtpquote.cpp 10 | ) 11 | 12 | PYTHON_ADD_MODULE(vnxtpquote ${headers} ${sources}) 13 | TARGET_include_directories(vnxtpquote PUBLIC ${PYTHON_INCLUDE_DIRS}) 14 | TARGET_LINK_LIBRARIES(vnxtpquote ${Boost_LIBRARIES} ${Boost_PY_LIBRARIES} ${PYTHON_LIBRARIES} ${XTPAPI_MD_LIBRARY}) 15 | 16 | add_custom_command(TARGET vnxtpquote POST_BUILD 17 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${XTPAPI_LIB_DLL} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE}) -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtpquote/vnxtpquote.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/vnxtpquote/vnxtpquote.cpp -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtpquote/vnxtpquote.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/vnxtpquote/vnxtpquote.h -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtptrader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(source_dir ${CMAKE_CURRENT_SOURCE_DIR}) 3 | 4 | set(headers 5 | ${source_dir}/vnxtptrader.h 6 | ) 7 | set(sources 8 | ${source_dir}/vnxtptrader.cpp 9 | ) 10 | 11 | PYTHON_ADD_MODULE(vnxtptrader ${headers} ${sources}) 12 | TARGET_include_directories(vnxtptrader PUBLIC ${PYTHON_INCLUDE_DIRS}) 13 | TARGET_LINK_LIBRARIES(vnxtptrader ${Boost_LIBRARIES} ${Boost_PY_LIBRARIES} ${PYTHON_LIBRARIES} ${XTPAPI_TD_LIBRARY}) 14 | 15 | 16 | add_custom_command(TARGET vnxtptrader POST_BUILD 17 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${XTPAPI_LIB_DLL} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE}) 18 | -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtptrader/vnxtptrader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/vnxtptrader/vnxtptrader.cpp -------------------------------------------------------------------------------- /vnpy/api/xtp/vnxtptrader/vnxtptrader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/vnxtptrader/vnxtptrader.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpGateway.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .xtpGateway_md import XtpMdApi 4 | from .xtpGateway_td import XtpTdApi 5 | 6 | XTP_EXCHANGE_SH = 1 #, ///<上证 7 | XTP_EXCHANGE_SZ = 2 #, ///<深证 8 | 9 | ######################################################################## 10 | class XtpGateway(object): 11 | """XTP接口""" 12 | 13 | #---------------------------------------------------------------------- 14 | def __init__(self, conf): 15 | """Constructor" 16 | :param conf: dict with key(userID, password, clientID, softwareKey, tdAddress, tdPort, mdAddress, mdPort) 17 | """ 18 | 19 | md_conf = dict({k: conf[k] for k in ['userID', 'password', 'clientID', 'mdAddress', 'mdPort']}) 20 | td_conf = dict({k: conf[k] for k in ['userID', 'password', 'clientID', 'softwareKey', 'tdAddress', 'tdPort']}) 21 | 22 | self.mdApi = XtpMdApi(self, md_conf) # 行情API 23 | self.tdApi = XtpTdApi(self, td_conf) # 交易API 24 | 25 | self.ticker_info_data = {} 26 | 27 | def OnLog(self, msg): 28 | print(msg) 29 | 30 | def OnError(self, error_id, error_msg): 31 | pass 32 | 33 | def connect(self): 34 | """连接""" 35 | 36 | # setting = self.conf 37 | # try: 38 | # userID = str(setting['userID']) 39 | # password = str(setting['password']) 40 | # clientID = int(setting['clientID']) 41 | # softwareKey = str(setting['softwareKey']) 42 | # tdAddress = str(setting['tdAddress']) 43 | # tdPort = int(setting['tdPort']) 44 | # mdAddress = str(setting['mdAddress']) 45 | # mdPort = int(setting['mdPort']) 46 | # except KeyError as err: 47 | # self.OnLog('Configuration File Misses some configuration, please check. Msg: %s' % err) 48 | # return 49 | 50 | # 创建行情和交易接口对象 51 | self.mdApi.connect() 52 | self.tdApi.connect() 53 | 54 | # # Steps 55 | # # 1. 初始化并启动查询 56 | # # 2. OnQueryPosition 收到 last为true时,调用 OnQueryPositionFinished 57 | # # 3. 订阅行情 58 | self.tdApi.qryPosition() 59 | self.tdApi.qryAccount() 60 | 61 | def OnQueryPositionFinished(self): 62 | """ 63 | We may want subscribe market data here; see mdApi.subscribe 64 | """ 65 | pass 66 | 67 | def close(self): 68 | """关闭""" 69 | self.mdApi.close() 70 | self.tdApi.close() 71 | 72 | def onQueryAllTickers(self, data, error, last): 73 | self.ticker_info_data[data['ticker']] = dict({'upper_price': data['upper_limit_price'], 74 | 'lower_price': data['lower_limit_price'], 75 | 'instrument_id': data['ticker'], 76 | 'price_tick': data['price_tick']}) 77 | if last: 78 | print('>>> queryAllTickers is done!!!') 79 | import json 80 | fp = open('kungfu_order_test_config.json', 'w') 81 | json.dump(self.ticker_info_data, fp, indent=4) 82 | fp.close() 83 | pass 84 | 85 | def queryAllTickers(self, exchange_id): 86 | # # 查询合约信息 87 | # self.queryAllTickers(XTP_EXCHANGE_SH) # 上交所 88 | # self.queryAllTickers(XTP_EXCHANGE_SZ) # 深交所 89 | if exchange_id == XTP_EXCHANGE_SH: 90 | self.mdApi.queryAllTickers(XTP_EXCHANGE_SH) 91 | elif exchange_id == XTP_EXCHANGE_SZ: 92 | self.mdApi.queryAllTickers(XTP_EXCHANGE_SZ) 93 | else: 94 | self.OnLog('>>> Invalid exchanged_id in queryAllTickers!!!') 95 | 96 | 97 | if __name__ == '__main__': 98 | 99 | import json 100 | with open('XTP_connect.json', 'r') as fp: 101 | xtp_conf = json.load(fp) 102 | print(xtp_conf) 103 | 104 | xtp = XtpGateway(xtp_conf) 105 | xtp.connect() 106 | while True: 107 | continue 108 | -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpGateway_md.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | from .vnxtpquote import QuoteApi 4 | 5 | 6 | class XtpMdApi(QuoteApi): 7 | """XTP行情API实现""" 8 | 9 | def __init__(self, gateway, conf): 10 | """Constructor 11 | :param conf: dict with key(userID, password, clientID, mdAddress, mdPort) 12 | """ 13 | super(XtpMdApi, self).__init__() 14 | 15 | self.gateway = gateway # gateway对象 16 | self.conf = conf 17 | 18 | self.reqID = 0 # 操作请求编号 19 | 20 | self.connectionStatus = False # 连接状态 21 | self.loginStatus = False # 登录状态 22 | 23 | self.subscribedSymbols = dict() # 已订阅合约代码 key=exchange_id, value=list(tickers) 24 | 25 | def onDisconnected(self, reason): 26 | """连接断开""" 27 | self.connectionStatus = False 28 | self.loginStatus = False 29 | 30 | content = (u'Disconnected from MdXtp. Reason: %s' % reason) 31 | self.writeLog(content) 32 | 33 | # 重新连接 34 | n = self.login(self.conf['mdAddress'], self.conf['mdPort'], self.conf['userID'], self.conf['password'], 1) 35 | if not n: 36 | self.connectionStatus = True 37 | self.loginStatus = True 38 | self.gateway.mdConnected = True 39 | self.writeLog('Connected to MdXtp!') 40 | else: 41 | self.writeLog('Failed connecting to MdXtp. Reason:%s' % n) 42 | 43 | #---------------------------------------------------------------------- 44 | def onError(self, error): 45 | """错误回报""" 46 | # log = VtLogData() 47 | # log.logContent = 'ErrorId: %d Msg: %s' % (error['error_id'], error['error_msg']) 48 | # # err.errorID = error['error_id'] 49 | # # err.errorMsg = error['error_msg'].decode('gbk') 50 | self.gateway.OnError(error['error_id'], error['error_msg']) 51 | 52 | #---------------------------------------------------------------------- 53 | def onSubMarketData(self, data, error, last): 54 | """订阅行情回报""" 55 | pass 56 | 57 | #---------------------------------------------------------------------- 58 | def onUnSubMarketData(self, data, error, last): 59 | """退订行情回报""" 60 | pass 61 | 62 | #---------------------------------------------------------------------- 63 | def onDepthMarketData(self, data): 64 | """行情推送""" 65 | # print(data) 66 | # self.gateway.OnRtnData(data) 67 | pass 68 | 69 | #---------------------------------------------------------------------- 70 | def onQueryAllTickers(self, data, error, last): 71 | """合约信息推送""" 72 | # print (data['ticker'], data['exchange_id'], data['price_tick'], data['ticker_type']) 73 | self.gateway.onQueryAllTickers(data, error, last) 74 | pass 75 | # if error and error['error_id']: 76 | # err = VtErrorData() 77 | # err.gatewayName = self.gatewayName 78 | # err.errorID = error['error_id'] 79 | # err.errorMsg = error['error_msg'].decode('gbk') 80 | # self.gateway.OnError(err) 81 | # return 82 | # 83 | # contract = VtContractData() 84 | # contract.gatewayName = self.gatewayName 85 | # 86 | # contract.symbol = data['ticker'] 87 | # contract.exchange = exchangeMapReverse.get(data['exchange_id'], EXCHANGE_UNKNOWN) 88 | # contract.vtSymbol = '.'.join([contract.symbol, contract.exchange]) 89 | # 90 | # contract.name = data['ticker_name'].decode('UTF-8') 91 | # contract.size = 1 92 | # contract.priceTick = data['price_tick'] 93 | # contract.productClass = productClassMapReverse.get(data['ticker_type'], PRODUCT_UNKNOWN) 94 | # 95 | # self.gateway.onContract(contract) 96 | 97 | #---------------------------------------------------------------------- 98 | def onSubOrderBook(self, data, error, last): 99 | """""" 100 | pass 101 | 102 | #---------------------------------------------------------------------- 103 | def onUnSubOrderBook(self, data, error, last): 104 | """""" 105 | pass 106 | 107 | #---------------------------------------------------------------------- 108 | def onOrderBook(self, data): 109 | """""" 110 | pass 111 | 112 | #---------------------------------------------------------------------- 113 | def onSubTickByTick(self, data, error, last): 114 | """""" 115 | pass 116 | 117 | #---------------------------------------------------------------------- 118 | def onUnSubTickByTick(self, data, error, last): 119 | """""" 120 | pass 121 | 122 | #---------------------------------------------------------------------- 123 | def onTickByTick(self, data): 124 | """""" 125 | pass 126 | 127 | #---------------------------------------------------------------------- 128 | def onSubscribeAllMarketData(self, error): 129 | """""" 130 | pass 131 | 132 | #---------------------------------------------------------------------- 133 | def onUnSubscribeAllMarketData(self, error): 134 | """""" 135 | pass 136 | 137 | #---------------------------------------------------------------------- 138 | def onSubscribeAllOrderBook(self, error): 139 | """""" 140 | pass 141 | 142 | #---------------------------------------------------------------------- 143 | def onUnSubscribeAllOrderBook(self, error): 144 | """""" 145 | pass 146 | 147 | #---------------------------------------------------------------------- 148 | def onSubscribeAllTickByTick(self, error): 149 | """""" 150 | pass 151 | 152 | #---------------------------------------------------------------------- 153 | def onUnSubscribeAllTickByTick(self, error): 154 | """""" 155 | pass 156 | 157 | #---------------------------------------------------------------------- 158 | def onQueryTickersPriceInfo(self, data, error, last): 159 | """""" 160 | pass 161 | 162 | #---------------------------------------------------------------------- 163 | def connect(self): 164 | """初始化连接""" 165 | # 如果尚未建立服务器连接,则进行连接 166 | if not self.connectionStatus: 167 | path = os.getcwd() + '/temp/xtp/' 168 | if not os.path.exists(path): 169 | os.makedirs(path) 170 | self.createQuoteApi(self.conf['clientID'], path) 171 | 172 | n = self.login(self.conf['mdAddress'], self.conf['mdPort'], self.conf['userID'], self.conf['password'], 1) 173 | if not n: 174 | self.connectionStatus = True 175 | self.loginStatus = True 176 | self.gateway.mdConnected = True 177 | self.writeLog('Connected to MdXtp!') 178 | else: 179 | self.writeLog('Failed connecting to MdXtp. Reason:%s' % n) 180 | 181 | #---------------------------------------------------------------------- 182 | def subscribe(self, tickers, exchange_id): 183 | """ 184 | 订阅合约 185 | :param tickers: list 186 | :param exchange_id: follows Wind convection 187 | :return: 188 | """ 189 | # 这里的设计是,如果尚未登录就调用了订阅方法 190 | # 则先保存订阅请求,登录完成后会自动订阅 191 | if exchange_id == 'SZ': 192 | xtp_exchange_id = XTP_EXCHANGE_SZ 193 | elif exchange_id == 'SH': 194 | xtp_exchange_id = XTP_EXCHANGE_SH 195 | else: 196 | print("Xtp only supports SZ, SH") 197 | return 198 | 199 | if self.loginStatus: 200 | for ticker in tickers: 201 | self.subscribeMarketData(ticker, xtp_exchange_id) 202 | if xtp_exchange_id not in self.subscribedSymbols: 203 | self.subscribedSymbols[xtp_exchange_id] = [] 204 | self.subscribedSymbols[xtp_exchange_id] += tickers 205 | 206 | #---------------------------------------------------------------------- 207 | def close(self): 208 | """关闭""" 209 | self.exit() 210 | 211 | #---------------------------------------------------------------------- 212 | def writeLog(self, content): 213 | """记录日志""" 214 | self.gateway.OnLog(content) 215 | 216 | -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpGateway_td.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | from .vnxtptrader import TraderApi 4 | 5 | 6 | ######################################################################## 7 | class XtpTdApi(TraderApi): 8 | """XTP交易API实现""" 9 | 10 | def __init__(self, gateway, conf): 11 | """API对象的初始化函数 12 | :param conf: dict with key(userID, password, clientID, softwareKey, tdAddress, tdPort) 13 | """ 14 | super(XtpTdApi, self).__init__() 15 | 16 | self.gateway = gateway # gateway对象 17 | self.conf = conf 18 | 19 | self.reqID = 0 # 操作请求编号 20 | 21 | self.connectionStatus = False # 连接状态 22 | self.loginStatus = False # 登录状态 23 | 24 | self.sessionID = 0 # 会话编号 25 | self.orderDict = {} # 委托缓存字典 26 | 27 | def onDisconnected(self, session, reason): 28 | """连接断开""" 29 | self.connectionStatus = False 30 | self.loginStatus = False 31 | self.gateway.tdConnected = False 32 | 33 | content = ('Disconnected from TdXtp. Reason: %s' % reason) 34 | self.writeLog(content) 35 | 36 | # 发起重新连接 37 | n = self.login(self.conf['tdAddress'], self.conf['tdPort'], self.conf['userID'], self.conf['password'], 1) 38 | 39 | if n: 40 | self.sessionID = n 41 | self.connectionStatus = True 42 | self.loginStatus = True 43 | self.writeLog('Connected to TdXtp. SessionID: %s' %n) 44 | else: 45 | self.writeLog('Failed connecting to TdXtp!') 46 | 47 | #---------------------------------------------------------------------- 48 | def onError(self, error): 49 | """错误回报""" 50 | # log = VtLogData() 51 | # log.logContent = 'onTdError ErrorId: %d Msg: %s' % (error['error_id'], error['error_msg']) 52 | # # err.errorID = error['error_id'] 53 | # # err.errorMsg = error['error_msg'].decode('gbk') 54 | # self.gateway.OnLog(log) 55 | self.gateway.OnError(error['error_id'], error['error_msg']) 56 | 57 | # err = VtErrorData() 58 | # err.gatewayName = self.gatewayName 59 | # err.errorID = error['error_id'] 60 | # err.errorMsg = error['error_msg'].decode('gbk') 61 | # self.gateway.OnError(err) 62 | 63 | #---------------------------------------------------------------------- 64 | def onOrderEvent(self, data, error, session): 65 | """委托数据回报""" 66 | # 错误信息 67 | if error['error_id']: 68 | self.gateway.OnError(error['error_id'], error['error_msg'] + " onOrderEvent OrderXtpId:" + str(data['order_xtp_id'])) 69 | # err = VtLogData() 70 | # err.logContent = 'onOrderEvent ErrorID: %d OrderXtpId: %d' % (error['error_id'], data['order_xtp_id']) 71 | # err.errorID = error['error_id'] 72 | # err.errorMsg = u'委托号' + str(data['order_xtp_id']) + ':' + error['error_msg'].decode('gbk') 73 | # err.errorTime = order.orderTime 74 | # self.gateway.OnLog(err) 75 | else: 76 | pass # # Your implementation 77 | 78 | def onTradeEvent(self, data, session): 79 | """成交推送""" 80 | pass # # Your implementation 81 | 82 | def onCancelOrderError(self, data, error, session): 83 | """撤单错误回报""" 84 | # 错误信息 85 | if error['error_id']: 86 | self.gateway.OnError(error['error_id'], error['error_msg'] + " onCancelOrderError OrderXtpId:" + str(data['order_xtp_id'])) 87 | else: 88 | pass # # Your implementation 89 | 90 | 91 | #---------------------------------------------------------------------- 92 | def onQueryOrder(self, data, error, reqid, last, session): 93 | """委托查询回报""" 94 | pass 95 | 96 | #---------------------------------------------------------------------- 97 | def onQueryTrade(self, data, error, reqid, last, session): 98 | """成交查询回报""" 99 | pass 100 | 101 | #---------------------------------------------------------------------- 102 | def onQueryPosition(self, data, error, reqid, last, session): 103 | """查询持仓回报""" 104 | if error['error_id']: 105 | self.gateway.OnError(error['error_id'], error['error_msg'] + " onQueryPosition.") 106 | return 107 | 108 | pass # # Your implementation 109 | 110 | if last: 111 | print('OnQueryPosition finished success!') 112 | self.gateway.OnQueryPositionFinished() 113 | 114 | #---------------------------------------------------------------------- 115 | def onQueryAsset(self, data, error, reqid, last, session): 116 | """账户查询回报""" 117 | # account = VtAccountData() 118 | # account.gatewayName = self.gatewayName 119 | # 120 | # # 账户代码 121 | # account.accountID = self.userID 122 | # account.vtAccountID = '.'.join([self.gatewayName, account.accountID]) 123 | # 124 | # # 数值相关 125 | # account.balance = float(data['total_asset']) 126 | # account.available = float(data['buying_power']) 127 | # account.commission = float(data['fund_buy_fee']) + float(data['fund_sell_fee']) 128 | print ('balance %f available %f' % (float(data['total_asset']), float(data['buying_power']))) 129 | # if last: 130 | # print('onQueryAsset finished success!') 131 | # # 推送 132 | # # self.gateway.onAccount(account) 133 | pass 134 | 135 | #---------------------------------------------------------------------- 136 | def onQueryStructuredFund(self, data, error, reqid, last, session): 137 | """""" 138 | pass 139 | 140 | #---------------------------------------------------------------------- 141 | def onQueryFundTransfer(self, data, error, reqid, last, session): 142 | """""" 143 | pass 144 | 145 | #---------------------------------------------------------------------- 146 | def onFundTransfer(self, data, error, session): 147 | """""" 148 | pass 149 | 150 | #---------------------------------------------------------------------- 151 | def onQueryETF(self, data, error, reqid, last, session): 152 | """""" 153 | pass 154 | 155 | #---------------------------------------------------------------------- 156 | def onQueryETFBasket(self, data, error, reqid, last, session): 157 | """""" 158 | pass 159 | 160 | #---------------------------------------------------------------------- 161 | def onQueryIPOInfoList(self, data, error, reqid, last, session): 162 | """""" 163 | pass 164 | 165 | #---------------------------------------------------------------------- 166 | def onQueryIPOQuotaInfo(self, data, error, reqid, last, session): 167 | """""" 168 | pass 169 | 170 | #---------------------------------------------------------------------- 171 | def connect(self): 172 | """初始化连接""" 173 | # 如果尚未建立服务器连接,则进行连接 174 | if not self.connectionStatus: 175 | path = os.getcwd() + '/temp/xtp/' 176 | if not os.path.exists(path): 177 | os.makedirs(path) 178 | self.createTraderApi(self.conf['clientID'], path) 179 | 180 | # 设置软件编码,认证用 181 | self.setSoftwareKey(self.conf['softwareKey']) 182 | 183 | # 设置订单和成交回报重传模式 184 | self.subscribePublicTopic(0) 185 | 186 | # 发起登录 187 | n = self.login(self.conf['tdAddress'], self.conf['tdPort'], self.conf['userID'], self.conf['password'], 1) 188 | 189 | if n: 190 | self.sessionID = n 191 | self.connectionStatus = True 192 | self.loginStatus = True 193 | self.writeLog('Connected to TdXtp. SessionID: %s.' %n) 194 | else: 195 | self.writeLog('Failed connecting to TdXtp!') 196 | 197 | #---------------------------------------------------------------------- 198 | def qryAccount(self): 199 | """查询账户""" 200 | if self.sessionID: 201 | self.reqID += 1 202 | self.queryAsset(self.sessionID, self.reqID) 203 | 204 | #---------------------------------------------------------------------- 205 | def qryPosition(self): 206 | """查询持仓""" 207 | if self.sessionID: 208 | self.reqID += 1 209 | self.queryPosition('', self.sessionID, self.reqID) 210 | 211 | #---------------------------------------------------------------------- 212 | def sendOrder(self, req): 213 | """发单""" 214 | return self.insertOrder(req, self.sessionID) 215 | # req = {} 216 | # req['ticker'] = orderReq.symbol 217 | # req['price'] = orderReq.price 218 | # req['quantity'] = orderReq.volume 219 | # req['price_type'] = priceTypeMap.get(orderReq.priceType, 0) 220 | # req['market'] = marketMap.get(orderReq.exchange, 0) 221 | # req['business_type'] = 0 # 目前只支持买卖业务 222 | # 223 | # # 目前尚未支持衍生品交易,因此不适用 224 | # #req['side'] = sideMap.get((orderReq.direction, OFFSET_NONE), 0) 225 | # if orderReq.direction == DIRECTION_LONG: 226 | # req['side'] = 1 227 | # else: 228 | # req['side'] = 2 229 | # 230 | # # 发出委托 231 | # orderID = str(self.insertOrder(req, self.sessionID)) 232 | # vtOrderID = '.'.join([self.gatewayName, orderID]) 233 | # 234 | # # 返回订单号(字符串),便于某些算法进行动态管理 235 | # return vtOrderID 236 | 237 | #---------------------------------------------------------------------- 238 | def sendCancel(self, order_xtp_id): 239 | """撤单,因为cancelOrder的命名已经被原生接口使用了,所以改为sendCancel""" 240 | return self.cancelOrder(order_xtp_id, self.sessionID) 241 | 242 | #---------------------------------------------------------------------- 243 | def close(self): 244 | """关闭""" 245 | self.exit() 246 | 247 | #---------------------------------------------------------------------- 248 | def writeLog(self, content): 249 | """记录日志""" 250 | self.gateway.OnLog(content) 251 | 252 | -------------------------------------------------------------------------------- /vnpy/api/xtp/xtp_data_type.py: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | typedefDict = {} 4 | 5 | ######################################################################### 6 | ###@author 中泰证券股份有限公司 7 | ###@file xtp_api_data_type.h 8 | ###@brief 定义兼容数据基本类型 9 | ######################################################################### 10 | 11 | 12 | ### 存放版本号的字符串长度 13 | XTP_VERSION_LEN = 16 14 | ### 版本号类型 15 | typedefDict["XTPVersionType"] = "string" 16 | ### 可交易日字符串长度 17 | XTP_TRADING_DAY_LEN = 9 18 | ### 存放证券代码的字符串长度 19 | XTP_TICKER_LEN = 16 20 | ### 存放证券名称的字符串长度 21 | XTP_TICKER_NAME_LEN = 64 22 | ### 本地报单编号的字符串长度 23 | XTP_LOCAL_ORDER_LEN = 11 24 | ### 交易所单号的字符串长度 25 | XTP_ORDER_EXCH_LEN = 17 26 | ### 成交执行编号的字符串长度 27 | XTP_EXEC_ID_LEN = 18 28 | ### 交易所交易员代码字符串长度 29 | XTP_BRANCH_PBU_LEN = 7 30 | ### 用户资金账户的字符串长度 31 | XTP_ACCOUNT_NAME_LEN = 16 32 | 33 | ######################################################################### 34 | ###@brief XTP_LOG_LEVEL是日志输出级别类型 35 | ######################################################################### 36 | typedefDict["XTP_LOG_LEVEL"] = "enum" 37 | 38 | ######################################################################### 39 | ###@brief XTP_PROTOCOL_TYPE是通讯传输协议方式 40 | ######################################################################### 41 | typedefDict["XTP_PROTOCOL_TYPE"] = "enum" 42 | 43 | 44 | 45 | ######################################################################### 46 | ###@brief XTP_EXCHANGE_TYPE是交易所类型 47 | ######################################################################### 48 | typedefDict["XTP_EXCHANGE_TYPE"] = "enum" 49 | 50 | ########################################################################## 51 | ###@brief XTP_MARKET_TYPE市场类型 52 | ########################################################################## 53 | typedefDict["XTP_MARKET_TYPE"] = "enum" 54 | 55 | 56 | ######################################################################### 57 | ###@brief XTP_PRICE_TYPE是价格类型 58 | ######################################################################### 59 | typedefDict["XTP_PRICE_TYPE"] = "enum" 60 | 61 | 62 | 63 | ######################################################################### 64 | ###@brief XTP_SIDE_TYPE是买卖方向类型 65 | ######################################################################### 66 | typedefDict["XTP_SIDE_TYPE"] = "enum" 67 | 68 | ######################################################################### 69 | ###@brief XTP_ORDER_ACTION_STATUS_TYPE是报单操作状态类型 70 | ######################################################################### 71 | typedefDict["XTP_ORDER_ACTION_STATUS_TYPE"] = "enum" 72 | 73 | ######################################################################### 74 | ###@brief XTP_ORDER_STATUS_TYPE是报单状态类型 75 | ######################################################################### 76 | typedefDict["XTP_ORDER_STATUS_TYPE"] = "enum" 77 | 78 | ######################################################################### 79 | ###@brief XTP_ORDER_SUBMIT_STATUS_TYPE是报单提交状态类型 80 | ######################################################################### 81 | typedefDict["XTP_ORDER_SUBMIT_STATUS_TYPE"] = "enum" 82 | 83 | 84 | ######################################################################### 85 | ###@brief XTP_TE_RESUME_TYPE是公有流(订单响应、成交回报)重传方式 86 | ######################################################################### 87 | typedefDict["XTP_TE_RESUME_TYPE"] = "enum" 88 | 89 | 90 | ########################################################################## 91 | ###@brief ETF_REPLACE_TYPE现金替代标识定义 92 | ########################################################################## 93 | typedefDict["ETF_REPLACE_TYPE"] = "enum" 94 | 95 | 96 | ########################################################################## 97 | ###@brief XTP_TICKER_TYPE证券类型 98 | ########################################################################## 99 | typedefDict["XTP_TICKER_TYPE"] = "enum" 100 | 101 | ########################################################################## 102 | ###@brief XTP_BUSINESS_TYPE证券业务类型 103 | ########################################################################## 104 | typedefDict["XTP_BUSINESS_TYPE"] = "enum" 105 | 106 | 107 | ########################################################################## 108 | ###@brief XTP_ACCOUNT_TYPE账户类型 109 | ########################################################################## 110 | typedefDict["XTP_ACCOUNT_TYPE"] = "enum" 111 | 112 | 113 | ######################################################################### 114 | ###@brief XTP_FUND_TRANSFER_TYPE是资金流转方向类型 115 | ######################################################################### 116 | typedefDict["XTP_FUND_TRANSFER_TYPE"] = "enum" 117 | 118 | ######################################################################### 119 | ###@brief XTP_FUND_OPER_STATUS柜台资金操作结果 120 | ######################################################################### 121 | typedefDict["XTP_FUND_OPER_STATUS"] = "enum" 122 | 123 | ######################################################################### 124 | ###@brief XTP_SPLIT_MERGE_STATUS是一个基金当天拆分合并状态类型 125 | ######################################################################### 126 | typedefDict["XTP_SPLIT_MERGE_STATUS"] = "enum" 127 | 128 | ######################################################################### 129 | ###@brief XTP_TBT_TYPE是一个逐笔回报类型 130 | ######################################################################### 131 | typedefDict["XTP_TBT_TYPE"] = "enum" 132 | 133 | ######################################################################### 134 | ###TXTPTradeTypeType是成交类型类型 135 | ######################################################################### 136 | typedefDict["TXTPTradeTypeType"] = "char" 137 | 138 | ###普通成交 139 | XTP_TRDT_COMMON = '0' 140 | ###现金替代 141 | XTP_TRDT_CASH = '1' 142 | ###一级市场成交 143 | XTP_TRDT_PRIMARY = '2' 144 | 145 | 146 | ######################################################################### 147 | ###TXTPOrderTypeType是报单类型类型 148 | ######################################################################### 149 | typedefDict["TXTPOrderTypeType"] = "char" 150 | 151 | ###正常 152 | XTP_ORDT_Normal = '0' 153 | ###报价衍生 154 | XTP_ORDT_DeriveFromQuote = '1' 155 | ###组合衍生 156 | XTP_ORDT_DeriveFromCombination = '2' 157 | ###组合报单 158 | XTP_ORDT_Combination = '3' 159 | ###条件单 160 | XTP_ORDT_ConditionalOrder = '4' 161 | ###互换单 162 | XTP_ORDT_Swap = '5' 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xoms_api_fund_struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xoms_api_fund_struct.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xoms_api_struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xoms_api_struct.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xquote_api_struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xquote_api_struct.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_data_type.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_data_type.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_struct.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_struct_common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xtp_api_struct_common.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xtp_quote_api.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xtp_quote_api.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/include/xtp_trader_api.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/include/xtp_trader_api.h -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/linux/libsodium.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/linux/libsodium.so -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/linux/libsodium.so.18: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/linux/libsodium.so.18 -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/linux/libxtpquoteapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/linux/libxtpquoteapi.so -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/linux/libxtptraderapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/linux/libxtptraderapi.so -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win32/dll/libsodium.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win32/dll/libsodium.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtpquoteapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtpquoteapi.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtpquoteapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtpquoteapi.lib -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtptraderapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtptraderapi.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtptraderapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win32/dll/xtptraderapi.lib -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win64/dll/libsodium.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win64/dll/libsodium.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtpquoteapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtpquoteapi.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtpquoteapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtpquoteapi.lib -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtptraderapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtptraderapi.dll -------------------------------------------------------------------------------- /vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtptraderapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7starsea/vnpy3/8f8fe1ab9b3b0a8c55fc7e26b003aa26a25e95b6/vnpy/api/xtp/xtpapi-1.1.16/win64/dll/xtptraderapi.lib -------------------------------------------------------------------------------- /vnpy/cmake/configuration.cmake: -------------------------------------------------------------------------------- 1 | # # Set path for boost and python 2 | set(BOOST_ROOT "C:/Boost") 3 | set(PYTHON_INCLUDE_DIR "F:/Anaconda3/include") 4 | 5 | -------------------------------------------------------------------------------- /vnpy/cmake/vnpy3common.cmake: -------------------------------------------------------------------------------- 1 | 2 | macro(init_compiler_system) 3 | if(WIN32) 4 | if(CMAKE_CONFIGURATION_TYPES) 5 | set(CMAKE_CONFIGURATION_TYPES Debug Release) 6 | endif() 7 | 8 | message(status "Setting MSVC flags") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX- /D UNICODE") 10 | add_definitions(-D_SCL_SECURE_NO_WARNINGS) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif(WIN32) 13 | 14 | if(UNIX) 15 | add_definitions(-Wall) 16 | add_definitions(-fPIC) 17 | include(CheckCXXCompilerFlag) 18 | CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVING_COMPILER_SUPPORTS_CXX11) 19 | if(HAVING_COMPILER_SUPPORTS_CXX11) 20 | add_definitions(-std=c++11) 21 | else(HAVING_COMPILER_SUPPORTS_CXX11) 22 | CHECK_CXX_COMPILER_FLAG(-std=c++0x HAVING_COMPILER_SUPPORTS_CXX0X) 23 | if(HAVING_COMPILER_SUPPORTS_CXX0X) 24 | add_definitions(-std=c++0x) 25 | else(HAVING_COMPILER_SUPPORTS_CXX0X) 26 | message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") 27 | endif(HAVING_COMPILER_SUPPORTS_CXX0X) 28 | endif(HAVING_COMPILER_SUPPORTS_CXX11) 29 | endif(UNIX) 30 | 31 | endmacro(init_compiler_system) 32 | 33 | 34 | macro(init_pthread_rt) 35 | if(UNIX) 36 | # if(CMAKE_USE_PTHREADS_INIT) 37 | set(CMAKE_USE_PTHREADS_INIT -lpthread) 38 | include(CheckLibraryExists) 39 | CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVING_REALTIME_LIB) 40 | IF(HAVING_REALTIME_LIB) 41 | LIST(APPEND CMAKE_USE_PTHREADS_INIT -lrt) 42 | ENDIF(HAVING_REALTIME_LIB) 43 | # ENDIF(CMAKE_USE_PTHREADS_INIT) 44 | endif(UNIX) 45 | endmacro(init_pthread_rt) -------------------------------------------------------------------------------- /vnpy/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set cmake="F:\Program Files (x86)\CMake\bin\cmake.exe" 3 | 4 | if not exist build mkdir build 5 | cd build 6 | %cmake% .. 7 | 8 | REM %cmake% --build . --target ALL_BUILD --config Debug 9 | %cmake% --build . --target ALL_BUILD --config Release 10 | 11 | cd .. 12 | ::rmdir /S /Q build 13 | 14 | 15 | pause -------------------------------------------------------------------------------- /vnpy/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cmake_make(){ 4 | cmake_source_dir=$1 5 | cmake_release_flag=$2 6 | cmake_debug_flag=$3 7 | 8 | cmake=`which cmake` 9 | if [ -z $cmake ] 10 | then 11 | echo "cmake does not exist!" 12 | exit -1 13 | fi 14 | if [ $cmake_release_flag == 1 ] 15 | then 16 | [ -d release ] || mkdir release 17 | cd release 18 | $cmake -DCMAKE_BUILD_TYPE=Release $cmake_source_dir 19 | make 20 | cd .. 21 | fi 22 | 23 | if [ $cmake_debug_flag == 2 ] 24 | then 25 | [ -d debug ] || mkdir debug 26 | cd debug 27 | $cmake -DCMAKE_BUILD_TYPE=Debug $cmake_source_dir 28 | make 29 | cd .. 30 | fi 31 | } 32 | 33 | debug_flag=0 34 | release_flag=1 35 | vnpy_api_xtp_dir=`pwd` 36 | [ -d build ] || mkdir build 37 | cd build 38 | cmake_make $vnpy_api_xtp_dir $release_flag $debug_flag 39 | cd .. 40 | 41 | 42 | 43 | --------------------------------------------------------------------------------