本文整理汇总了Python中EventEngine.DyEvent.data['pos']方法的典型用法代码示例。如果您正苦于以下问题:Python DyEvent.data['pos']方法的具体用法?Python DyEvent.data['pos']怎么用?Python DyEvent.data['pos']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventEngine.DyEvent
的用法示例。
在下文中一共展示了DyEvent.data['pos']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _stockPositionUpdateHandler
# 需要导入模块: from EventEngine import DyEvent [as 别名]
# 或者: from EventEngine.DyEvent import data['pos'] [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)