本文整理匯總了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)