本文整理汇总了Python中EventEngine.DyEvent类的典型用法代码示例。如果您正苦于以下问题:Python DyEvent类的具体用法?Python DyEvent怎么用?Python DyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dyStockSelectRegressionEngineProcess
def dyStockSelectRegressionEngineProcess(outQueue, inQueue, tradeDays, strategy, codes, histDaysDataSource):
strategyCls = strategy['class']
parameters = strategy['param']
DyStockCommon.defaultHistDaysDataSource = histDaysDataSource
dummyEventEngine = DyDummyEventEngine()
queueInfo = DyQueueInfo(outQueue)
selectEngine = DyStockSelectSelectEngine(dummyEventEngine, queueInfo, False)
selectEngine.setTestedStocks(codes)
for day in tradeDays:
try:
event = inQueue.get_nowait()
except queue.Empty:
pass
parameters['基准日期'] = day
if selectEngine.runStrategy(strategyCls, parameters):
event = DyEvent(DyEventType.stockSelectStrategyRegressionAck)
event.data['class'] = strategyCls
event.data['period'] = [tradeDays[0], tradeDays[-1]]
event.data['day'] = day
event.data['result'] = selectEngine.result
outQueue.put(event)
else:
queueInfo.print('回归选股策略失败:{0}, 周期[{1}, {2}], 基准日期{3}'.format(strategyCls.chName, tradeDays[0], tradeDays[-1], day), DyLogData.error)
示例2: _startAccountManager
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: _updateStockHistDays_Handler
def _updateStockHistDays_Handler(self, event):
# unpack
codes = event.data
# check stop flag firstly
if self._isStopped:
self._printCount()
self._eventEngine.put(DyEvent(DyEventType.stopAck))
return
# update one code each time
code = sorted(codes)[0]
self._updateOneCode(code, codes[code])
# update progress
self._progress.update()
# delete updated code
del codes[code]
if not codes: # all codes are are updated
self._printCount()
self._eventEngine.put(DyEvent(DyEventType.finish))
return
# send for next updating
event = DyEvent(DyEventType.updateStockHistDays_)
event.data = codes
self._eventEngine.put(event)
示例4: cancel
def cancel(self, cancelEntrust):
"""
取消委托
"""
# find corresponding entrust
entrusts = self._curEntrusts.get(cancelEntrust.code)
if entrusts is None:
return False
for entrust in entrusts:
if entrust.dyEntrustId == cancelEntrust.dyEntrustId:
break
else:
return False
if entrust.isDone():
self._info.print('{}: 撤销委托失败: {}'.format(self.__class__.__name__, entrust.__dict__, DyLogData.warning))
return False
if entrust.brokerEntrustId is None:
self._curWorkingCancelEntrusts.append(entrust)
return True
# put cancel event
event = DyEvent(DyEventType.stockCancel + self.broker)
event.data = copy.copy(entrust)
self._eventEngine.put(event)
return True
示例5: _newEntrust
def _newEntrust(self, type, datetime, strategyCls, code, name, price, volume):
"""
生成新的委托,并向交易接口发送委托事件
"""
# check if there's same code and type of entrust not done for different strategy
entrusts = self._curEntrusts.get(code)
if entrusts is not None:
for entrust in entrusts:
if (not entrust.isDone()) and entrust.type == type and entrust.strategyCls != strategyCls:
self._info.print('{}: 策略[{}]委托失败({}, {}, {}, 价格={}, 数量={}): 策略[{}]有未完成的委托'.format(self.__class__.__name__, strategyCls.chName,
code, name, type, price, volume,
entrust.strategyCls.chName), DyLogData.warning)
return None
# create a new entrust
curEntrustCount = self.newCurEntrustCount()
entrust = DyStockEntrust(datetime, type, code, name, price, volume)
entrust.dyEntrustId = '{0}.{1}_{2}'.format(self.broker, self._curTDay, curEntrustCount)
entrust.strategyCls = strategyCls
# add into 当日委托
self._curEntrusts.setdefault(code, [])
self._curEntrusts[code].append(copy.copy(entrust))
# put buy/sell event
eventType = DyEventType.stockBuy if type == DyStockOpType.buy else DyEventType.stockSell
event = DyEvent(eventType + self.broker)
event.data = copy.copy(entrust)
self._eventEngine.put(event)
return entrust
示例6: _stopAccountManager
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]
示例7: handle_msg_all
def handle_msg_all(self, msg):
if msg['user']['name'] == 'self':
event = DyEvent(DyEventType.wxQueryStockStrategy)
event.data = msg['content']['data']
self._eventEngine.put(event)
示例8: _stockStrategyDataPrepareHandler
def _stockStrategyDataPrepareHandler(self, event):
date = event.data['date']
classes = event.data['classes']
if self._strategyClsCount == 0: # new start
self._strategyClsCount = len(classes)
else:
if self._isStopped:
# reset
self._strategyClsCount = 0
self._isStopped = False
# send stopAck
self._eventEngine.put(DyEvent(DyEventType.stopAck))
return
# only process the first one
self._stockStrategyDataPrepare(date, classes[0])
self._stockStrategyPosDataPrepare(date, classes[0])
self._stockStrategySimuTraderPosCloseUpdate(date, classes[0])
self._strategyClsCount -= 1
# check if finish or not
if self._strategyClsCount == 0: # finish
self._eventEngine.put(DyEvent(DyEventType.finish))
else:
# send left
event = DyEvent(DyEventType.stockStrategyDataPrepare)
event.data['date'] = date
event.data['classes'] = classes[1:]
self._eventEngine.put(event)
示例9: print
def print(self, description, type=DyLogData.info):
if not self._enabled and type != DyLogData.error and type != DyLogData.warning: return
event = DyEvent(DyEventType.subLog_ + '_' + str(self._paramGroupNo) + str(self._period))
event.data = DyLogData(description, type)
self._outQueue.put(event)
示例10: runStrategy
def runStrategy(self, strategyCls, paramters):
self._info.print("开始准备运行选股策略: {0}".format(strategyCls.chName), DyLogData.ind)
self._info.initProgress()
# init
self._init()
# create strategy instance
self._strategy = strategyCls(paramters, self._info)
# run
if self._run():
# ack
event = DyEvent(DyEventType.stockSelectStrategySelectAck)
event.data['class'] = strategyCls
event.data['result'] = self._result
event.data['baseDate'] = self._strategy.baseDate
self._eventEngine.put(event)
# finish
self._eventEngine.put(DyEvent(DyEventType.finish))
ret = True
else:
# fail
self._eventEngine.put(DyEvent(DyEventType.fail))
ret = False
return ret
示例11: _histDaysMannualUpdate
def _histDaysMannualUpdate(self):
if self._histDaysMannualUpdateAction.text() == '停止':
self._mainEngine._info.print('停止股票(指数)历史日线数据手动更新...', DyLogData.ind)
# change UI
self._stopRunningMutexAction()
event = DyEvent(DyEventType.stopUpdateStockHistDaysReq)
self._mainEngine.eventEngine.put(event)
else: # 开始手动更新
data = {}
if DyStockDataHistDaysManualUpdateDlg(data, self).exec_():
self._mainEngine._info.print('开始股票(指数,基金)历史日线数据手动更新[{0}, {1}]...'.format(data['startDate'], data['endDate']), DyLogData.ind)
# change UI
self._startRunningMutexAction(self._histDaysMannualUpdateAction)
event = DyEvent(DyEventType.updateStockHistDays)
event.data = data
event.data['codes'] = DyStockCommon.getDyStockCodes(event.data['codes'])
# 是否要更新指数的日线数据
if event.data['index']:
if event.data['codes'] is None:
event.data['codes'] = []
event.data['codes'].extend(list(DyStockCommon.indexes))
self._mainEngine.eventEngine.put(event)
示例12: _stockMarketTicksHandler
def _stockMarketTicksHandler(self, event):
if self._pushAction is None:
return
ticks = event.data
strategyData = self._latestStrategyData.get('DyST_IndexMeanReversion')
if strategyData is None:
return
strategyCls = strategyData[0]
tick = ticks.get(strategyCls.targetCode)
if tick is None:
return
# event
event = DyEvent(DyEventType.stockStrategyManualBuy)
event.data['class'] = strategyCls
event.data['tick'] = tick
event.data['volume'] = 100
event.data['price'] = round(tick.preClose * 0.92, 3)
self._eventEngine.put(event)
self._info.print('通过WX委托买入{0}, {1}股, 价格{2}'.format(tick.name, event.data['volume'], event.data['price']), DyLogData.ind1)
# sent to WX
self._sendWx('委托买入{0}, {1}股, 价格{2}'.format(tick.name, event.data['volume'], event.data['price']))
# clear
self._pushAction = None
self._eventEngine.unregister(DyEventType.stockMarketTicks, self._stockMarketTicksHandler, DyStockTradeEventHandType.wxEngine)
示例13: putStockMarketStrengthUpdateEvent
def putStockMarketStrengthUpdateEvent(self, strategyCls, time, marketStrengthInfo):
event = DyEvent(DyEventType.stockMarketStrengthUpdate)
event.data['class'] = strategyCls
event.data['time'] = time
event.data['data'] = marketStrengthInfo
self._eventEngine.put(event)
示例14: _putTickEvent
def _putTickEvent(self, ctaTickDatas):
if not ctaTickDatas:
return
event = DyEvent(DyEventType.stockMarketTicks)
event.data = ctaTickDatas
self._eventEngine.put(event)
示例15: progressTotal
def progressTotal(self, percent):
if self._progressTotal != percent:
self._progressTotal = percent
event = DyEvent(DyEventType.progressTotal)
event.data = percent
self._eventEngine.put(event)