當前位置: 首頁>>代碼示例>>Python>>正文


Python EventEngine.DyEvent類代碼示例

本文整理匯總了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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:30,代碼來源:DyStockSelectRegressionEngineProcess.py

示例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
開發者ID:yutiansut,項目名稱:DevilYuan,代碼行數:25,代碼來源:DyStockCtaEngine.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:30,代碼來源:DyStockDataDaysEngine.py

示例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
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:30,代碼來源:DyStockAccountManager.py

示例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
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:34,代碼來源:DyStockAccountManager.py

示例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]
開發者ID:yutiansut,項目名稱:DevilYuan,代碼行數:30,代碼來源:DyStockCtaEngine.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:7,代碼來源:DyStockTradeWxEngine.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:35,代碼來源:DyStockDataStrategyDataPrepareEngine.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:7,代碼來源:DyCommon.py

示例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
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:31,代碼來源:DyStockSelectSelectEngine.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:30,代碼來源:DyStockDataMainWindow.py

示例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)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:34,代碼來源:DyStockTradeWxEngine.py

示例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)
開發者ID:yutiansut,項目名稱:DevilYuan,代碼行數:7,代碼來源:DyStockCtaEngine.py

示例14: _putTickEvent

    def _putTickEvent(self, ctaTickDatas):
        if not ctaTickDatas:
            return

        event = DyEvent(DyEventType.stockMarketTicks)
        event.data = ctaTickDatas

        self._eventEngine.put(event)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:8,代碼來源:DyStockMarketEngine.py

示例15: progressTotal

    def progressTotal(self, percent):
        if self._progressTotal != percent:
            self._progressTotal = percent

            event = DyEvent(DyEventType.progressTotal)
            event.data = percent

            self._eventEngine.put(event)
開發者ID:hack1943,項目名稱:DevilYuan,代碼行數:8,代碼來源:DyCommon.py


注:本文中的EventEngine.DyEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。