Skip to content

Commit

Permalink
Fixing __call for non api functions + Access Binance response headers…
Browse files Browse the repository at this point in the history
… about x-mbx-used-weight and x-mbx-used-weight-1m
  • Loading branch information
jaggedsoft authored Jun 11, 2020
2 parents 288e6f5 + a455b94 commit 9a8156d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions php-binance-api-rate-limiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 30 additions & 2 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 9a8156d

Please sign in to comment.