作者 karlet

feat:完善bybit下单

... ... @@ -371,6 +371,20 @@ class CmBroker
}
return $res;
}
if ($this->plat == self::PLAT_BYBIT) {
$orderOri = $order->toBybitOrder($this->symbolInfos, function ($symbol) {
return $this->getSymbolOri($symbol, $this->plat);
});
$this->msg("下单", $orderOri);
if ($orderOri['qty'] == 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()
... ...
... ... @@ -102,4 +102,40 @@ class Order
}
return $order;
}
function toBybitOrder(array $symbolInfos, callable $toSymbolOri)
{
$symbol = call_user_func($toSymbolOri, $this->symbol);
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$this->symbol];
$order = [
'symbol' => $symbol,
'qty' => round($this->qty, $symbolInfo->qtyPrec),
'price' => round($this->price, $symbolInfo->pricePrec),
'orderLinkId' => $this->cliOrdId,
];
if ($this->ordType == "MARKET") {
$order['orderType'] = "Market";
unset($order['price']);
}
if ($this->ordType == "LIMIT") {
$order['timeInForce'] = "GTC";
}
if ($this->ordType == "IOC") {
$order['timeInForce'] = "IOC";
$order['orderType'] = "Limit";
}
if ($this->side == "BUY") {
$order['side'] = "Buy";
} else {
$order['side'] = "Sell";
}
if ($this->posSide == "LONG") {
$order['positionIdx'] = "1";
} else if ($this->posSide == "SHORT") {
$order['positionIdx'] = "2";
} else {
$order['positionIdx'] = "0";
}
return $order;
}
}
... ...