作者 karlet

feat:完善交易对精度

... ... @@ -253,6 +253,18 @@ class CmBroker
}
$this->symbolInfos = $infos;
}
if ($this->plat == self::PLAT_BINANCE) {
$res = $this->exBroker->getSymbolInfos();
$infos = [];
foreach ($res as $key => $value) {
if ($value["quoteAsset"] == "USDT") {
$info = SymbolInfo::transferBinance($value, function ($symbol) {
return $this->getSymbolSt($symbol);
});
$infos[$info->symbol] = $info;
}
}
}
//定时10m刷新
swoole_timer_after(1000 * 60 * 10, function () {
$this->initSymbolInfos();
... ...
... ... @@ -30,6 +30,13 @@ class Api
$method = "GET";
return $this->request($method, $url, $params);
}
//获取交易对信息
public function getExchangeInfo($params)
{
$url = "/fapi/v1/exchangeInfo";
$method = "GET";
return $this->request($method, $url, $params);
}
//-------private interface ------------
//获取用户监听key
... ...
... ... @@ -116,4 +116,13 @@ class ExBroker
$this->wsKline->close();
}
}
public function getSymbolInfos()
{
$res = $this->api->getExchangeInfo([]);
if (!isset($res['symbols'])) {
output('okx获取所有交易对信息失败');
return [];
}
return $res['symbols'];
}
}
... ...
... ... @@ -53,4 +53,27 @@ class SymbolInfo
$info = new SymbolInfo($data["instId"], $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
return $info;
}
public static function transferBinance($data, callable $getSymbolSt): SymbolInfo
{
$symbolOri = $data['symbol'];
$symbolSt = $getSymbolSt($symbolOri); //转换为标准交易对
$ctVal = 1;
$pricePrec = 0;
$qtyPrec = 0;
$lotPrec = 0;
$minLot = 0;
foreach ($data['filters'] as $v) {
if ($v['filterType'] == 'PRICE_FILTER') {
$pricePrec = getPrecision($v['tickSize']);
}
if ($v['filterType'] == 'LOT_SIZE') {
$minLot = $v['minQty'];
$minQty = $minLot * $ctVal;
$qtyPrec = getPrecision($minLot);
$lotPrec = getPrecision($minLot);
}
}
$info = new SymbolInfo($symbolOri, $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
return $info;
}
}
... ...