Skip to content

Commit 9a8156d

Browse files
authored
Fixing __call for non api functions + Access Binance response headers about x-mbx-used-weight and x-mbx-used-weight-1m
2 parents 288e6f5 + a455b94 commit 9a8156d

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

php-binance-api-rate-limiter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ private function ordersPerDay()
236236
*/
237237
public function __call(string $name, array $arguments)
238238
{
239-
$weight = $this->weights[$name];
239+
$weight = $this->weights[$name] ?? false;
240240

241-
if ($weight > 0) {
241+
if ($weight && $weight > 0) {
242242
$this->requestsPerMinute();
243243
if (in_array($name, $this->ordersfunctions) === true) {
244244
$this->ordersPerSecond();

php-binance-api.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class API
5353

5454
protected $exchangeInfo = NULL;
5555
protected $lastRequest = [];
56-
56+
57+
private $xMbxUsedWeight = 0;
58+
private $xMbxUsedWeight1m = 0;
59+
5760
/**
5861
* Constructor for the class,
5962
* send as many argument as you want.
@@ -1015,7 +1018,15 @@ protected function httpRequest(string $url, string $method = "GET", array $param
10151018
'header' => $header,
10161019
'json' => $json
10171020
];
1018-
1021+
1022+
if (isset($header['x-mbx-used-weight'])) {
1023+
$this->setXMbxUsedWeight($header['x-mbx-used-weight']);
1024+
}
1025+
1026+
if (isset($header['x-mbx-used-weight-1m'])) {
1027+
$this->setXMbxUsedWeight1m($header['x-mbx-used-weight-1m']);
1028+
}
1029+
10191030
if(isset($json['msg'])){
10201031
// should always output error, not only on httpdebug
10211032
// not outputing errors, hides it from users and ends up with tickets on github
@@ -2347,5 +2358,22 @@ private function floorDecimal($n, $decimals=2)
23472358
{
23482359
return floor($n * pow(10, $decimals)) / pow(10, $decimals);
23492360
}
2361+
2362+
2363+
private function setXMbxUsedWeight (int $usedWeight) : void {
2364+
$this->xMbxUsedWeight = $usedWeight;
2365+
}
2366+
2367+
private function setXMbxUsedWeight1m (int $usedWeight1m) : void {
2368+
$this->xMbxUsedWeight1m = $usedWeight1m;
2369+
}
2370+
2371+
public function getXMbxUsedWeight () : int {
2372+
$this->xMbxUsedWeight;
2373+
}
2374+
2375+
public function getXMbxUsedWeight1m () : int {
2376+
$this->xMbxUsedWeight1m;
2377+
}
23502378

23512379
}

0 commit comments

Comments
 (0)