|
...
|
...
|
@@ -134,27 +134,36 @@ class WsDataOrder |
|
|
|
}
|
|
|
|
public static function TransferBybitOrder($data, $symbolInfos, callable $toSymbolSt): WsDataOrder|null
|
|
|
|
{
|
|
|
|
$order = $data['data'];
|
|
|
|
$symbol = call_user_func($toSymbolSt, $order['symbol']);
|
|
|
|
$symbol = call_user_func($toSymbolSt, $data['symbol']);
|
|
|
|
/** @var SymbolInfo $symbolInfo */
|
|
|
|
$symbolInfo = $symbolInfos[$symbol] ?? null;
|
|
|
|
if ($symbolInfo == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$platform = 'bybit';
|
|
|
|
$posSide = strtoupper($order['side']);
|
|
|
|
$side = strtoupper($order['side']);
|
|
|
|
$price = (float)$order['price'];
|
|
|
|
$avgPx = (float)$order['avg_price'];
|
|
|
|
$lot = (float)$order['qty'];
|
|
|
|
$posSide = "BOTH";
|
|
|
|
if ($data['positionIdx'] == 1) {
|
|
|
|
$posSide = "LONG";
|
|
|
|
}
|
|
|
|
if ($data['positionIdx'] == 2) {
|
|
|
|
$posSide = "SHORT";
|
|
|
|
}
|
|
|
|
$side = strtoupper($data['side']);
|
|
|
|
$price = (float)$data['price'];
|
|
|
|
$avgPx = (float)$data['avgPrice'];
|
|
|
|
$lot = (float)$data['qty'];
|
|
|
|
$qty = $lot;
|
|
|
|
$pnl = (float)$order['realised_pnl'];
|
|
|
|
$ts = (int)$order['transact_time'];
|
|
|
|
$uts = (int)$order['transact_time'];
|
|
|
|
$ordType = strtoupper($order['order_type']);
|
|
|
|
$cliOrdId = $order['order_link_id'];
|
|
|
|
$ordId = $order['order_id'];
|
|
|
|
$status = self::getBnStatus($order['order_status']);
|
|
|
|
$pnl = (float)$data['closedPnl']; //去除手续费资金费的盈亏
|
|
|
|
$ts = (int)$data['updatedTime'];
|
|
|
|
$uts = (int)$data['updatedTime'];
|
|
|
|
$ordType = strtoupper($data['orderType']);
|
|
|
|
$timeInForce = $data['timeInForce'];
|
|
|
|
if ($timeInForce == 'IOC' && $ordType == "LIMIT") {
|
|
|
|
$ordType = "IOC";
|
|
|
|
}
|
|
|
|
$cliOrdId = $data['orderLinkId'];
|
|
|
|
$ordId = $data['orderId'];
|
|
|
|
$status = self::getBybitStatus($data['orderStatus']);
|
|
|
|
return new WsDataOrder($platform, $posSide, $symbol, $side, $price, $avgPx, $qty, $lot, $pnl, $ts, $uts, $ordType, $cliOrdId, $ordId, $status);
|
|
|
|
}
|
|
|
|
private static function getBnStatus(string $state)
|
|
...
|
...
|
@@ -176,4 +185,20 @@ class WsDataOrder |
|
|
|
}
|
|
|
|
return 'UNKNOWN';
|
|
|
|
}
|
|
|
|
private static function getBybitStatus(string $state)
|
|
|
|
{
|
|
|
|
if ($state == 'New') {
|
|
|
|
return 'LIVE';
|
|
|
|
}
|
|
|
|
if ($state == 'PartiallyFilled') {
|
|
|
|
return 'PARTIALLY_FILLED';
|
|
|
|
}
|
|
|
|
if ($state == 'Filled') {
|
|
|
|
return 'FILLED';
|
|
|
|
}
|
|
|
|
if ($state == 'Cancelled' || $state == "Rejected") {
|
|
|
|
return 'CANCELED';
|
|
|
|
}
|
|
|
|
return 'UNKNOWN';
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|