From 84908cfb872697f0b38b0ce9d8fb6218f59722c5 Mon Sep 17 00:00:00 2001 From: Munvier Date: Thu, 11 Jun 2020 13:35:47 +0200 Subject: [PATCH 1/2] Fixing __call for non api functions --- php-binance-api-rate-limiter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-binance-api-rate-limiter.php b/php-binance-api-rate-limiter.php index 15d7c712..0ca00394 100755 --- a/php-binance-api-rate-limiter.php +++ b/php-binance-api-rate-limiter.php @@ -236,9 +236,9 @@ private function ordersPerDay() */ public function __call(string $name, array $arguments) { - $weight = $this->weights[$name]; + $weight = $this->weights[$name] ?? false; - if ($weight > 0) { + if ($weight && $weight > 0) { $this->requestsPerMinute(); if (in_array($name, $this->ordersfunctions) === true) { $this->ordersPerSecond(); From a455b946908c87f2606cfd8e2a2659b1aa50a8fe Mon Sep 17 00:00:00 2001 From: Munvier Date: Thu, 11 Jun 2020 13:53:21 +0200 Subject: [PATCH 2/2] Provide setter/getter for headers x-mbx-used-weight and x-mbx-used-weight-1 --- php-binance-api.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 8cd3e78e..c8e8f005 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -53,7 +53,10 @@ class API protected $exchangeInfo = NULL; protected $lastRequest = []; - + + private $xMbxUsedWeight = 0; + private $xMbxUsedWeight1m = 0; + /** * Constructor for the class, * send as many argument as you want. @@ -1015,7 +1018,15 @@ protected function httpRequest(string $url, string $method = "GET", array $param 'header' => $header, 'json' => $json ]; - + + if (isset($header['x-mbx-used-weight'])) { + $this->setXMbxUsedWeight($header['x-mbx-used-weight']); + } + + if (isset($header['x-mbx-used-weight-1m'])) { + $this->setXMbxUsedWeight1m($header['x-mbx-used-weight-1m']); + } + if(isset($json['msg'])){ // should always output error, not only on httpdebug // not outputing errors, hides it from users and ends up with tickets on github @@ -2347,5 +2358,22 @@ private function floorDecimal($n, $decimals=2) { return floor($n * pow(10, $decimals)) / pow(10, $decimals); } + + + private function setXMbxUsedWeight (int $usedWeight) : void { + $this->xMbxUsedWeight = $usedWeight; + } + + private function setXMbxUsedWeight1m (int $usedWeight1m) : void { + $this->xMbxUsedWeight1m = $usedWeight1m; + } + + public function getXMbxUsedWeight () : int { + $this->xMbxUsedWeight; + } + + public function getXMbxUsedWeight1m () : int { + $this->xMbxUsedWeight1m; + } }