|
...
|
...
|
@@ -62,6 +62,13 @@ class Api |
|
|
|
// 设置杠杆
|
|
|
|
public function setLeverage($param)
|
|
|
|
{
|
|
|
|
// 确保杠杆值为字符串类型
|
|
|
|
if (isset($param['buyLeverage'])) {
|
|
|
|
$param['buyLeverage'] = (string)$param['buyLeverage'];
|
|
|
|
}
|
|
|
|
if (isset($param['sellLeverage'])) {
|
|
|
|
$param['sellLeverage'] = (string)$param['sellLeverage'];
|
|
|
|
}
|
|
|
|
$path = '/v5/position/set-leverage';
|
|
|
|
$method = 'POST';
|
|
|
|
return $this->request($path, $method, $param, true);
|
|
...
|
...
|
@@ -79,27 +86,16 @@ class Api |
|
|
|
private function createSign($timestamp, $method, $path, $params = [])
|
|
|
|
{
|
|
|
|
$recv_window = '5000';
|
|
|
|
$queryString = '';
|
|
|
|
$postBody = '';
|
|
|
|
$sign_str = $timestamp . $this->apiInfo->key . $recv_window;
|
|
|
|
|
|
|
|
if ($method == 'GET' && !empty($params)) {
|
|
|
|
ksort($params);
|
|
|
|
$queryString = http_build_query($params);
|
|
|
|
}
|
|
|
|
if ($method == 'POST' && !empty($params)) {
|
|
|
|
ksort($params);
|
|
|
|
$postBody = json_encode($params);
|
|
|
|
$sign_str .= http_build_query($params);
|
|
|
|
} else if ($method == 'POST' && !empty($params)) {
|
|
|
|
$sign_str .= json_encode($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sign_str = $timestamp . $this->apiInfo->key . $recv_window . $path;
|
|
|
|
if ($queryString) {
|
|
|
|
$sign_str .= '?' . $queryString;
|
|
|
|
}
|
|
|
|
if ($postBody) {
|
|
|
|
$sign_str .= $postBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash_hmac('sha256', $sign_str, $this->apiInfo->secret);
|
|
|
|
$sign = hash_hmac('sha256', $sign_str, $this->apiInfo->secret);
|
|
|
|
return $sign;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function request($path, $method, $param, $auth = false)
|
|
...
|
...
|
@@ -125,7 +121,6 @@ class Api |
|
|
|
|
|
|
|
$url = $this->host . $path;
|
|
|
|
$result = "";
|
|
|
|
|
|
|
|
if ($method == 'POST') {
|
|
|
|
$result = Curl::httpPost($url, $param, $header);
|
|
|
|
} else {
|
...
|
...
|
|