修复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) cmake_minimum_required(VERSION 2.8)
project(vn_ctp_api) project(vn_ctp_api)
# 使
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
if (CMAKE_COMPILER_IS_GNUC OR CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11")
endif () endif ()
#
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
# 使64
option(USE_64BITS "comiple 64bits" ON) option(USE_64BITS "comiple 64bits" ON)
if (USE_64BITS) if (USE_64BITS)
add_definitions(-DUSE_64BITS) add_definitions(-DUSE_64BITS)
@ -16,6 +19,7 @@ if (USE_64BITS)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif() endif()
# C++ API
if (WIN32) if (WIN32)
set(CTPAPI_PATH ctpapi) set(CTPAPI_PATH ctpapi)
elseif (UNIX) elseif (UNIX)
@ -33,6 +37,8 @@ find_library(CTPAPI_TD_LIBRARY
NAMES thosttraderapi NAMES thosttraderapi
PATHS ${CTPAPI_PATH}) PATHS ${CTPAPI_PATH})
#
set (vnctpmd ) set (vnctpmd )
set (vnctptd ) set (vnctptd )
@ -46,14 +52,14 @@ if (BUILD_CTP_MD)
endif() endif()
option(BUILD_CTP_TD "build ctp td" ON) option(BUILD_CTP_TD "build ctp td" ON)
if (BUILD_CTP_TD) if (BUILD_CTP_TD)
add_definitions(-DBUILD_CTP_MD) add_definitions(-DBUILD_CTP_TD)
set(CTP_TD_PATH vnctptd/vnctptd) set(CTP_TD_PATH vnctptd/vnctptd)
include_directories(CTP_TD_PATH) include_directories(CTP_TD_PATH)
set(VN_CTP_TD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctptd/vnctptd/vnctptd.cpp) set(VN_CTP_TD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctptd/vnctptd/vnctptd.cpp)
add_library(vnctptd SHARED ${VN_CTP_TD_SOURCE}) add_library(vnctptd SHARED ${VN_CTP_TD_SOURCE})
endif() endif()
# Python
set(PYTHON_LIBRARY ) set(PYTHON_LIBRARY )
if (WIN32) if (WIN32)
set(PYTHON_INCLUDE_PATH C:/Python27/include) set(PYTHON_INCLUDE_PATH C:/Python27/include)
@ -79,11 +85,20 @@ if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
endif() endif()
# solib
set_target_properties(vnctpmd PROPERTIES PREFIX "")
# .so
target_link_libraries(vnctpmd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY}) target_link_libraries(vnctpmd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY})
# dllpydwindows
set(MD_DLL "${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.dll") set(MD_DLL "${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.dll")
if (EXISTS ${MD_DLL}) if (EXISTS ${MD_DLL})
file(RENAME ${MD_DLL} ${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.pyd) file(RENAME ${MD_DLL} ${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.pyd)
endif() endif()
# MD
set_target_properties(vnctptd PROPERTIES PREFIX "")
target_link_libraries(vnctptd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY}) target_link_libraries(vnctptd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY})
set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll) set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll)
if (EXISTS ${TD_DLL}) if (EXISTS ${TD_DLL})

View File

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

View File

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