作者 karlet

feat:增加获取杠杆

... ... @@ -236,4 +236,18 @@ class CmBroker
{
$this->exBroker->setLongShortMode($isLongShort);
}
//获取全部品种的杠杆
public function getLevers()
{
$levers = $this->exBroker->getAllLevers();
if ($this->plat == 'okx') {
$resNew = [];
foreach ($levers as $key => $value) {
$symbol = $this->getSymbolSt($key); //转换为标准交易对
$resNew[$symbol] = $value;
}
$levers = $resNew;
}
return $levers;
}
}
... ...
... ... @@ -240,4 +240,50 @@ class ExBroker
$res = $this->api->setPositionMode($param);
output("设置持仓模式", $res);
}
//获取所有品种杠杆信息
public function getAllLevers()
{
//获取所有USDT SWAP 交易对
$res = $this->api->instruments(["instType" => "SWAP"]);
$Symbols = [];
foreach ($res["data"] as $key => $value) {
if ($value["settleCcy"] == "USDT") {
$Symbols[] = $value["instId"];
}
}
//获取所有品种的杠杆信息
return $this->getLevers($Symbols);
}
//获取杠杆
private function getLevers($symbols)
{
$levers = [];
$param = [
'mgnMode' => 'cross'
];
$count = 0;
$instId = '';
foreach ($symbols as $key => $value) {
$count++;
if ($instId == '') {
$instId = $value;
} else {
$instId = $instId . ',' . $value;
}
if ($count % 20 == 0 || $count == count($symbols)) {
$param['instId'] = $instId;
$instId = '';
$res = $this->api->leverageInfo($param, $this->apiInfo);
if ($res['code'] == 0) {
foreach ($res["data"] as $key => $value) {
$levers[$value["instId"]] = $value["lever"];
}
} else {
var_dump($res);
break;
}
}
}
return $levers;
}
}
... ...