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