From 20f0118a776f5b32d85df08cbf23540916eb9b20 Mon Sep 17 00:00:00 2001 From: vnpy Date: Fri, 13 May 2016 23:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.ctp/CMakeLists.txt | 21 ++++++++++++++++++--- vn.trader/dataRecorder/drEngine.py | 28 ++++++++++++++++++---------- vn.trader/sgitGateway/sgitGateway.py | 2 +- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/vn.ctp/CMakeLists.txt b/vn.ctp/CMakeLists.txt index ed2a498a..c024981b 100644 --- a/vn.ctp/CMakeLists.txt +++ b/vn.ctp/CMakeLists.txt @@ -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,9 +37,11 @@ find_library(CTPAPI_TD_LIBRARY NAMES thosttraderapi PATHS ${CTPAPI_PATH}) + +# 设置编译源文件 set (vnctpmd ) set (vnctptd ) - + option(BUILD_CTP_MD "build ctp md" ON) if (BUILD_CTP_MD) add_definitions(-DBUILD_CTP_MD) @@ -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() +# 去掉生成的so文件名中前缀的lib +set_target_properties(vnctpmd PROPERTIES PREFIX "") + +# 链接生成.so文件 target_link_libraries(vnctpmd ${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 ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY}) set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll) if (EXISTS ${TD_DLL}) diff --git a/vn.trader/dataRecorder/drEngine.py b/vn.trader/dataRecorder/drEngine.py index 7a7f35ae..fe3ba433 100644 --- a/vn.trader/dataRecorder/drEngine.py +++ b/vn.trader/dataRecorder/drEngine.py @@ -62,15 +62,15 @@ 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] # 针对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() diff --git a/vn.trader/sgitGateway/sgitGateway.py b/vn.trader/sgitGateway/sgitGateway.py index defe0bb0..8ab1b22b 100644 --- a/vn.trader/sgitGateway/sgitGateway.py +++ b/vn.trader/sgitGateway/sgitGateway.py @@ -909,7 +909,7 @@ class SgitTdApi(TdApi): pos.frozen = data['ShortFrozen'] # 持仓量 - pos.position = data['Position'] + pos.position = data['TodayPosition'] pos.ydPosition = data['YdPosition'] # 持仓均价