2015-05-21 07:14:20 +00:00
|
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
该文件中包含的是交易平台的底层接口相关的部分,
|
|
|
|
|
主要对API进行了一定程度的简化封装,方便开发。
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from vnctpmd import MdApi
|
|
|
|
|
from vnctptd import TdApi
|
|
|
|
|
from eventEngine import *
|
|
|
|
|
from ctp_data_type import defineDict
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def print_dict(d):
|
|
|
|
|
"""打印API收到的字典,该函数主要用于开发时的debug"""
|
|
|
|
|
print '-'*60
|
|
|
|
|
l = d.keys()
|
|
|
|
|
l.sort()
|
|
|
|
|
for key in l:
|
|
|
|
|
print key, ':', d[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
class DemoMdApi(MdApi):
|
|
|
|
|
"""
|
|
|
|
|
Demo中的行情API封装
|
|
|
|
|
封装后所有数据自动推送到事件驱动引擎中,由其负责推送到各个监听该事件的回调函数上
|
|
|
|
|
|
|
|
|
|
对用户暴露的主动函数包括:
|
|
|
|
|
登陆 login
|
|
|
|
|
订阅合约 subscribe
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def __init__(self, eventEngine):
|
|
|
|
|
"""
|
|
|
|
|
API对象的初始化函数
|
|
|
|
|
"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.__init__() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
super(DemoMdApi, self).__init__()
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.__init__() super success'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 事件引擎,所有数据都推送到其中,再由事件引擎进行分发
|
|
|
|
|
self.__eventEngine = eventEngine
|
|
|
|
|
|
|
|
|
|
# 请求编号,由api负责管理
|
|
|
|
|
self.__reqid = 0
|
|
|
|
|
|
|
|
|
|
# 以下变量用于实现连接和重连后的自动登陆
|
|
|
|
|
self.__userid = ''
|
|
|
|
|
self.__password = ''
|
|
|
|
|
self.__brokerid = ''
|
|
|
|
|
|
|
|
|
|
# 以下集合用于重连后自动订阅之前已订阅的合约,使用集合为了防止重复
|
2015-09-16 07:34:00 +00:00
|
|
|
|
self.__setSubscribed = set()
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 初始化.con文件的保存目录为\mdconnection,注意这个目录必须已存在,否则会报错
|
2015-09-16 07:34:00 +00:00
|
|
|
|
self.createFtdcMdApi(os.getcwd() + '\\mdconnection\\')
|
|
|
|
|
print u'DemoApi.py DemoMdApi.__init__() createFtdcMdApi success'
|
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.__init__() end'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onFrontConnected(self):
|
|
|
|
|
"""服务器连接"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onFrontConnected() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
event.dict_['log'] = u'行情服务器连接成功'
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
# 如果用户已经填入了用户名等等,则自动尝试连接
|
|
|
|
|
if self.__userid:
|
|
|
|
|
req = {}
|
|
|
|
|
req['UserID'] = self.__userid
|
|
|
|
|
req['Password'] = self.__password
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
self.reqUserLogin(req, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.onFrontConnected() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onFrontDisconnected(self, n):
|
|
|
|
|
"""服务器断开"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onFrontDisconnected() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
event.dict_['log'] = u'行情服务器连接断开'
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onFrontDisconnected() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onHeartBeatWarning(self, n):
|
|
|
|
|
"""心跳报警"""
|
|
|
|
|
# 因为API的心跳报警比较常被触发,且与API工作关系不大,因此选择忽略
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onHeartBeatWarning()'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspError(self, error, n, last):
|
|
|
|
|
"""错误回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspError() begin'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'行情错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspError() end'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUserLogin(self, data, error, n, last):
|
|
|
|
|
"""登陆回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUserLogin() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
|
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
log = u'行情服务器登陆成功'
|
|
|
|
|
else:
|
|
|
|
|
log = u'登陆回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
|
|
|
|
|
event.dict_['log'] = log
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
## 重连后自动订阅之前已经订阅过的合约
|
|
|
|
|
#if self.__setSubscribed:
|
|
|
|
|
#for instrument in self.__setSubscribed:
|
|
|
|
|
#self.subscribe(instrument[0], instrument[1])
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
2015-10-07 16:27:06 +00:00
|
|
|
|
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUserLogin() end'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUserLogout(self, data, error, n, last):
|
|
|
|
|
"""登出回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUserLogout() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
|
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
log = u'行情服务器登出成功'
|
|
|
|
|
else:
|
|
|
|
|
log = u'登出回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
|
|
|
|
|
event.dict_['log'] = log
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUserLogout() end'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspSubMarketData(self, data, error, n, last):
|
|
|
|
|
"""订阅合约回报"""
|
|
|
|
|
# 通常不在乎订阅错误,选择忽略
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspSubMarketData()'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUnSubMarketData(self, data, error, n, last):
|
|
|
|
|
"""退订合约回报"""
|
2015-10-07 16:27:06 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUnSubMarketData()'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 同上
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnDepthMarketData(self, data):
|
|
|
|
|
"""行情推送"""
|
|
|
|
|
# 行情推送收到后,同时触发常规行情事件,以及特定合约行情事件,用于满足不同类型的监听
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRtnDepthMarketData() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 常规行情事件
|
|
|
|
|
event1 = Event(type_=EVENT_MARKETDATA)
|
|
|
|
|
event1.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event1)
|
|
|
|
|
|
|
|
|
|
# 特定合约行情事件
|
|
|
|
|
event2 = Event(type_=(EVENT_MARKETDATA_CONTRACT+data['InstrumentID']))
|
|
|
|
|
event2.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event2)
|
|
|
|
|
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRtnDepthMarketData() end'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspSubForQuoteRsp(self, data, error, n, last):
|
|
|
|
|
"""订阅期权询价"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUnSubForQuoteRsp(self, data, error, n, last):
|
|
|
|
|
"""退订期权询价"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRspUnSubForQuoteRsp()'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnForQuoteRsp(self, data):
|
|
|
|
|
"""期权询价推送"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.onRtnForQuoteRsp()'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def login(self, address, userid, password, brokerid):
|
|
|
|
|
"""连接服务器"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.login() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__userid = userid
|
|
|
|
|
self.__password = password
|
|
|
|
|
self.__brokerid = brokerid
|
|
|
|
|
|
|
|
|
|
# 注册服务器地址
|
|
|
|
|
self.registerFront(address)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.login() registerFront success'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 初始化连接,成功会调用onFrontConnected
|
|
|
|
|
self.init()
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoMdApi.login() init() success'
|
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoMdApi.login() end'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def subscribe(self, instrumentid, exchangeid):
|
|
|
|
|
"""订阅合约"""
|
|
|
|
|
self.subscribeMarketData(instrumentid)
|
|
|
|
|
|
|
|
|
|
instrument = (instrumentid, exchangeid)
|
|
|
|
|
self.__setSubscribed.add(instrument)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
class DemoTdApi(TdApi):
|
|
|
|
|
"""
|
|
|
|
|
Demo中的交易API封装
|
|
|
|
|
主动函数包括:
|
|
|
|
|
login 登陆
|
|
|
|
|
getInstrument 查询合约信息
|
|
|
|
|
getAccount 查询账号资金
|
|
|
|
|
getInvestor 查询投资者
|
|
|
|
|
getPosition 查询持仓
|
|
|
|
|
sendOrder 发单
|
|
|
|
|
cancelOrder 撤单
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def __init__(self, eventEngine):
|
|
|
|
|
"""API对象的初始化函数"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.__init__() begin'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
super(DemoTdApi, self).__init__()
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.__init__() call super() success'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 事件引擎,所有数据都推送到其中,再由事件引擎进行分发
|
|
|
|
|
self.__eventEngine = eventEngine
|
|
|
|
|
|
|
|
|
|
# 请求编号,由api负责管理
|
|
|
|
|
self.__reqid = 0
|
|
|
|
|
|
|
|
|
|
# 报单编号,由api负责管理
|
|
|
|
|
self.__orderref = 0
|
|
|
|
|
|
|
|
|
|
# 以下变量用于实现连接和重连后的自动登陆
|
|
|
|
|
self.__userid = ''
|
|
|
|
|
self.__password = ''
|
|
|
|
|
self.__brokerid = ''
|
|
|
|
|
|
|
|
|
|
# 合约字典(保存合约查询数据)
|
|
|
|
|
self.__dictInstrument = {}
|
|
|
|
|
|
|
|
|
|
# 初始化.con文件的保存目录为\tdconnection
|
|
|
|
|
self.createFtdcTraderApi(os.getcwd() + '\\tdconnection\\')
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.__init__() createFtdcTraderApi() success.'
|
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.__init__() end.'
|
|
|
|
|
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onFrontConnected(self):
|
|
|
|
|
"""服务器连接"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onFrontConnected() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
event.dict_['log'] = u'交易服务器连接成功'
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
# 如果用户已经填入了用户名等等,则自动尝试连接
|
|
|
|
|
if self.__userid:
|
|
|
|
|
req = {}
|
|
|
|
|
req['UserID'] = self.__userid
|
|
|
|
|
req['Password'] = self.__password
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
self.reqUserLogin(req, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onFrontConnected() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onFrontDisconnected(self, n):
|
|
|
|
|
"""服务器断开"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onFrontDisconnected() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
event.dict_['log'] = u'交易服务器连接断开'
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onFrontDisconnected() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onHeartBeatWarning(self, n):
|
2015-09-16 07:34:00 +00:00
|
|
|
|
"""心跳"""
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onHeartBeatWarning().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspAuthenticate(self, data, error, n, last):
|
2015-09-16 07:34:00 +00:00
|
|
|
|
"""鉴权"""
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspAuthenticate().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUserLogin(self, data, error, n, last):
|
|
|
|
|
"""登陆回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserLogin() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
|
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
log = u'交易服务器登陆成功'
|
|
|
|
|
else:
|
|
|
|
|
log = u'登陆回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
self.getSettlement() # 登录完成后立即查询结算信息
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserLogin() getSettlement success.'
|
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserLogin() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUserLogout(self, data, error, n, last):
|
|
|
|
|
"""登出回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserLogout() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
|
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
log = u'交易服务器登出成功'
|
|
|
|
|
else:
|
|
|
|
|
log = u'登出回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserLogout() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspUserPasswordUpdate(self, data, error, n, last):
|
2015-09-16 07:34:00 +00:00
|
|
|
|
"""用户登录密码更新事件"""
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspUserPasswordUpdate().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspTradingAccountPasswordUpdate(self, data, error, n, last):
|
2015-09-16 07:34:00 +00:00
|
|
|
|
"""用户交易密码更新事件"""
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspTradingAccountPasswordUpdate().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspOrderInsert(self, data, error, n, last):
|
|
|
|
|
"""发单错误(柜台)"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspOrderInsert() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u' 发单错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspOrderInsert() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspParkedOrderInsert(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspParkedOrderInsert().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspParkedOrderAction(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspParkedOrderInsert().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspOrderAction(self, data, error, n, last):
|
|
|
|
|
"""撤单错误(柜台)"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspOrderAction() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'撤单错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspOrderAction() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQueryMaxOrderVolume(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQueryMaxOrderVolume().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspSettlementInfoConfirm(self, data, error, n, last):
|
|
|
|
|
"""确认结算信息回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspSettlementInfoConfirm() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'结算信息确认完成'
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
event = Event(type_=EVENT_TDLOGIN)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspSettlementInfoConfirm() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspRemoveParkedOrder(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspRemoveParkedOrder().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspRemoveParkedOrderAction(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspRemoveParkedOrderAction().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspExecOrderInsert(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspExecOrderInsert().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspExecOrderAction(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspExecOrderAction().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspForQuoteInsert(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspForQuoteInsert().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQuoteInsert(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQuoteInsert().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQuoteAction(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQuoteAction().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryOrder(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryOrder().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTrade(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTrade().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInvestorPosition(self, data, error, n, last):
|
|
|
|
|
"""持仓查询回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestorPosition() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
event = Event(type_=EVENT_POSITION)
|
|
|
|
|
event.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
else:
|
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'持仓查询回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestorPosition() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTradingAccount(self, data, error, n, last):
|
|
|
|
|
"""资金账户查询回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTradingAccount() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
event = Event(type_=EVENT_ACCOUNT)
|
|
|
|
|
event.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
else:
|
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'账户查询回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTradingAccount() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInvestor(self, data, error, n, last):
|
|
|
|
|
"""投资者查询回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestor() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
event = Event(type_=EVENT_INVESTOR)
|
|
|
|
|
event.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
else:
|
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'合约投资者回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestor() end.'
|
|
|
|
|
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTradingCode(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTradingCode() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInstrumentMarginRate(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInstrumentMarginRate() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInstrumentCommissionRate(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInstrumentCommissionRate() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryExchange(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryExchange() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryProduct(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryProduct() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInstrument(self, data, error, n, last):
|
|
|
|
|
"""
|
|
|
|
|
合约查询回报
|
|
|
|
|
由于该回报的推送速度极快,因此不适合全部存入队列中处理,
|
|
|
|
|
选择先储存在一个本地字典中,全部收集完毕后再推送到队列中
|
|
|
|
|
(由于耗时过长目前使用其他进程读取)
|
|
|
|
|
"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInstrument() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
if error['ErrorID'] == 0:
|
|
|
|
|
event = Event(type_=EVENT_INSTRUMENT)
|
|
|
|
|
event.dict_['data'] = data
|
|
|
|
|
event.dict_['last'] = last
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
else:
|
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'合约投资者回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInstrument() end.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryDepthMarketData(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryDepthMarketData().'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQrySettlementInfo(self, data, error, n, last):
|
|
|
|
|
"""查询结算信息回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQrySettlementInfo() begin.'
|
2015-07-10 00:34:04 +00:00
|
|
|
|
if last:
|
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'结算信息查询完成'
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
|
|
|
|
|
|
|
|
|
self.confirmSettlement() # 查询完成后立即确认结算信息
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQrySettlementInfo() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTransferBank(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTransferBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInvestorPositionDetail(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestorPositionDetail() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryNotice(self, data, error, n, last):
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryNotice() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
""""""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQrySettlementInfoConfirm(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQrySettlementInfoConfirm() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInvestorPositionCombineDetail(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestorPositionCombineDetail() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryCFMMCTradingAccountKey(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryCFMMCTradingAccountKey() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryEWarrantOffset(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryEWarrantOffset() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryInvestorProductGroupMargin(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryInvestorProductGroupMargin() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryExchangeMarginRate(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryExchangeMarginRate() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryExchangeMarginRateAdjust(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryExchangeMarginRateAdjust() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryExchangeRate(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryExchangeRate() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQrySecAgentACIDMap(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQrySecAgentACIDMap() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryOptionInstrTradeCost(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryOptionInstrTradeCost() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryOptionInstrCommRate(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryOptionInstrCommRate() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryExecOrder(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryExecOrder() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryForQuote(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryForQuote() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryQuote(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryQuote() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTransferSerial(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTransferSerial() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryAccountregister(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryAccountregister() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspError(self, error, n, last):
|
|
|
|
|
"""错误回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspError() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'交易错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspError() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnOrder(self, data):
|
|
|
|
|
"""报单回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnOrder() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 更新最大报单编号
|
|
|
|
|
newref = data['OrderRef']
|
|
|
|
|
self.__orderref = max(self.__orderref, int(newref))
|
|
|
|
|
|
|
|
|
|
# 常规报单事件
|
|
|
|
|
event1 = Event(type_=EVENT_ORDER)
|
|
|
|
|
event1.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event1)
|
|
|
|
|
|
|
|
|
|
# 特定合约行情事件
|
|
|
|
|
event2 = Event(type_=(EVENT_ORDER_ORDERREF+data['OrderRef']))
|
|
|
|
|
event2.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event2)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnOrder() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnTrade(self, data):
|
|
|
|
|
"""成交回报"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnTrade() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 常规成交事件
|
|
|
|
|
event1 = Event(type_=EVENT_TRADE)
|
|
|
|
|
event1.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event1)
|
|
|
|
|
|
|
|
|
|
# 特定合约成交事件
|
|
|
|
|
event2 = Event(type_=(EVENT_TRADE_CONTRACT+data['InstrumentID']))
|
|
|
|
|
event2.dict_['data'] = data
|
|
|
|
|
self.__eventEngine.put(event2)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnTrade() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnOrderInsert(self, data, error):
|
|
|
|
|
"""发单错误回报(交易所)"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnOrderInsert() begin.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'发单错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnOrderInsert() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnOrderAction(self, data, error):
|
|
|
|
|
"""撤单错误回报(交易所)"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnOrderAction() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
event = Event(type_=EVENT_LOG)
|
|
|
|
|
log = u'撤单错误回报,错误代码:' + unicode(error['ErrorID']) + u',' + u'错误信息:' + error['ErrorMsg'].decode('gbk')
|
|
|
|
|
event.dict_['log'] = log
|
|
|
|
|
self.__eventEngine.put(event)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnOrderAction() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnInstrumentStatus(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnInstrumentStatus() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnTradingNotice(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnTradingNotice() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnErrorConditionalOrder(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnErrorConditionalOrder() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnExecOrder(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnExecOrder() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnExecOrderInsert(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnExecOrderInsert() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnExecOrderAction(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnExecOrderAction() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnForQuoteInsert(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnForQuoteInsert() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnQuote(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnQuote() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnQuoteInsert(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnQuoteInsert() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnQuoteAction(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnQuoteAction() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnForQuoteRsp(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnForQuoteRsp() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryContractBank(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryContractBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryParkedOrder(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryParkedOrder() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryParkedOrderAction(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryParkedOrderAction() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryTradingNotice(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryTradingNotice() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryBrokerTradingParams(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryBrokerTradingParams() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQryBrokerTradingAlgos(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQryBrokerTradingAlgos() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnFromBankToFutureByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnFromBankToFutureByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnFromFutureToBankByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnFromFutureToBankByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromBankToFutureByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromBankToFutureByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromFutureToBankByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromFutureToBankByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnFromBankToFutureByFuture(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnFromBankToFutureByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnFromFutureToBankByFuture(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnFromFutureToBankByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromBankToFutureByFutureManual(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromBankToFutureByFutureManual() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromFutureToBankByFutureManual(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromFutureToBankByFutureManual() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnQueryBankBalanceByFuture(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnQueryBankBalanceByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnBankToFutureByFuture(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnBankToFutureByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnFutureToBankByFuture(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnFutureToBankByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnRepealBankToFutureByFutureManual(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnRepealBankToFutureByFutureManual() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnRepealFutureToBankByFutureManual(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnRepealFutureToBankByFutureManual() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onErrRtnQueryBankBalanceByFuture(self, data, error):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onErrRtnQueryBankBalanceByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromBankToFutureByFuture(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromBankToFutureByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnRepealFromFutureToBankByFuture(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnRepealFromFutureToBankByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspFromBankToFutureByFuture(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspFromBankToFutureByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspFromFutureToBankByFuture(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspFromFutureToBankByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRspQueryBankAccountMoneyByFuture(self, data, error, n, last):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRspQueryBankAccountMoneyByFuture() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnOpenAccountByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnOpenAccountByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnCancelAccountByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnCancelAccountByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def onRtnChangeAccountByBank(self, data):
|
|
|
|
|
""""""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.onRtnChangeAccountByBank() '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def login(self, address, userid, password, brokerid):
|
|
|
|
|
"""连接服务器"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.login() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__userid = userid
|
|
|
|
|
self.__password = password
|
|
|
|
|
self.__brokerid = brokerid
|
|
|
|
|
|
|
|
|
|
# 数据重传模式设为从本日开始
|
|
|
|
|
self.subscribePrivateTopic(0)
|
|
|
|
|
self.subscribePublicTopic(0)
|
|
|
|
|
|
|
|
|
|
# 注册服务器地址
|
|
|
|
|
self.registerFront(address)
|
|
|
|
|
|
|
|
|
|
# 初始化连接,成功会调用onFrontConnected
|
|
|
|
|
self.init()
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.login() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def getInstrument(self):
|
|
|
|
|
"""查询合约"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getInstrument() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
self.reqQryInstrument({}, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getInstrument() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def getAccount(self):
|
|
|
|
|
"""查询账户"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getAccount() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
self.reqQryTradingAccount({}, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getAccount() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def getInvestor(self):
|
|
|
|
|
"""查询投资者"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getInvestor() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
self.reqQryInvestor({}, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getInvestor() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def getPosition(self):
|
|
|
|
|
"""查询持仓"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getPosition() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
req = {}
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
req['InvestorID'] = self.__userid
|
|
|
|
|
self.reqQryInvestorPosition(req, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.getPosition() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def sendOrder(self, instrumentid, exchangeid, price, pricetype, volume, direction, offset):
|
|
|
|
|
"""发单"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.sendOrder() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
req = {}
|
|
|
|
|
|
|
|
|
|
req['InstrumentID'] = instrumentid
|
|
|
|
|
req['OrderPriceType'] = pricetype
|
|
|
|
|
req['LimitPrice'] = price
|
|
|
|
|
req['VolumeTotalOriginal'] = volume
|
|
|
|
|
req['Direction'] = direction
|
|
|
|
|
req['CombOffsetFlag'] = offset
|
|
|
|
|
|
|
|
|
|
self.__orderref = self.__orderref + 1
|
|
|
|
|
req['OrderRef'] = str(self.__orderref)
|
|
|
|
|
|
|
|
|
|
req['InvestorID'] = self.__userid
|
|
|
|
|
req['UserID'] = self.__userid
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
req['CombHedgeFlag'] = defineDict['THOST_FTDC_HF_Speculation'] # 投机单
|
|
|
|
|
req['ContingentCondition'] = defineDict['THOST_FTDC_CC_Immediately'] # 立即发单
|
|
|
|
|
req['ForceCloseReason'] = defineDict['THOST_FTDC_FCC_NotForceClose'] # 非强平
|
|
|
|
|
req['IsAutoSuspend'] = 0 # 非自动挂起
|
|
|
|
|
req['TimeCondition'] = defineDict['THOST_FTDC_TC_GFD'] # 今日有效
|
|
|
|
|
req['VolumeCondition'] = defineDict['THOST_FTDC_VC_AV'] # 任意成交量
|
|
|
|
|
req['MinVolume'] = 1 # 最小成交量为1
|
|
|
|
|
|
|
|
|
|
self.reqOrderInsert(req, self.__reqid)
|
|
|
|
|
|
2015-09-16 07:34:00 +00:00
|
|
|
|
print u'DemoApi.py DemoTdApi.sendOrder() end.'
|
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
# 返回订单号,便于某些算法进行动态管理
|
|
|
|
|
return self.__orderref
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def cancelOrder(self, instrumentid, exchangeid, orderref, frontid, sessionid):
|
|
|
|
|
"""撤单"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.cancelOrder() begin. '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
req = {}
|
|
|
|
|
|
|
|
|
|
req['InstrumentID'] = instrumentid
|
|
|
|
|
req['ExchangeID'] = exchangeid
|
|
|
|
|
req['OrderRef'] = orderref
|
|
|
|
|
req['FrontID'] = frontid
|
|
|
|
|
req['SessionID'] = sessionid
|
|
|
|
|
|
|
|
|
|
req['ActionFlag'] = defineDict['THOST_FTDC_AF_Delete']
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
req['InvestorID'] = self.__userid
|
|
|
|
|
|
|
|
|
|
self.reqOrderAction(req, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.cancelOrder() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def getSettlement(self):
|
|
|
|
|
"""查询结算信息"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.getSettlement() begin '
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
req = {}
|
|
|
|
|
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
req['InvestorID'] = self.__userid
|
|
|
|
|
|
|
|
|
|
self.reqQrySettlementInfo(req, self.__reqid)
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.getSettlement() end.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def confirmSettlement(self):
|
|
|
|
|
"""确认结算信息"""
|
2015-09-16 07:34:00 +00:00
|
|
|
|
|
|
|
|
|
print u'DemoApi.py DemoTdApi.confirmSettlement() begin.'
|
2015-05-21 07:14:20 +00:00
|
|
|
|
self.__reqid = self.__reqid + 1
|
|
|
|
|
req = {}
|
|
|
|
|
|
|
|
|
|
req['BrokerID'] = self.__brokerid
|
|
|
|
|
req['InvestorID'] = self.__userid
|
|
|
|
|
|
2015-09-16 07:34:00 +00:00
|
|
|
|
self.reqSettlementInfoConfirm(req, self.__reqid)
|
|
|
|
|
print u'DemoApi.py DemoTdApi.confirmSettlement() end.'
|