作者 karlet

feat:完善bybit下单

@@ -371,6 +371,20 @@ class CmBroker @@ -371,6 +371,20 @@ class CmBroker
371 } 371 }
372 return $res; 372 return $res;
373 } 373 }
  374 + if ($this->plat == self::PLAT_BYBIT) {
  375 + $orderOri = $order->toBybitOrder($this->symbolInfos, function ($symbol) {
  376 + return $this->getSymbolOri($symbol, $this->plat);
  377 + });
  378 + $this->msg("下单", $orderOri);
  379 + if ($orderOri['qty'] == 0) {
  380 + $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单";
  381 + $this->msg($msg, $orderOri);
  382 + return ["code" => 2, "msg" => $msg];
  383 + }
  384 + $res = $this->exBroker->placeOrder($orderOri);
  385 + $this->msg("下单结果", $res);
  386 + return $res;
  387 + }
374 } 388 }
375 389
376 public function msg() 390 public function msg()
@@ -102,4 +102,40 @@ class Order @@ -102,4 +102,40 @@ class Order
102 } 102 }
103 return $order; 103 return $order;
104 } 104 }
  105 + function toBybitOrder(array $symbolInfos, callable $toSymbolOri)
  106 + {
  107 + $symbol = call_user_func($toSymbolOri, $this->symbol);
  108 + /** @var SymbolInfo $symbolInfo */
  109 + $symbolInfo = $symbolInfos[$this->symbol];
  110 + $order = [
  111 + 'symbol' => $symbol,
  112 + 'qty' => round($this->qty, $symbolInfo->qtyPrec),
  113 + 'price' => round($this->price, $symbolInfo->pricePrec),
  114 + 'orderLinkId' => $this->cliOrdId,
  115 + ];
  116 + if ($this->ordType == "MARKET") {
  117 + $order['orderType'] = "Market";
  118 + unset($order['price']);
  119 + }
  120 + if ($this->ordType == "LIMIT") {
  121 + $order['timeInForce'] = "GTC";
  122 + }
  123 + if ($this->ordType == "IOC") {
  124 + $order['timeInForce'] = "IOC";
  125 + $order['orderType'] = "Limit";
  126 + }
  127 + if ($this->side == "BUY") {
  128 + $order['side'] = "Buy";
  129 + } else {
  130 + $order['side'] = "Sell";
  131 + }
  132 + if ($this->posSide == "LONG") {
  133 + $order['positionIdx'] = "1";
  134 + } else if ($this->posSide == "SHORT") {
  135 + $order['positionIdx'] = "2";
  136 + } else {
  137 + $order['positionIdx'] = "0";
  138 + }
  139 + return $order;
  140 + }
105 } 141 }