def unsubscribe(self, unifiedSymbol, gatewayId=None): logger.info("策略%s取消订阅合约%s", self.strategyId, unifiedSymbol) contract = ClientTradeCacheService.getContractByUnifiedSymbol( unifiedSymbol) if contract is not None: if unifiedSymbol in self.subscribedUnifiedSymbolSet: self.subscribedUnifiedSymbolSet.remove(unifiedSymbol) RpcClientApiService.unsubscribe(contract, gatewayId, sync=True) else: logger.error("策略%s退订行情错误,未能找到合约%s", self.strategyId, unifiedSymbol)
def submitOrder(self, unifiedSymbol, orderPriceType, direction, offsetFlag, accountId, price, volume, originOrderId=None, sync=True): if self.initSwitch and self.tradingSwitch: submitOrderReq = SubmitOrderReqField() submitOrderReq.contract.CopyFrom( ClientTradeCacheService.getContractByUnifiedSymbol( unifiedSymbol)) submitOrderReq.direction = direction submitOrderReq.offsetFlag = offsetFlag submitOrderReq.orderPriceType = orderPriceType submitOrderReq.timeCondition = TimeConditionEnum.TC_GFD submitOrderReq.price = price submitOrderReq.minVolume = 1 submitOrderReq.stopPrice = 0.0 submitOrderReq.volumeCondition = VolumeConditionEnum.VC_AV submitOrderReq.contingentCondition = ContingentConditionEnum.CC_Immediately submitOrderReq.hedgeFlag = HedgeFlagEnum.HF_Speculation submitOrderReq.forceCloseReason = ForceCloseReasonEnum.FCR_NotForceClose submitOrderReq.volume = volume account = ClientTradeCacheService.getAccountByAccountId(accountId) submitOrderReq.gatewayId = account.gatewayId submitOrderReq.accountCode = account.code submitOrderReq.currency = account.currency if originOrderId is None: submitOrderReq.originOrderId = str(uuid.uuid4()) else: submitOrderReq.originOrderId = originOrderId self.originOrderIdSet.add(submitOrderReq.originOrderId) logger.info("策略%s提交定单 %s", MessageToJson(submitOrderReq), self.strategyId) if sync: orderId = RpcClientApiService.submitOrder(submitOrderReq, sync=True) return orderId else: RpcClientApiService.submitOrder(submitOrderReq, sync=False) return None else: logger.error("策略尚未初始化或未处于交易状态") return None
def subscribe(self, unifiedSymbol, gatewayId=None): logger.info("策略%s订阅合约%s", self.strategyId, unifiedSymbol) contract = ClientTradeCacheService.getContractByUnifiedSymbol( unifiedSymbol) if contract is not None: self.subscribedUnifiedSymbolSet.add(unifiedSymbol) if gatewayId is not None: contract.gatewayId = gatewayId else: contract.gatewayId = "" RpcClientApiService.subscribe(contract, None, sync=True) else: logger.error("策略%s订阅行情错误,未能找到合约%s", self.strategyId, unifiedSymbol)