bifinex的订单号:
def _gen_unqiue_cid(self): self.order_id += 1 local_oid = time.strftime("%y%m%d") + str(self.order_id) return int(local_oid) def send_order(self, req: OrderRequest): orderid = self._gen_unqiue_cid() if req.direction == Direction.LONG: amount = req.volume else: amount = -req.volume o = { "cid": orderid, "type": ORDERTYPE_VT2BITFINEX[req.type], "symbol": "t" + req.symbol, "amount": str(amount), "price": str(req.price), } request = [0, "on", None, o] order = req.create_order_data(orderid, self.gateway_name) self.send_packet(request) self.gateway.on_order(order) return order.vt_orderid
bitmex的
def _new_order_id(self): with self.order_count_lock: self.order_count += 1 return self.order_count def send_order(self, req: OrderRequest): """""" orderid = str(self.connect_time + self._new_order_id()) data = { "symbol": req.symbol, "side": DIRECTION_VT2BITMEX[req.direction], "ordType": ORDERTYPE_VT2BITMEX[req.type], "orderQty": int(req.volume), "clOrdID": orderid, } inst = [] # Order special instructions # Only add price for limit order. if req.type == OrderType.LIMIT: data["price"] = req.price elif req.type == OrderType.STOP: data["stopPx"] = req.price inst.append("LastPrice") # Check for close order if req.offset == Offset.CLOSE: inst.append("ReduceOnly") # Generate execInst if inst: data["execInst"] = ",".join(inst) order = req.create_order_data(orderid, self.gateway_name) self.add_request( "POST", "/order", callback=self.on_send_order, data=data, extra=order, on_failed=self.on_send_order_failed, on_error=self.on_send_order_error, ) self.gateway.on_order(order) return order.vt_orderid