作者 karlet

feat:listenkey

@@ -33,7 +33,7 @@ class BinanceSpot @@ -33,7 +33,7 @@ class BinanceSpot
33 { 33 {
34 $len = count($param); 34 $len = count($param);
35 if ($len == 0) { 35 if ($len == 0) {
36 - output('param 为空,签名失败'); 36 +// output('param 为空,签名失败');
37 return $param; 37 return $param;
38 } 38 }
39 $paramStr = http_build_query($param); 39 $paramStr = http_build_query($param);
@@ -62,6 +62,28 @@ class BinanceSpot @@ -62,6 +62,28 @@ class BinanceSpot
62 } 62 }
63 return json_decode($data, true); 63 return json_decode($data, true);
64 } 64 }
  65 + private function requestListenKey($method, $path, $param)
  66 + {
  67 + $url = $this->createUrl($path);
  68 +// $param['timestamp'] = getMicrotime();
  69 + $param['signature'] = $this->createSign($this->secret, $param);
  70 + $header = $this->createHeader($this->apikey);
  71 + if (!in_array(strtoupper($method), ['GET', 'POST', 'DELETE'])) {
  72 + output('请求方法错误', $method, $path, $param);
  73 + return 0;
  74 + }
  75 + $data = json_encode([]);
  76 + if (strtoupper($method) == 'POST') {
  77 + $data = Curl::httpPost($url, $param, $header);
  78 + }
  79 + if (strtoupper($method) == 'GET') {
  80 + $data = Curl::httpGet($url, $param, $header);
  81 + }
  82 + if (strtoupper($method) == 'DELETE') {
  83 + $data = Curl::httpDelete($url, $param, $header);
  84 + }
  85 + return json_decode($data, true);
  86 + }
65 87
66 static private function requestMarket($method, $path, $param) 88 static private function requestMarket($method, $path, $param)
67 { 89 {
@@ -151,14 +173,14 @@ class BinanceSpot @@ -151,14 +173,14 @@ class BinanceSpot
151 { 173 {
152 $path = '/api/v3/userDataStream'; 174 $path = '/api/v3/userDataStream';
153 $method = 'POST'; 175 $method = 'POST';
154 - return $this->requestMarket($method, $path, $param); 176 + return $this->requestListenKey($method, $path, $param);
155 } 177 }
156 //延长 Listen Key 有效期 (USER_STREAM) 178 //延长 Listen Key 有效期 (USER_STREAM)
157 public function listenKeyDelay($param) 179 public function listenKeyDelay($param)
158 { 180 {
159 $path = '/api/v3/userDataStream'; 181 $path = '/api/v3/userDataStream';
160 $method = 'PUT'; 182 $method = 'PUT';
161 - return $this->requestMarket($method, $path, $param); 183 + return $this->requestListenKey($method, $path, $param);
162 } 184 }
163 185
164 /* 186 /*