本文整理汇总了Python中EventEngine.DyEvent.data['broker']方法的典型用法代码示例。如果您正苦于以下问题:Python DyEvent.data['broker']方法的具体用法?Python DyEvent.data['broker']怎么用?Python DyEvent.data['broker']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventEngine.DyEvent
的用法示例。
在下文中一共展示了DyEvent.data['broker']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _stopAccountManager
# 需要导入模块: from EventEngine import DyEvent [as 别名]
# 或者: from EventEngine.DyEvent import data['broker'] [as 别名]
def _stopAccountManager(self, strategyCls, oneKeyHangUp=False):
"""
停止策略的账户管理者
@oneKeyHangUp: 一键挂机导致的
"""
if strategyCls.broker is None:
return
if strategyCls.broker not in self._accountManagers:
return
self._info.print('股票CTA引擎: 账号[{0}]解除绑定策略[{1}]'.format(self.accountManagerMap[strategyCls.broker].brokerName, strategyCls.chName), DyLogData.ind1)
# check if other running strategies use the same account manager
for strategy, _ in self._strategies.values():
if strategy.name != strategyCls.name and \
strategyCls.broker == strategy.broker and \
strategy.state.isState(DyStockStrategyState.running):
return
# 退出策略的实盘交易接口
event = DyEvent(DyEventType.stockLogout)
event.data['broker'] = strategyCls.broker
event.data['oneKeyHangUp'] = oneKeyHangUp
self._eventEngine.put(event)
# 销毁券商账户管理者
self._accountManagers[strategyCls.broker].exit()
del self._accountManagers[strategyCls.broker]
示例2: _startAccountManager
# 需要导入模块: from EventEngine import DyEvent [as 别名]
# 或者: from EventEngine.DyEvent import data['broker'] [as 别名]
def _startAccountManager(self, strategyCls):
"""
启动策略的账户管理者
"""
if strategyCls.broker is None:
return True
if strategyCls.broker not in self._accountManagers:
# 实例化券商账户管理者
accountManager = self.accountManagerMap[strategyCls.broker](self._eventEngine, self._info)
# 账户管理的开盘前准备
accountManager.onOpen(datetime.now().strftime("%Y-%m-%d"))
self._accountManagers[strategyCls.broker] = accountManager
# 登录策略的实盘交易接口
event = DyEvent(DyEventType.stockLogin)
event.data['broker'] = strategyCls.broker
self._eventEngine.put(event)
self._info.print('股票CTA引擎: 账号[{0}]绑定策略[{1}]'.format(self.accountManagerMap[strategyCls.broker].brokerName, strategyCls.chName), DyLogData.ind1)
return True
示例3: _stockPosSyncFromBrokerHandler
# 需要导入模块: from EventEngine import DyEvent [as 别名]
# 或者: from EventEngine.DyEvent import data['broker'] [as 别名]
def _stockPosSyncFromBrokerHandler(self, event):
"""
收到来自券商接口的持仓同步事件
!!!如果交易不是通过策略,或者持仓同步不是在开盘时,可能会导致信息不一致或者错误。
"""
# unpack
header = event.data['header']
rows = event.data['rows']
# it's synchronized from broker
self._curPosSyncData = {}
for data in rows:
# unpack from 券商接口持仓数据
code = DyStockCommon.getDyStockCode(data[header.index(self.headerNameMap['position']['code'])])
name = data[header.index(self.headerNameMap['position']['name'])]
totalVolume = float(data[header.index(self.headerNameMap['position']['totalVolume'])])
availVolume = float(data[header.index(self.headerNameMap['position']['availVolume'])])
price = float(data[header.index(self.headerNameMap['position']['price'])])
cost = float(data[header.index(self.headerNameMap['position']['cost'])])
# get position
pos = self._curPos.get(code)
if pos is None:
continue
# set sync data firstly
self._curPosSyncData[code] = {'volumeAdjFactor': totalVolume/pos.totalVolume,
'priceAdjFactor': pos.cost/cost,
'cost': cost
}
# syn with positions from broker
pos.price = price
pos.cost = cost
pos.totalVolume = totalVolume
pos.availVolume = availVolume
pos.priceAdjFactor = self._curPosSyncData[code]['priceAdjFactor']
pos.volumeAdjFactor = self._curPosSyncData[code]['volumeAdjFactor']
if pos.priceAdjFactor != 1:
pos.xrd = True
pos.sync = True
# 发送行情监控事件
self._putStockMarketMonitorEvent()
# 发送股票持仓同步事件
event = DyEvent(DyEventType.stockPosSyncFromAccountManager)
event.data['broker'] = self.broker
event.data['data'] = self._curPosSyncData
self._eventEngine.put(event)
示例4: _stockPositionUpdateHandler
# 需要导入模块: from EventEngine import DyEvent [as 别名]
# 或者: from EventEngine.DyEvent import data['broker'] [as 别名]
def _stockPositionUpdateHandler(self, event):
"""
收到来自券商接口的账户持仓更新事件
"""
# unpack
header = event.data['header']
rows = event.data['rows']
# 先前持仓代码
codes = list(self._curPos)
for data in rows:
# unpack from 券商接口持仓数据
code = DyStockCommon.getDyStockCode(data[header.index(self.headerNameMap['position']['code'])])
name = data[header.index(self.headerNameMap['position']['name'])]
totalVolume = float(data[header.index(self.headerNameMap['position']['totalVolume'])])
availVolume = float(data[header.index(self.headerNameMap['position']['availVolume'])])
price = float(data[header.index(self.headerNameMap['position']['price'])])
cost = float(data[header.index(self.headerNameMap['position']['cost'])])
# get position
if code in self._curPos:
pos = self._curPos[code]
codes.remove(code)
else:
# new pos, we just take time now without accuracy
if totalVolume > 0:
pos = DyStockPos(datetime.now(), None, code, name, price, totalVolume, 0)
pos.sync = True
else:
continue
# syn with positions from broker
pos.price = price
pos.cost = cost
pos.totalVolume = totalVolume
pos.availVolume = availVolume
# write back
self._curPos[code] = pos
# 删除不在券商接口数据里的持仓
for code in codes:
del self._curPos[code]
# 发送行情监控事件
self._putStockMarketMonitorEvent()
# 发送券商账户股票持仓更新事件
event = DyEvent(DyEventType.stockOnPos)
event.data['broker'] = self.broker
event.data['pos'] = copy.deepcopy(self._curPos)
self._eventEngine.put(event)