@@ -6,12 +6,12 @@ discard block |
||
6 | 6 | |
7 | 7 | class BinanceAPI |
8 | 8 | { |
9 | - protected $key; // API key |
|
10 | - protected $secret; // API secret |
|
11 | - protected $url; // API base URL |
|
12 | - protected $recvWindow; // API base URL |
|
13 | - protected $version; // API version |
|
14 | - protected $curl; // curl handle |
|
9 | + protected $key; // API key |
|
10 | + protected $secret; // API secret |
|
11 | + protected $url; // API base URL |
|
12 | + protected $recvWindow; // API base URL |
|
13 | + protected $version; // API version |
|
14 | + protected $curl; // curl handle |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Constructor for BinanceAPI |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @return mixed |
89 | 89 | * @throws Exception |
90 | 90 | */ |
91 | - private function request($url, $params = [], $method = 'GET') |
|
91 | + private function request($url, $params = [ ], $method = 'GET') |
|
92 | 92 | { |
93 | 93 | // Set URL & Header |
94 | - curl_setopt($this->curl, CURLOPT_URL, $this->url . $url); |
|
94 | + curl_setopt($this->curl, CURLOPT_URL, $this->url.$url); |
|
95 | 95 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, array()); |
96 | 96 | |
97 | 97 | //Add post vars |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | //Get result |
104 | 104 | $result = curl_exec($this->curl); |
105 | 105 | if ($result === false) |
106 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
106 | + throw new Exception('CURL error: '.curl_error($this->curl)); |
|
107 | 107 | |
108 | 108 | // decode results |
109 | 109 | $result = json_decode($result, true); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $data = [ |
127 | 127 | 'symbol' => $symbol |
128 | 128 | ]; |
129 | - return $this->request('v3/ticker/price?symbol=' . $symbol , $data); |
|
129 | + return $this->request('v3/ticker/price?symbol='.$symbol, $data); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function getMarkets() |
175 | 175 | { |
176 | 176 | $return = $this->request('v3/exchangeInfo'); |
177 | - return $return['symbols']; |
|
177 | + return $return[ 'symbols' ]; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | public function getBalances() |
187 | 187 | { |
188 | 188 | $b = $this->privateRequest('v3/account'); |
189 | - return $b['balances']; |
|
189 | + return $b[ 'balances' ]; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | * @return mixed |
199 | 199 | * @throws Exception |
200 | 200 | */ |
201 | - private function privateRequest($url, $params = [], $method = 'GET') |
|
201 | + private function privateRequest($url, $params = [ ], $method = 'GET') |
|
202 | 202 | { |
203 | 203 | // build the POST data string |
204 | - $params['timestamp'] = number_format((microtime(true) * 1000), 0, '.', ''); |
|
205 | - $params['recvWindow'] = $this->recvWindow; |
|
204 | + $params[ 'timestamp' ] = number_format((microtime(true) * 1000), 0, '.', ''); |
|
205 | + $params[ 'recvWindow' ] = $this->recvWindow; |
|
206 | 206 | |
207 | 207 | $query = http_build_query($params, '', '&'); |
208 | 208 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $sign = hash_hmac('sha256', $query, $this->secret); |
211 | 211 | |
212 | 212 | $headers = array( |
213 | - 'X-MBX-APIKEY: ' . $this->key |
|
213 | + 'X-MBX-APIKEY: '.$this->key |
|
214 | 214 | ); |
215 | 215 | |
216 | 216 | // make request |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $postdata = $params; |
221 | 221 | |
222 | 222 | // Set URL & Header |
223 | - curl_setopt($this->curl, CURLOPT_URL, $this->url . $url . "?{$query}&signature={$sign}"); |
|
223 | + curl_setopt($this->curl, CURLOPT_URL, $this->url.$url."?{$query}&signature={$sign}"); |
|
224 | 224 | |
225 | 225 | //Add post vars |
226 | 226 | if ($method == "POST") { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | //Get result |
232 | 232 | $result = curl_exec($this->curl); |
233 | 233 | if ($result === false) |
234 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
234 | + throw new Exception('CURL error: '.curl_error($this->curl)); |
|
235 | 235 | |
236 | 236 | // decode results |
237 | 237 | $result = json_decode($result, true); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | 'quantity' => $quantity |
311 | 311 | ]; |
312 | 312 | if ($price !== false) { |
313 | - $data['price'] = $price; |
|
313 | + $data[ 'price' ] = $price; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $b = $this->privateRequest('v3/order', $data, 'POST'); |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public function depositAddress($symbol) |
372 | 372 | { |
373 | - return $this->wapiRequest("v3/depositAddress.html", ['asset' => $symbol]); |
|
373 | + return $this->wapiRequest("v3/depositAddress.html", [ 'asset' => $symbol ]); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | * @return mixed |
383 | 383 | * @throws Exception |
384 | 384 | */ |
385 | - private function wapiRequest($url, $params = [], $method = 'GET') |
|
385 | + private function wapiRequest($url, $params = [ ], $method = 'GET') |
|
386 | 386 | { |
387 | 387 | // build the POST data string |
388 | - $params['timestamp'] = number_format((microtime(true) * 1000), 0, '.', ''); |
|
389 | - $params['recvWindow'] = $this->recvWindow; |
|
388 | + $params[ 'timestamp' ] = number_format((microtime(true) * 1000), 0, '.', ''); |
|
389 | + $params[ 'recvWindow' ] = $this->recvWindow; |
|
390 | 390 | |
391 | 391 | $query = http_build_query($params, '', '&'); |
392 | 392 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $sign = hash_hmac('sha256', $query, $this->secret); |
395 | 395 | |
396 | 396 | $headers = array( |
397 | - 'X-MBX-APIKEY: ' . $this->key |
|
397 | + 'X-MBX-APIKEY: '.$this->key |
|
398 | 398 | ); |
399 | 399 | |
400 | 400 | // make request |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | $postdata = $params; |
405 | 405 | |
406 | 406 | // Set URL & Header |
407 | - curl_setopt($this->curl, CURLOPT_URL, $this->wapi_url . $url . "?{$query}&signature={$sign}"); |
|
407 | + curl_setopt($this->curl, CURLOPT_URL, $this->wapi_url.$url."?{$query}&signature={$sign}"); |
|
408 | 408 | |
409 | 409 | //Add post vars |
410 | 410 | if ($method == "POST") { |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | //Get result |
416 | 416 | $result = curl_exec($this->curl); |
417 | 417 | if ($result === false) |
418 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
418 | + throw new Exception('CURL error: '.curl_error($this->curl)); |
|
419 | 419 | |
420 | 420 | // decode results |
421 | 421 | $result = json_decode($result, true); |
@@ -102,14 +102,16 @@ discard block |
||
102 | 102 | |
103 | 103 | //Get result |
104 | 104 | $result = curl_exec($this->curl); |
105 | - if ($result === false) |
|
106 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
105 | + if ($result === false) { |
|
106 | + throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
107 | + } |
|
107 | 108 | |
108 | 109 | // decode results |
109 | 110 | $result = json_decode($result, true); |
110 | 111 | |
111 | - if (!is_array($result) || json_last_error()) |
|
112 | - throw new Exception('JSON decode error'); |
|
112 | + if (!is_array($result) || json_last_error()) { |
|
113 | + throw new Exception('JSON decode error'); |
|
114 | + } |
|
113 | 115 | |
114 | 116 | return $result; |
115 | 117 | |
@@ -230,13 +232,15 @@ discard block |
||
230 | 232 | |
231 | 233 | //Get result |
232 | 234 | $result = curl_exec($this->curl); |
233 | - if ($result === false) |
|
234 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
235 | + if ($result === false) { |
|
236 | + throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
237 | + } |
|
235 | 238 | |
236 | 239 | // decode results |
237 | 240 | $result = json_decode($result, true); |
238 | - if (!is_array($result) || json_last_error()) |
|
239 | - throw new Exception('JSON decode error'); |
|
241 | + if (!is_array($result) || json_last_error()) { |
|
242 | + throw new Exception('JSON decode error'); |
|
243 | + } |
|
240 | 244 | |
241 | 245 | return $result; |
242 | 246 | |
@@ -414,13 +418,15 @@ discard block |
||
414 | 418 | |
415 | 419 | //Get result |
416 | 420 | $result = curl_exec($this->curl); |
417 | - if ($result === false) |
|
418 | - throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
421 | + if ($result === false) { |
|
422 | + throw new Exception('CURL error: ' . curl_error($this->curl)); |
|
423 | + } |
|
419 | 424 | |
420 | 425 | // decode results |
421 | 426 | $result = json_decode($result, true); |
422 | - if (!is_array($result) || json_last_error()) |
|
423 | - throw new Exception('JSON decode error'); |
|
427 | + if (!is_array($result) || json_last_error()) { |
|
428 | + throw new Exception('JSON decode error'); |
|
429 | + } |
|
424 | 430 | |
425 | 431 | return $result; |
426 | 432 |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | class BinanceAPIFacade extends Facade { |
8 | 8 | |
9 | - protected static function getFacadeAccessor() { |
|
10 | - return 'binance'; |
|
11 | - } |
|
9 | + protected static function getFacadeAccessor() { |
|
10 | + return 'binance'; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | } |
@@ -6,19 +6,19 @@ |
||
6 | 6 | |
7 | 7 | class BinanceServiceProvider extends ServiceProvider { |
8 | 8 | |
9 | - public function boot() |
|
10 | - { |
|
11 | - $this->publishes([ |
|
12 | - __DIR__.'/../config/binance.php' => config_path('binance.php') |
|
13 | - ]); |
|
14 | - } |
|
9 | + public function boot() |
|
10 | + { |
|
11 | + $this->publishes([ |
|
12 | + __DIR__.'/../config/binance.php' => config_path('binance.php') |
|
13 | + ]); |
|
14 | + } |
|
15 | 15 | |
16 | - public function register() |
|
17 | - { |
|
18 | - $this->mergeConfigFrom(__DIR__.'/../config/binance.php', 'binance'); |
|
19 | - $this->app->bind('binance', function() { |
|
20 | - return new BinanceAPI(config('binance')); |
|
21 | - }); |
|
22 | - } |
|
16 | + public function register() |
|
17 | + { |
|
18 | + $this->mergeConfigFrom(__DIR__.'/../config/binance.php', 'binance'); |
|
19 | + $this->app->bind('binance', function() { |
|
20 | + return new BinanceAPI(config('binance')); |
|
21 | + }); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | } |