修改了部分主引擎的对外API函数

This commit is contained in:
WOLF 2015-12-30 22:01:17 +08:00
parent e7808df556
commit 52bc6fd441
12 changed files with 145 additions and 119 deletions

View File

@ -19,11 +19,10 @@ class CtaEngine(object):
settingFileName = 'CTA_setting.json'
#----------------------------------------------------------------------
def __init__(self, mainEngine, eventEngine, dataEngine):
def __init__(self, mainEngine, eventEngine):
"""Constructor"""
self.mainEngine = mainEngine
self.eventEngine = eventEngine
self.dataEngine = dataEngine
# 保存策略对象的字典
# key为策略名称value为策略对象注意策略名称不允许重复
@ -53,7 +52,7 @@ class CtaEngine(object):
#----------------------------------------------------------------------
def sendOrder(self, vtSymbol, orderType, price, volume, strategy):
"""发单"""
contract = self.dataEngine.getContract(vtSymbol)
contract = self.mainEngine.getContract(vtSymbol)
req = VtOrderReq()
req.symbol = contract.symbol
@ -86,7 +85,7 @@ class CtaEngine(object):
def cancelOrder(self, vtOrderID):
"""撤单"""
# 查询报单对象
order = self.dataEngine.getOrder(vtOrderID)
order = self.mainEngine.getOrder(vtOrderID)
# 如果查询成功
if order:
@ -282,7 +281,7 @@ class CtaEngine(object):
l.append(strategy)
# 订阅合约
contract = self.dataEngine.getContract(strategy.vtSymbol)
contract = self.mainEngine.getContract(strategy.vtSymbol)
if contract:
req = VtSubscribeReq()
req.symbol = contract.symbol

View File

@ -129,14 +129,14 @@ class CtpGateway(VtGateway):
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
self.tdApi.getAccount()
self.tdApi.qryAccount()
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.tdApi.getPosition()
self.tdApi.qryPosition()
#----------------------------------------------------------------------
def close(self):
@ -151,7 +151,7 @@ class CtpGateway(VtGateway):
"""初始化连续查询"""
if self.qryEnabled:
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryFunctionList = [self.qryAccount, self.qryPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点
@ -1214,13 +1214,13 @@ class CtpTdApi(TdApi):
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户"""
self.reqID += 1
self.reqQryTradingAccount({}, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.reqID += 1
req = {}

View File

@ -127,14 +127,14 @@ class FemasGateway(VtGateway):
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
self.tdApi.getAccount()
self.tdApi.qryAccount()
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.tdApi.getPosition()
self.tdApi.qryPosition()
#----------------------------------------------------------------------
def close(self):
@ -149,7 +149,7 @@ class FemasGateway(VtGateway):
"""初始化连续查询"""
if self.qryEnabled:
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryFunctionList = [self.qryAccount, self.qryPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点
@ -478,7 +478,7 @@ class FemasTdApi(TdApi):
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户"""
self.reqID += 1
req = {}
@ -487,7 +487,7 @@ class FemasTdApi(TdApi):
self.reqQryInvestorAccount(req, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.reqID += 1
req = {}

View File

@ -6,7 +6,7 @@ ibpy的gateway接入
注意事项
1. ib api只能获取和操作当前连接后下的单并且每次重启程序后之前下的单子收不到
2. ib api的成交也只会推送当前连接后的成交
3. ib api的持仓和账户更新可以订阅成主推模式因此getAccount和getPosition就用不到了
3. ib api的持仓和账户更新可以订阅成主推模式因此qryAccount和qryPosition就用不到了
4. 目前只支持股票和期货交易ib api里期权合约的确定是基于Contract对象的多个字段比较复杂暂时没做
5. 海外市场的交易规则和国内有很多细节上的不同所以一些字段类型的映射可能不合理如果发现问题欢迎指出
'''
@ -230,7 +230,7 @@ class IbGateway(VtGateway):
self.connection.cancelOrder(cancelOrderReq.orderID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
log = VtLogData()
log.gatewayName = self.gatewayName
@ -238,7 +238,7 @@ class IbGateway(VtGateway):
self.onLog(log)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -15,12 +15,6 @@ from vnksgoldtd import TdApi
from ksgoldDataType import *
from vtGateway import *
# 价格类型映射
#priceTypeMap = {}
#priceTypeMap[PRICETYPE_LIMITPRICE] = defineDict["THOST_FTDC_OPT_LimitPrice"]
#priceTypeMap[PRICETYPE_MARKETPRICE] = defineDict["THOST_FTDC_OPT_AnyPrice"]
#priceTypeMapReverse = {v: k for k, v in priceTypeMap.items()}
# 以下类型映射参考的是原生API里的Constant.h
# 方向类型映射
@ -103,14 +97,14 @@ class KsgoldGateway(VtGateway):
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
self.tdApi.getAccount()
self.tdApi.qryAccount()
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.tdApi.getPosition()
self.tdApi.qryPosition()
#----------------------------------------------------------------------
def close(self):
@ -124,7 +118,7 @@ class KsgoldGateway(VtGateway):
def initQuery(self):
"""初始化连续查询"""
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryFunctionList = [self.qryAccount, self.qryPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点
@ -696,13 +690,13 @@ class KsgoldTdApi(TdApi):
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户"""
self.reqID += 1
self.reqQryTradingAccount({}, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.reqID += 1
self.reqQryInvestorPosition({}, self.reqID)

View File

@ -123,14 +123,14 @@ class KsotpGateway(VtGateway):
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
self.tdApi.getAccount()
self.tdApi.qryAccount()
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.tdApi.getPosition()
self.tdApi.qryPosition()
#----------------------------------------------------------------------
def close(self):
@ -145,7 +145,7 @@ class KsotpGateway(VtGateway):
"""初始化连续查询"""
if self.qryEnabled:
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryFunctionList = [self.qryAccount, self.qryPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点,金仕达接口查询非常慢,因此不适合频繁查询
@ -1169,7 +1169,7 @@ class KsotpTdApi(TdApi):
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户"""
self.reqID += 1
req = {}
@ -1178,7 +1178,7 @@ class KsotpTdApi(TdApi):
self.reqQryTradingAccount(req, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.reqID += 1
req = {}

View File

@ -130,14 +130,14 @@ class LtsGateway(VtGateway):
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
self.qryApi.getAccount()
self.qryApi.qryAccount()
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.qryApi.getPosition()
self.qryApi.qryPosition()
#----------------------------------------------------------------------
def close(self):
@ -154,7 +154,7 @@ class LtsGateway(VtGateway):
"""初始化连续查询"""
if self.qryEnabled:
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryFunctionList = [self.qryAccount, self.qryPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点
@ -1227,7 +1227,7 @@ class LtsQryApi(QryApi):
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户"""
self.reqID += 1
#是否需要INVESTERID, BROKERID?
@ -1237,7 +1237,7 @@ class LtsQryApi(QryApi):
self.reqQryTradingAccount(req, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
self.reqID += 1
req = {}

View File

@ -17,7 +17,7 @@ class BasicCell(QtGui.QTableWidgetItem):
"""基础的单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None):
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(BasicCell, self).__init__()
self.data = None
@ -38,7 +38,7 @@ class DirectionCell(QtGui.QTableWidgetItem):
"""用来显示买卖方向的单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None):
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(DirectionCell, self).__init__()
self.data = None
@ -57,35 +57,43 @@ class DirectionCell(QtGui.QTableWidgetItem):
########################################################################
class NameCell(QtGui.QTableWidgetItem):
"""用来显示合约中文的单元格"""
dataEngine = None
"""用来显示合约中文名的单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None, dataEngine=None):
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(NameCell, self).__init__()
self.data = None
if text:
self.setContent(text)
#----------------------------------------------------------------------
@staticmethod
def setDataEngine(self, dataEngine):
"""设置读取合约用的数据引擎对象"""
self.dataEngine = dataEngine
def setContent(self, text):
"""设置内容"""
self.setText(text)
########################################################################
class NameCell(QtGui.QTableWidgetItem):
"""用来显示合约中文的单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(NameCell, self).__init__()
self.mainEngine = mainEngine
self.data = None
if text:
self.setContent(text)
#----------------------------------------------------------------------
def setContent(self, text):
"""设置内容"""
if self.dataEngine:
if self.mainEngine:
# 首先尝试正常获取合约对象
contract = self.dataEngine.getContract(text)
# 如果交易所代码为UNKNOWN则删除交易所代码部分后再试
if EXCHANGE_UNKNOWN in text:
i = text.index('.')
symbol = text[:i]
contract = self.dataEngine.getContract(symbol)
contract = self.mainEngine.getContract(text)
# 如果能读取合约信息
if contract:
@ -97,7 +105,7 @@ class BidCell(QtGui.QTableWidgetItem):
"""买价单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None):
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(BidCell, self).__init__()
self.data = None
@ -118,7 +126,7 @@ class AskCell(QtGui.QTableWidgetItem):
"""买价单元格"""
#----------------------------------------------------------------------
def __init__(self, text=None):
def __init__(self, text=None, mainEngine=None):
"""Constructor"""
super(AskCell, self).__init__()
self.data = None
@ -146,10 +154,11 @@ class BasicMonitor(QtGui.QTableWidget):
signal = QtCore.pyqtSignal(type(Event()))
#----------------------------------------------------------------------
def __init__(self, eventEngine=None, parent=None):
def __init__(self, mainEngine=None, eventEngine=None, parent=None):
"""Constructor"""
super(BasicMonitor, self).__init__(parent)
self.mainEngine = mainEngine
self.eventEngine = eventEngine
# 保存表头标签用
@ -250,7 +259,7 @@ class BasicMonitor(QtGui.QTableWidget):
for n, header in enumerate(self.headerList):
content = safeUnicode(data.__getattribute__(header))
cellType = self.headerDict[header]['cellType']
cell = cellType(content)
cell = cellType(content, self.mainEngine)
if self.font:
cell.setFont(self.font) # 如果设置了特殊字体,则进行单元格设置
@ -267,7 +276,7 @@ class BasicMonitor(QtGui.QTableWidget):
for header in self.headerList:
content = safeUnicode(data.__getattribute__(header))
cell = d[header]
cell.setContent(content)
cell.setContent(content, self.mainEngine)
if self.saveData: # 如果设置了保存数据对象,则进行对象保存
cell.data = data
@ -277,7 +286,7 @@ class BasicMonitor(QtGui.QTableWidget):
for n, header in enumerate(self.headerList):
content = safeUnicode(data.__getattribute__(header))
cellType = self.headerDict[header]['cellType']
cell = cellType(content)
cell = cellType(content, self.mainEngine)
if self.font:
cell.setFont(self.font)
@ -311,9 +320,9 @@ class MarketMonitor(BasicMonitor):
"""市场监控组件"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(MarketMonitor, self).__init__(eventEngine, parent)
super(MarketMonitor, self).__init__(mainEngine, eventEngine, parent)
# 设置表头有序字典
d = OrderedDict()
@ -357,9 +366,9 @@ class LogMonitor(BasicMonitor):
"""日志监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(LogMonitor, self).__init__(eventEngine, parent)
super(LogMonitor, self).__init__(mainEngine, eventEngine, parent)
d = OrderedDict()
d['logTime'] = {'chinese':u'时间', 'cellType':BasicCell}
@ -378,9 +387,9 @@ class ErrorMonitor(BasicMonitor):
"""错误监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(ErrorMonitor, self).__init__(eventEngine, parent)
super(ErrorMonitor, self).__init__(mainEngine, eventEngine, parent)
d = OrderedDict()
d['errorID'] = {'chinese':u'错误代码', 'cellType':BasicCell}
@ -400,9 +409,9 @@ class TradeMonitor(BasicMonitor):
"""成交监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(TradeMonitor, self).__init__(eventEngine, parent)
super(TradeMonitor, self).__init__(mainEngine, eventEngine, parent)
d = OrderedDict()
d['tradeID'] = {'chinese':u'成交编号', 'cellType':BasicCell}
@ -428,9 +437,9 @@ class OrderMonitor(BasicMonitor):
"""委托监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, mainEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(OrderMonitor, self).__init__(eventEngine, parent)
super(OrderMonitor, self).__init__(mainEngine, eventEngine, parent)
self.mainEngine = mainEngine
@ -486,9 +495,9 @@ class PositionMonitor(BasicMonitor):
"""持仓监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(PositionMonitor, self).__init__(eventEngine, parent)
super(PositionMonitor, self).__init__(mainEngine, eventEngine, parent)
d = OrderedDict()
d['symbol'] = {'chinese':u'合约代码', 'cellType':BasicCell}
@ -513,9 +522,9 @@ class AccountMonitor(BasicMonitor):
"""账户监控"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(AccountMonitor, self).__init__(eventEngine, parent)
super(AccountMonitor, self).__init__(mainEngine, eventEngine, parent)
d = OrderedDict()
d['accountID'] = {'chinese':u'账户', 'cellType':BasicCell}
@ -561,6 +570,7 @@ class TradingWidget(QtGui.QFrame):
EXCHANGE_CZCE,
EXCHANGE_SSE,
EXCHANGE_SZSE,
EXCHANGE_SGE,
EXCHANGE_SMART,
EXCHANGE_GLOBEX,
EXCHANGE_IDEALPRO]
@ -576,12 +586,11 @@ class TradingWidget(QtGui.QFrame):
gatewayList = ['']
#----------------------------------------------------------------------
def __init__(self, mainEngine, eventEngine, dataEngine, parent=None):
def __init__(self, mainEngine, eventEngine, parent=None):
"""Constructor"""
super(TradingWidget, self).__init__(parent)
self.mainEngine = mainEngine
self.eventEngine = eventEngine
self.dataEngine = dataEngine
self.symbol = ''
@ -788,10 +797,10 @@ class TradingWidget(QtGui.QFrame):
# 查询合约
if exchange:
vtSymbol = '.'.join([symbol, exchange])
contract = self.dataEngine.getContract(vtSymbol)
contract = self.mainEngine.getContract(vtSymbol)
else:
vtSymbol = symbol
contract = self.dataEngine.getContract(symbol)
contract = self.mainEngine.getContract(symbol)
if contract:
vtSymbol = contract.vtSymbol
@ -925,7 +934,7 @@ class TradingWidget(QtGui.QFrame):
#----------------------------------------------------------------------
def cancelAll(self):
"""一键撤销所有委托"""
l = self.dataEngine.getAllWorkingOrders()
l = self.mainEngine.getAllWorkingOrders()
for order in l:
req = VtCancelOrderReq()
req.symbol = order.symbol
@ -941,11 +950,11 @@ class ContractMonitor(BasicMonitor):
"""合约查询"""
#----------------------------------------------------------------------
def __init__(self, dataEngine, parent=None):
def __init__(self, mainEngine, parent=None):
"""Constructor"""
super(ContractMonitor, self).__init__(parent=parent)
self.dataEngine = dataEngine
self.mainEngine = mainEngine
d = OrderedDict()
d['symbol'] = {'chinese':u'合约代码', 'cellType':BasicCell}
@ -974,7 +983,7 @@ class ContractMonitor(BasicMonitor):
#----------------------------------------------------------------------
def showAllContracts(self):
"""显示所有合约数据"""
l = self.dataEngine.getAllContracts()
l = self.mainEngine.getAllContracts()
d = {'.'.join([contract.exchange, contract.symbol]):contract for contract in l}
l2 = d.keys()
l2.sort(reverse=True)

View File

@ -11,13 +11,12 @@ class MainWindow(QtGui.QMainWindow):
"""主窗口"""
#----------------------------------------------------------------------
def __init__(self, mainEngine, eventEngine, dataEngine):
def __init__(self, mainEngine, eventEngine):
"""Constructor"""
super(MainWindow, self).__init__()
self.mainEngine = mainEngine
self.eventEngine = eventEngine
self.dataEngine = dataEngine
self.widgetDict = {} # 用来保存子窗口的字典
@ -34,15 +33,15 @@ class MainWindow(QtGui.QMainWindow):
#----------------------------------------------------------------------
def initCentral(self):
"""初始化中心区域"""
marketM = MarketMonitor(self.eventEngine)
logM = LogMonitor(self.eventEngine)
errorM = ErrorMonitor(self.eventEngine)
tradeM = TradeMonitor(self.eventEngine)
orderM = OrderMonitor(self.eventEngine, self.mainEngine)
positionM = PositionMonitor(self.eventEngine)
accountM = AccountMonitor(self.eventEngine)
marketM = MarketMonitor(self.mainEngine, self.eventEngine)
logM = LogMonitor(self.mainEngine, self.eventEngine)
errorM = ErrorMonitor(self.mainEngine, self.eventEngine)
tradeM = TradeMonitor(self.mainEngine, self.eventEngine)
orderM = OrderMonitor(self.mainEngine, self.eventEngine)
positionM = PositionMonitor(self.mainEngine, self.eventEngine)
accountM = AccountMonitor(self.mainEngine, self.eventEngine)
tradingW = TradingWidget(self.mainEngine, self.mainEngine.eventEngine, self.mainEngine.dataEngine)
tradingW = TradingWidget(self.mainEngine, self.eventEngine)
leftTab = QtGui.QTabWidget()
leftTab.addTab(logM, u'日志')
@ -226,7 +225,7 @@ class MainWindow(QtGui.QMainWindow):
try:
self.widgetDict['contractM'].show()
except KeyError:
self.widgetDict['contractM'] = ContractMonitor(self.mainEngine.dataEngine)
self.widgetDict['contractM'] = ContractMonitor(self.mainEngine)
self.widgetDict['contractM'].show()
#----------------------------------------------------------------------

View File

@ -25,8 +25,19 @@ class MainEngine(object):
# 创建数据引擎
self.dataEngine = DataEngine(self.eventEngine)
uiBasicWidget.NameCell.setDataEngine(uiBasicWidget.NameCell, self.dataEngine) # 将数据引擎对象传给NameCell
# MongoDB数据库相关
self.dbClient = None # MongoDB客户端对象
# CTA引擎
self.ctaEngine = CtaEngine(self, self.eventEngine)
# 调用一个个初始化函数
self.initGateway()
#----------------------------------------------------------------------
def initGateway(self):
"""初始化接口对象"""
# 用来保存接口对象的字典
self.gatewayDict = OrderedDict()
@ -77,12 +88,6 @@ class MainEngine(object):
self.addGateway(IbGateway, 'IB')
except Exception, e:
print e
# MongoDB数据库相关
self.dbClient = None # MongoDB客户端对象
# CTA引擎
self.ctaEngine = CtaEngine(self, self.eventEngine, self.dataEngine)
#----------------------------------------------------------------------
def addGateway(self, gateway, gatewayName=None):
@ -126,7 +131,7 @@ class MainEngine(object):
self.writeLog(u'接口不存在:%s' %gatewayName)
#----------------------------------------------------------------------
def getAccont(self, gatewayName):
def qryAccont(self, gatewayName):
"""查询特定接口的账户"""
if gatewayName in self.gatewayDict:
gateway = self.gatewayDict[gatewayName]
@ -135,7 +140,7 @@ class MainEngine(object):
self.writeLog(u'接口不存在:%s' %gatewayName)
#----------------------------------------------------------------------
def getPosition(self, gatewayName):
def qryPosition(self, gatewayName):
"""查询特定接口的持仓"""
if gatewayName in self.gatewayDict:
gateway = self.gatewayDict[gatewayName]
@ -193,7 +198,27 @@ class MainEngine(object):
return cursor
else:
return None
#----------------------------------------------------------------------
def getContract(self, vtSymbol):
"""查询合约"""
return self.dataEngine.getContract(vtSymbol)
#----------------------------------------------------------------------
def getAllContracts(self):
"""查询所有合约(返回列表)"""
return self.dataEngine.getAllContracts()
#----------------------------------------------------------------------
def getOrder(self, vtOrderID):
"""查询委托"""
return self.dataEngine.getOrder(vtOrderID)
#----------------------------------------------------------------------
def getAllWorkingOrders(self):
"""查询所有的活跃的委托(返回列表)"""
return self.dataEngine.getAllWorkingOrders()
########################################################################
class DataEngine(object):

View File

@ -127,12 +127,12 @@ class VtGateway(object):
pass
#----------------------------------------------------------------------
def getAccount(self):
def qryAccount(self):
"""查询账户资金"""
pass
#----------------------------------------------------------------------
def getPosition(self):
def qryPosition(self):
"""查询持仓"""
pass

View File

@ -17,7 +17,7 @@ def main():
app.setFont(BASIC_FONT)
mainEngine = MainEngine()
mainWindow = MainWindow(mainEngine, mainEngine.eventEngine, mainEngine.dataEngine)
mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
mainWindow.showMaximized()
sys.exit(app.exec_())