def sendOrder(self, vtSymbol, direction, offset, price, volume, payup=0): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: return '' req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.vtSymbol = contract.vtSymbol req.direction = direction req.offset = offset req.volume = int(volume) req.priceType = PRICETYPE_LIMITPRICE if direction == DIRECTION_LONG: req.price = price + payup * contract.priceTick else: req.price = price - payup * contract.priceTick # 委托转换 reqList = self.mainEngine.convertOrderReq(req) vtOrderIDList = [] for req in reqList: vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) vtOrderIDList.append(vtOrderID) return vtOrderIDList
def onPlaceOrder(self, clientId, req): """委托""" params = req['params'] s, e = params['security'].split('.') contract = self.mainEngine.getContract(s) if not contract: vtOrderID = '' error = [-1, u'委托失败,找不到合约%s' %params['security']] else: vor = VtOrderReq() vor.symbol = s vor.exchange = EXCHANGE_MAP[e] vor.direction, vor.offset = ACTION_MAP[params['action']] vor.price = float(params['price']) vor.volume = int(params['size']) vor.priceType = PRICETYPE_LIMITPRICE vtOrderID = self.mainEngine.sendOrder(vor, contract.gatewayName) error = [0, ''] self.server.send_rsp(clientId, req, vtOrderID, error) self.writeLog(u'发出响应:%s' %vtOrderID)
def sendOrder(self, vtSymbol, direction, offset, price, volume, payup=0): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: return '' req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.vtSymbol = contract.vtSymbol req.direction = direction req.offset = offset req.volume = int(volume) req.priceType = PRICETYPE_LIMITPRICE if direction == DIRECTION_LONG: req.price = price + payup * contract.priceTick else: req.price = price - payup * contract.priceTick # 委托转换 reqList = self.mainEngine.convertOrderReq(req) vtOrderIDList = [] for req in reqList: vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) vtOrderIDList.append(vtOrderID) return vtOrderIDList
def onPlaceOrder(self, clientId, req): """委托""" params = req['params'] s, e = params['security'].split('.') contract = self.mainEngine.getContract(s) if not contract: vtOrderID = '' error = [-1, u'委托失败,找不到合约%s' % params['security']] else: vor = VtOrderReq() vor.symbol = s vor.exchange = EXCHANGE_MAP[e] vor.direction, vor.offset = ACTION_MAP[params['action']] vor.price = float(params['price']) vor.volume = int(params['size']) vor.priceType = PRICETYPE_LIMITPRICE vtOrderID = self.mainEngine.sendOrder(vor, contract.gatewayName) error = [0, ''] self.server.send_rsp(clientId, req, vtOrderID, error) self.writeLog(u'发出响应:%s' % vtOrderID)
def post(self): """发单""" args = self.postParser.parse_args() token = args['token'] if token != TOKEN: return {'result_code':'error','message':'token error'} print(args) vtSymbol = args['vtSymbol'] price = args['price'] volume = args['volume'] priceType = args['priceType'] direction = args['direction'] offset = args['offset'] contract = me.getContract(vtSymbol) if not contract: return {'result_code':'error','message':'contract error'} priceType_map = {'PRICETYPE_LIMITPRICE' : u'限价','PRICETYPE_MARKETPRICE' : u'市价','PRICETYPE_FAK' : u'FAK','PRICETYPE_FOK' : u'FOK'} direction_map = {'DIRECTION_LONG' : u'多','DIRECTION_SHORT' : u'空'} offset_map = {'OFFSET_OPEN' : u'开仓', 'OFFSET_CLOSE' : u'平仓','OFFSET_CLOSETODAY' : u'平今','OFFSET_CLOSEYESTERDAY' : u'平昨'} req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.price = float(price) req.volume = int(volume) req.priceType = priceType_map[ priceType ] req.direction = direction_map[ direction ] req.offset = offset_map[ offset ] vtOrderID = me.sendOrder(req, contract.gatewayName) return {'result_code':'success','data':vtOrderID}
def sendOrder(self, algo, vtSymbol, direction, price, volume, priceType=None, offset=None): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: self.writeLog(u'%s委托下单失败,找不到合约:%s' %(algo.algoName, vtSymbol)) req = VtOrderReq() req.vtSymbol = vtSymbol req.symbol = contract.symbol req.exchange = contract.exchange req.direction = direction req.offset = OFFSET_CLOSETODAY req.price = price req.volume = volume if priceType: req.priceType = priceType else: req.priceType = PRICETYPE_LIMITPRICE if offset: req.offset = offset else: req.offset = OFFSET_OPEN vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) self.orderAlgoDict[vtOrderID] = algo return vtOrderID
def fastTrade(self, symbol, direction, offset, price, volume): """封装下单函数""" contract = self.mainEngine.getContract(symbol) if not contract: return req = VtOrderReq() req.symbol = symbol req.exchange = contract.exchange req.direction = direction req.offset = offset req.price = price req.volume = volume req.priceType = PRICETYPE_LIMITPRICE self.mainEngine.sendOrder(req, contract.gatewayName)
def fastTrade(self, symbol, direction, offset, price, volume): """封装下单函数""" contract = self.mainEngine.getContract(symbol) if not contract: return req = VtOrderReq() req.symbol = symbol req.exchange = contract.exchange req.direction = direction req.offset = offset req.price = price req.volume = volume req.priceType = PRICETYPE_LIMITPRICE self.mainEngine.sendOrder(req, contract.gatewayName)
def sendOrder(self, vtSymbol, direction, offset, price, volume): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: return '' req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.vtSymbol = vtSymbol req.price = price req.volume = volume req.direction = direction req.offset = offset req.priceType = PRICETYPE_LIMITPRICE return self.mainEngine.sendOrder(req, contract.gatewayName)
def sendOrder(self, vtSymbol, direction, offset, price, volume): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: return '' req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.vtSymbol = vtSymbol req.price = price req.volume = volume req.direction = direction req.offset = offset req.priceType = PRICETYPE_LIMITPRICE return self.mainEngine.sendOrder(req, contract.gatewayName)
def sendOrder(self, algo, vtSymbol, direction, price, volume): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol)) req = VtOrderReq() req.vtSymbol = vtSymbol req.symbol = contract.symbol req.exchange = contract.exchange req.direction = direction req.priceType = PRICETYPE_LIMITPRICE req.offset = OFFSET_CLOSETODAY req.price = price req.volume = volume vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) return vtOrderID
def sendOrder(self, algo, vtSymbol, direction, price, volume, priceType=None, offset=None): """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol)) vtSymbol = '.'.join([contract.symbol, contract.exchange]) req = VtOrderReq() req.vtSymbol = vtSymbol req.symbol = contract.symbol req.exchange = contract.exchange req.direction = direction req.offset = OFFSET_CLOSETODAY req.price = price req.volume = volume if priceType: req.priceType = priceType else: req.priceType = PRICETYPE_LIMITPRICE if offset: req.offset = offset else: req.offset = OFFSET_OPEN strData = 'symbol %s exchange %s price %.2f volume %d direction %s offset %s vtSymbol %s gatewayName %s'\ %(req.symbol,req.exchange,req.price,req.volume,req.direction,req.offset,req.vtSymbol,contract.gatewayName) print 'currency productClass ', req.currency, req.productClass # print 'sendOrder req:' # print strData vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) self.orderAlgoDict[vtOrderID] = algo return vtOrderID
def sendOrder(self, algo, vtSymbol, direction, price, volume, priceType=None, offset=None): logger.info(f"{algo.algoName}") print(f"进入发单") print(vtSymbol) """发单""" contract = self.mainEngine.getContract(vtSymbol) if not contract: self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol)) req = VtOrderReq() req.vtSymbol = vtSymbol req.symbol = contract.symbol req.exchange = contract.exchange req.direction = direction req.offset = OFFSET_CLOSETODAY req.price = price req.volume = volume if priceType: req.priceType = priceType else: req.priceType = PRICETYPE_LIMITPRICE if offset: req.offset = offset else: req.offset = OFFSET_OPEN vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) self.orderAlgoDict[vtOrderID] = algo logger.info(f"{vtOrderID}") return vtOrderID
def newOrder(self, vtSymbol): """""" for vtPositionName in self.targetDict.keys(): if vtSymbol not in vtPositionName: continue pos = self.posDict[vtPositionName] target = self.targetDict[vtPositionName] if pos == target: continue contract = self.mainEngine.getContract(vtSymbol) tick = self.mainEngine.getTick(vtSymbol) if not tick: return req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.priceType = PRICETYPE_LIMITPRICE req.volume = abs(target - pos) # Open position if target > pos: req.offset = OFFSET_OPEN if DIRECTION_LONG in vtPositionName: req.direction = DIRECTION_LONG if tick.upperLimit: req.price = tick.upperLimit else: req.price = tick.askPrice1 elif DIRECTION_SHORT in vtPositionName: req.direction = DIRECTION_SHORT if tick.lowerLimit: req.price = tick.lowerLimit else: req.price = tick.bidPrice1 self.mainEngine.sendOrder(req, contract.gatewayName) # Close position elif target < pos: req.offset = OFFSET_CLOSE if DIRECTION_LONG in vtPositionName: req.direction = DIRECTION_SHORT if tick.upperLimit: req.price = tick.upperLimit else: req.price = tick.askPrice1 elif DIRECTION_SHORT in vtPositionName: req.direction = DIRECTION_LONG if tick.lowerLimit: req.price = tick.lowerLimit else: req.price = tick.bidPrice1 # Use auto-convert for solving today/yesterday position problem reqList = self.mainEngine.convertOrderReq(req) for convertedReq in reqList: self.mainEngine.sendOrder(convertedReq, contract.gatewayName) # Write log msg = u'发出%s委托 %s%s %s@%s' % (vtSymbol, req.direction, req.offset, req.price, req.volume) self.writeLog(msg)
def newOrder(self, vtSymbol): """""" for vtPositionName in self.targetDict.keys(): if vtSymbol not in vtPositionName: continue pos = self.posDict[vtPositionName] target = self.targetDict[vtPositionName] if pos == target: continue contract = self.mainEngine.getContract(vtSymbol) tick = self.mainEngine.getTick(vtSymbol) if not tick: return req = VtOrderReq() req.symbol = contract.symbol req.exchange = contract.exchange req.priceType = PRICETYPE_LIMITPRICE req.volume = abs(target - pos) # Open position if target > pos: req.offset = OFFSET_OPEN if DIRECTION_LONG in vtPositionName: req.direction = DIRECTION_LONG if tick.upperLimit: req.price = tick.upperLimit else: req.price = tick.askPrice1 elif DIRECTION_SHORT in vtPositionName: req.direction = DIRECTION_SHORT if tick.lowerLimit: req.price = tick.lowerLimit else: req.price = tick.bidPrice1 self.mainEngine.sendOrder(req, contract.gatewayName) # Close position elif target < pos: req.offset = OFFSET_CLOSE if DIRECTION_LONG in vtPositionName: req.direction = DIRECTION_SHORT if tick.upperLimit: req.price = tick.upperLimit else: req.price = tick.askPrice1 elif DIRECTION_SHORT in vtPositionName: req.direction = DIRECTION_LONG if tick.lowerLimit: req.price = tick.lowerLimit else: req.price = tick.bidPrice1 # Use auto-convert for solving today/yesterday position problem reqList = self.mainEngine.convertOrderReq(req) for convertedReq in reqList: self.mainEngine.sendOrder(convertedReq, contract.gatewayName) # Write log msg = u'发出%s委托 %s%s %s@%s' %(vtSymbol, req.direction, req.offset, req.price, req.volume) self.writeLog(msg)