|
@@ -62,6 +62,13 @@ class Api |
|
@@ -62,6 +62,13 @@ class Api |
|
62
|
// 设置杠杆
|
62
|
// 设置杠杆
|
|
63
|
public function setLeverage($param)
|
63
|
public function setLeverage($param)
|
|
64
|
{
|
64
|
{
|
|
|
|
65
|
+ // 确保杠杆值为字符串类型
|
|
|
|
66
|
+ if (isset($param['buyLeverage'])) {
|
|
|
|
67
|
+ $param['buyLeverage'] = (string)$param['buyLeverage'];
|
|
|
|
68
|
+ }
|
|
|
|
69
|
+ if (isset($param['sellLeverage'])) {
|
|
|
|
70
|
+ $param['sellLeverage'] = (string)$param['sellLeverage'];
|
|
|
|
71
|
+ }
|
|
65
|
$path = '/v5/position/set-leverage';
|
72
|
$path = '/v5/position/set-leverage';
|
|
66
|
$method = 'POST';
|
73
|
$method = 'POST';
|
|
67
|
return $this->request($path, $method, $param, true);
|
74
|
return $this->request($path, $method, $param, true);
|
|
@@ -79,27 +86,16 @@ class Api |
|
@@ -79,27 +86,16 @@ class Api |
|
79
|
private function createSign($timestamp, $method, $path, $params = [])
|
86
|
private function createSign($timestamp, $method, $path, $params = [])
|
|
80
|
{
|
87
|
{
|
|
81
|
$recv_window = '5000';
|
88
|
$recv_window = '5000';
|
|
82
|
- $queryString = '';
|
|
|
|
83
|
- $postBody = '';
|
89
|
+ $sign_str = $timestamp . $this->apiInfo->key . $recv_window;
|
|
84
|
|
90
|
|
|
85
|
if ($method == 'GET' && !empty($params)) {
|
91
|
if ($method == 'GET' && !empty($params)) {
|
|
86
|
- ksort($params);
|
|
|
|
87
|
- $queryString = http_build_query($params);
|
|
|
|
88
|
- }
|
|
|
|
89
|
- if ($method == 'POST' && !empty($params)) {
|
|
|
|
90
|
- ksort($params);
|
|
|
|
91
|
- $postBody = json_encode($params);
|
92
|
+ $sign_str .= http_build_query($params);
|
|
|
|
93
|
+ } else if ($method == 'POST' && !empty($params)) {
|
|
|
|
94
|
+ $sign_str .= json_encode($params);
|
|
92
|
}
|
95
|
}
|
|
93
|
|
96
|
|
|
94
|
- $sign_str = $timestamp . $this->apiInfo->key . $recv_window . $path;
|
|
|
|
95
|
- if ($queryString) {
|
|
|
|
96
|
- $sign_str .= '?' . $queryString;
|
|
|
|
97
|
- }
|
|
|
|
98
|
- if ($postBody) {
|
|
|
|
99
|
- $sign_str .= $postBody;
|
|
|
|
100
|
- }
|
|
|
|
101
|
-
|
|
|
|
102
|
- return hash_hmac('sha256', $sign_str, $this->apiInfo->secret);
|
97
|
+ $sign = hash_hmac('sha256', $sign_str, $this->apiInfo->secret);
|
|
|
|
98
|
+ return $sign;
|
|
103
|
}
|
99
|
}
|
|
104
|
|
100
|
|
|
105
|
private function request($path, $method, $param, $auth = false)
|
101
|
private function request($path, $method, $param, $auth = false)
|
|
@@ -125,7 +121,6 @@ class Api |
|
@@ -125,7 +121,6 @@ class Api |
|
125
|
|
121
|
|
|
126
|
$url = $this->host . $path;
|
122
|
$url = $this->host . $path;
|
|
127
|
$result = "";
|
123
|
$result = "";
|
|
128
|
-
|
|
|
|
129
|
if ($method == 'POST') {
|
124
|
if ($method == 'POST') {
|
|
130
|
$result = Curl::httpPost($url, $param, $header);
|
125
|
$result = Curl::httpPost($url, $param, $header);
|
|
131
|
} else {
|
126
|
} else {
|