作者 karlet

feat:完善部分k线,订单监听问题

... ... @@ -370,7 +370,23 @@ class CmBroker
}
return $arr[$period];
}
throw new Exception('平台错误' + $platTarget);
if ($platTarget == self::PLAT_BITGET) {
$arr = [
'1m' => 'candle1m',
'5m' => 'candle5m',
'15m' => 'candle15m',
'30m' => 'candle30m',
'1h' => 'candle1H',
'4h' => 'candle4H',
'12h' => 'candle12H',
'1d' => 'candle1D',
];
if (!isset($arr[$period])) {
throw new Exception('周期错误,' . $this->plat . '不支持的周期' . $period);
}
return $arr[$period];
}
throw new Exception('平台错误' . $platTarget);
}
//转换为原始交易对
... ...
... ... @@ -73,8 +73,8 @@ class ExBroker
'op' => 'subscribe',
'args' => [
[
'instType' => 'SPOT',
'channel' => 'candle' . $interval,
'instType' => 'USDT-FUTURES',
'channel' => $interval,
'instId' => $symbol
]
]
... ... @@ -115,7 +115,7 @@ class ExBroker
private function wsLogin()
{
$timestamp = (string)(getMicrotime() / 1000);
$timestamp = (string)(getMicrotime());
$this->wsAcc->push(json_encode([
'op' => 'login',
'args' => [
... ... @@ -155,15 +155,25 @@ class ExBroker
'op' => 'subscribe',
'args' => [
[
'instType' => 'SPOT',
'channel' => 'account',
'instId' => 'default'
"instType" => "USDT-FUTURES",
"channel" => "positions",
"instId" => "default",
],
[
'instType' => 'SPOT',
'channel' => 'orders',
'instId' => 'default'
]
"instType" => "USDT-FUTURES",
"channel" => "account",
"coin" => "default"
],
[
"instType" => "USDT-FUTURES",
"channel" => "orders",
"instId" => "default"
],
[
"instType" => "USDT-FUTURES",
"channel" => "fill",
"instId" => "default"
],
]
]));
}
... ...
... ... @@ -88,15 +88,15 @@ class Kline
public static function transferBitget($data)
{
$kline = $data['data'][0];
$time = (int)($kline['ts']);
$open = (float)$kline['open'];
$high = (float)$kline['high'];
$low = (float)$kline['low'];
$close = (float)$kline['close'];
$vol = (float)$kline['vol'];
$volQuote = (float)$kline['volCcy'];
$uts = $time;
$isFinal = $kline['confirm'] ?? true;
$time = (int)($kline[0]);
$open = (float)$kline[1];
$high = (float)$kline[2];
$low = (float)$kline[3];
$close = (float)$kline[4];
$vol = (float)$kline[5];
$volQuote = (float)$kline[6];
$uts = $data['ts'];
$isFinal = $data['action'] == "snapshot";
return new Kline($time, $open, $high, $low, $close, $vol, $volQuote, $uts, $isFinal);
}
}
... ...
... ... @@ -203,26 +203,43 @@ class WsDataOrder
}
public static function TransferBitgetOrder(array $data, array $symbolInfos, callable $toSymbolSt): WsDataOrder|null
{
$symbol = call_user_func($toSymbolSt, $data['symbol']);
var_dump($data);
$symbol = call_user_func($toSymbolSt, $data['instId']);
/** @var SymbolInfo $symbolInfo */
$symbolInfo = $symbolInfos[$symbol] ?? null;
if ($symbolInfo === null) {
return null;
}
$posSide = strtoupper($data['posSide']);
if ($posSide == 'NET') {
$posSide = 'BOTH';
}
$avgPx = 0;
if (isset($data['priceAvg'])) {
$avgPx = (float)$data['priceAvg'];
}
$ordType = strtoupper($data['orderType']);
$timeInForce = strtoupper($data['force']);
if ($ordType == 'LIMIT' && $timeInForce == 'IOC') {
$ordType = 'IOC';
}
$pnl = 0;
if (isset($data['pnl'])) {
$pnl = (float)$data['pnl'];
}
return new WsDataOrder(
'bitget',
'BOTH',
$posSide,
$symbol,
strtoupper($data['side']),
(float)$data['price'],
(float)$data['fillPrice'],
$avgPx,
(float)$data['size'],
(float)$data['size'],
0,
$pnl,
(int)($data['cTime']),
(int)($data['uTime']),
strtoupper($data['orderType']),
$ordType,
$data['clientOid'],
$data['orderId'],
self::getBitgetStatus($data['status'])
... ... @@ -232,9 +249,9 @@ class WsDataOrder
private static function getBitgetStatus($status)
{
switch ($status) {
case 'new':
case 'live':
return 'LIVE';
case 'partial-filled':
case 'partially_filled':
return 'PARTIALLY_FILLED';
case 'filled':
return 'FILLED';
... ...