Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxy123 committed May 13, 2016
1 parent 4560507 commit 20f0118
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
21 changes: 18 additions & 3 deletions vn.ctp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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})
Expand Down
28 changes: 18 additions & 10 deletions vn.trader/dataRecorder/drEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def loadSetting(self):

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:
Expand All @@ -79,30 +79,38 @@ def loadSetting(self):

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()
Expand Down
2 changes: 1 addition & 1 deletion vn.trader/sgitGateway/sgitGateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def onRspQryInvestorPosition(self, data, error, n, last):
pos.frozen = data['ShortFrozen']

# 持仓量
pos.position = data['Position']
pos.position = data['TodayPosition']
pos.ydPosition = data['YdPosition']

# 持仓均价
Expand Down

0 comments on commit 20f0118

Please sign in to comment.