修复bug

This commit is contained in:
vnpy 2016-05-13 23:24:10 +08:00
parent 4560507369
commit 20f0118a77
3 changed files with 37 additions and 14 deletions

View File

@ -1,14 +1,17 @@
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)
@ -16,6 +19,7 @@ if (USE_64BITS)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
# C++ API
if (WIN32)
set(CTPAPI_PATH ctpapi)
elseif (UNIX)
@ -33,6 +37,8 @@ find_library(CTPAPI_TD_LIBRARY
NAMES thosttraderapi
PATHS ${CTPAPI_PATH})
#
set (vnctpmd )
set (vnctptd )
@ -46,14 +52,14 @@ if (BUILD_CTP_MD)
endif()
option(BUILD_CTP_TD "build ctp td" ON)
if (BUILD_CTP_TD)
add_definitions(-DBUILD_CTP_MD)
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)
@ -79,11 +85,20 @@ if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
# solib
set_target_properties(vnctpmd PROPERTIES PREFIX "")
# .so
target_link_libraries(vnctpmd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY})
# dllpydwindows
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 ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY})
set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll)
if (EXISTS ${TD_DLL})

View File

@ -62,8 +62,7 @@ class DrEngine(object):
for setting in l:
symbol = setting[0]
drTick = DrTickData() # 该tick实例可以用于缓存部分数据目前未使用
self.tickDict[symbol] = drTick
vtSymbol = symbol
req = VtSubscribeReq()
req.symbol = setting[0]
@ -71,6 +70,7 @@ class DrEngine(object):
# 针对LTS和IB接口订阅行情需要交易所代码
if len(setting)>=3:
req.exchange = setting[2]
vtSymbol = '.'.join([symbol, req.exchange])
# 针对IB接口订阅行情需要货币和产品类型
if len(setting)>=5:
@ -79,30 +79,38 @@ class DrEngine(object):
self.mainEngine.subscribe(req, setting[1])
drTick = DrTickData() # 该tick实例可以用于缓存部分数据目前未使用
self.tickDict[vtSymbol] = drTick
if 'bar' in setting:
l = setting['bar']
for setting in l:
symbol = setting[0]
bar = DrBarData()
self.barDict[symbol] = bar
vtSymbol = symbol
req = VtSubscribeReq()
req.symbol = symbol
if len(setting)>=3:
req.exchange = setting[2]
vtSymbol = '.'.join([symbol, req.exchange])
if len(setting)>=5:
req.currency = setting[3]
req.productClass = setting[4]
req = VtSubscribeReq()
req.symbol = symbol
self.mainEngine.subscribe(req, gatewayName)
self.mainEngine.subscribe(req, setting[1])
bar = DrBarData()
self.barDict[vtSymbol] = bar
if 'active' in setting:
d = setting['active']
for activeSymbol, symbol in d.items():
self.activeSymbolDict[symbol] = activeSymbol
# 注意这里的vtSymbol对于IB和LTS接口应该后缀.交易所
for activeSymbol, vtSymbol in d.items():
self.activeSymbolDict[vtSymbol] = activeSymbol
# 注册事件监听
self.registerEvent()

View File

@ -909,7 +909,7 @@ class SgitTdApi(TdApi):
pos.frozen = data['ShortFrozen']
# 持仓量
pos.position = data['Position']
pos.position = data['TodayPosition']
pos.ydPosition = data['YdPosition']
# 持仓均价