def processMessage(self): strategy = StrategyEngine.getStrategyByStrategyId(self.strategyId) while strategy is not None and self is strategy: if self.msgQueue.empty(): time.sleep(0.01) strategy = StrategyEngine.getStrategyByStrategyId( self.strategyId) continue message = self.msgQueue.get() if message['type'] == 'tick': tick = message['value'] if tick.unifiedSymbol in self.subscribedUnifiedSymbolSet: self.processTick(tick) elif message['type'] == 'trade': trade = message['value'] self.processTrade(trade) elif message['type'] == 'order': order = message['value'] self.processOrder(order) strategy = StrategyEngine.getStrategyByStrategyId(self.strategyId)
def onRpcTickRtn(rpcTickRtn): ClientTradeCacheService.storeTick(rpcTickRtn.tick) StrategyEngine.onTick(rpcTickRtn.tick)
def onRpcOrderRtn(rpcOrderRtn): ClientTradeCacheService.storeOrder(rpcOrderRtn.order) StrategyEngine.onOrder(rpcOrderRtn.order)
def onRpcTradeRtn(rpcTradeRtn): ClientTradeCacheService.storeTrade(rpcTradeRtn.trade) StrategyEngine.onTrade(rpcTradeRtn.trade)
def onRpcTradeListRtn(rpcTradeListRtn): for trade in rpcTradeListRtn.trade: ClientTradeCacheService.storeTrade(trade) StrategyEngine.onTrade(trade)
def onRpcOrderListRtn(rpcOrderListRtn): for order in rpcOrderListRtn.order: ClientTradeCacheService.storeOrder(order) StrategyEngine.onOrder(order)
startDatetime = '2020-06-15 00:00:00.000000' startTimestamp = int( time.mktime(time.strptime(startDatetime, "%Y-%m-%d %H:%M:%S.%f")) * 1000) endDatetime = '2020-06-23 00:00:00.000000' endTimestamp = int( time.mktime(time.strptime(endDatetime, "%Y-%m-%d %H:%M:%S.%f")) * 1000) print(startDatetime) print(endTimestamp) barList = RpcClientApiService.queryDBBarList(startTimestamp, endTimestamp, "IC2009@CFFEX@FUTURES", BarCycleEnum.B_1Min, MarketDataDBTypeEnum.MDDT_MIX, reqId=None, timeoutSeconds=None) print(len(barList)) demoStrategyId = "TEST-STRATEGY-ID-000" strategyDemo = StrategyDemo({"strategyId": demoStrategyId}) StrategyEngine.addStrategy(strategyDemo) strategyDemo.initStrategy() strategyDemo.startTrading() while True: time.sleep(100)
Config.operatorId = operatorId Config.nodeId = nodeId WebSocketClientHandler.connect(loginResult['cookie']) time.sleep(2) logging.info("获取账户列表") RpcClientApiService.getAccountList(sync=True) logging.info("获取持仓列表") RpcClientApiService.getPositionList(sync=True) logging.info("获取混合合约列表") RpcClientApiService.getMixContractList(sync=True) logging.info("获取委托列表") RpcClientApiService.getOrderList(sync=True) logging.info("获取成交列表") RpcClientApiService.getTradeList(sync=True) logging.info("获取Tick列表") RpcClientApiService.getTickList(sync=True) demoStrategyId = "TEST-STRATEGY-ID-000" strategyDemo = StrategyDemo(demoStrategyId) StrategyEngine.addStrategy(strategyDemo) StrategyEngine.start() strategyDemo.initStrategy() strategyDemo.startTrading() while True: time.sleep(100)