作者 karlet

feat:完善下单

... ... @@ -456,6 +456,20 @@ class CmBroker
$this->msg("下单结果", $res);
return $res;
}
if ($this->plat == self::PLAT_BITGET) {
$orderOri = $order->toBitgetOrder($this->symbolInfos, function ($symbol) {
return $this->getSymbolOri($symbol, $this->plat);
});
$this->msg("下单", $orderOri);
if ($orderOri['size'] == 0) {
$msg = "当前下单数量为{$order->qty},最小下单数量为{$symbolInfo->minQty},不下单";
$this->msg($msg, $orderOri);
return ["code" => 2, "msg" => $msg];
}
$res = $this->exBroker->placeOrder($orderOri);
$this->msg("下单结果", $res);
return $res;
}
}
public function msg()
... ...
... ... @@ -73,7 +73,7 @@ class Order
}
return $order;
}
function toBinanceOrder(array $symbolInfos, callable $toSymbolOri)
public function toBinanceOrder(array $symbolInfos, callable $toSymbolOri)
{
$symbol = call_user_func($toSymbolOri, $this->symbol);
/** @var SymbolInfo $symbolInfo */
... ... @@ -102,7 +102,7 @@ class Order
}
return $order;
}
function toBybitOrder(array $symbolInfos, callable $toSymbolOri)
public function toBybitOrder(array $symbolInfos, callable $toSymbolOri)
{
$symbol = call_user_func($toSymbolOri, $this->symbol);
/** @var SymbolInfo $symbolInfo */
... ... @@ -140,4 +140,37 @@ class Order
}
return $order;
}
public function toBitgetOrder(array $symbolInfos, callable $toSymbolOri)
{
$symbol = call_user_func($toSymbolOri, $this->symbol);
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$this->symbol];
$tradeSide = "open";
if (($this->posSide == "SHORT" && $this->side == "BUY") || ($this->posSide == "LONG" && $this->side == "SELL")) {
$tradeSide = "close";
}
$timeInForce = "GTC";
if ($this->ordType == "IOC") {
$timeInForce = "IOC";
$ordType = "LIMIT";
}
if ($this->ordType == "FOK") {
$timeInForce = "FOK";
$ordType = "LIMIT";
}
$order = [
'productType' => 'USDT-FUTURES',
'marginMode' => 'crossed',
'marginCoin' => 'USDT',
'symbol' => $symbol,
'side' => strtolower($this->side),
'orderType' => strtolower($this->ordType),
'price' => (string)round($this->price, $symbolInfo->pricePrec),
'size' => (string)round($this->qty, $symbolInfo->qtyPrec),
'tradeSide' => $tradeSide,
'force' => $timeInForce,
'clientOid' => $this->cliOrdId,
];
return $order;
}
}
... ...