作者 karlet

feat:完善下单

@@ -456,6 +456,20 @@ class CmBroker @@ -456,6 +456,20 @@ class CmBroker
456 $this->msg("下单结果", $res); 456 $this->msg("下单结果", $res);
457 return $res; 457 return $res;
458 } 458 }
  459 + if ($this->plat == self::PLAT_BITGET) {
  460 + $orderOri = $order->toBitgetOrder($this->symbolInfos, function ($symbol) {
  461 + return $this->getSymbolOri($symbol, $this->plat);
  462 + });
  463 + $this->msg("下单", $orderOri);
  464 + if ($orderOri['size'] == 0) {
  465 + $msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单";
  466 + $this->msg($msg, $orderOri);
  467 + return ["code" => 2, "msg" => $msg];
  468 + }
  469 + $res = $this->exBroker->placeOrder($orderOri);
  470 + $this->msg("下单结果", $res);
  471 + return $res;
  472 + }
459 } 473 }
460 474
461 public function msg() 475 public function msg()
@@ -73,7 +73,7 @@ class Order @@ -73,7 +73,7 @@ class Order
73 } 73 }
74 return $order; 74 return $order;
75 } 75 }
76 - function toBinanceOrder(array $symbolInfos, callable $toSymbolOri) 76 + public function toBinanceOrder(array $symbolInfos, callable $toSymbolOri)
77 { 77 {
78 $symbol = call_user_func($toSymbolOri, $this->symbol); 78 $symbol = call_user_func($toSymbolOri, $this->symbol);
79 /** @var SymbolInfo $symbolInfo */ 79 /** @var SymbolInfo $symbolInfo */
@@ -102,7 +102,7 @@ class Order @@ -102,7 +102,7 @@ class Order
102 } 102 }
103 return $order; 103 return $order;
104 } 104 }
105 - function toBybitOrder(array $symbolInfos, callable $toSymbolOri) 105 + public function toBybitOrder(array $symbolInfos, callable $toSymbolOri)
106 { 106 {
107 $symbol = call_user_func($toSymbolOri, $this->symbol); 107 $symbol = call_user_func($toSymbolOri, $this->symbol);
108 /** @var SymbolInfo $symbolInfo */ 108 /** @var SymbolInfo $symbolInfo */
@@ -140,4 +140,37 @@ class Order @@ -140,4 +140,37 @@ class Order
140 } 140 }
141 return $order; 141 return $order;
142 } 142 }
  143 + public function toBitgetOrder(array $symbolInfos, callable $toSymbolOri)
  144 + {
  145 + $symbol = call_user_func($toSymbolOri, $this->symbol);
  146 + /** @var SymbolInfo $symbolInfo */
  147 + $symbolInfo = $symbolInfos[$this->symbol];
  148 + $tradeSide = "open";
  149 + if (($this->posSide == "SHORT" && $this->side == "BUY") || ($this->posSide == "LONG" && $this->side == "SELL")) {
  150 + $tradeSide = "close";
  151 + }
  152 + $timeInForce = "GTC";
  153 + if ($this->ordType == "IOC") {
  154 + $timeInForce = "IOC";
  155 + $ordType = "LIMIT";
  156 + }
  157 + if ($this->ordType == "FOK") {
  158 + $timeInForce = "FOK";
  159 + $ordType = "LIMIT";
  160 + }
  161 + $order = [
  162 + 'productType' => 'USDT-FUTURES',
  163 + 'marginMode' => 'crossed',
  164 + 'marginCoin' => 'USDT',
  165 + 'symbol' => $symbol,
  166 + 'side' => strtolower($this->side),
  167 + 'orderType' => strtolower($this->ordType),
  168 + 'price' => (string)round($this->price, $symbolInfo->pricePrec),
  169 + 'size' => (string)round($this->qty, $symbolInfo->qtyPrec),
  170 + 'tradeSide' => $tradeSide,
  171 + 'force' => $timeInForce,
  172 + 'clientOid' => $this->cliOrdId,
  173 + ];
  174 + return $order;
  175 + }
143 } 176 }