binance / binance/binance-connector-php

Fix bug with showHeader => true and weightUsage => true

Open
#25 0 comments 0 reactions 0 assignees View on GitHub
reviewing
Dominant language
PHP
Stars
106
Forks
29
PR merge metrics
No merged PRs in 30d

Description

I detect bug with enabled both showHeader and weightUsage, returns only weightUsage in array without header.
I fixed this in method processRequest in file /src/Binance/APIClient.php
Fixed code:
```
private function processRequest($method, $path, $params = array())
{
try {
$response = $this->httpRequest->request($method, $this->buildQuery($path, $params));
} catch (\GuzzleHttp\Exception\ClientException $e) {
throw new ClientException($e);
} catch (\GuzzleHttp\Exception\ServerException $e) {
throw new ServerException($e);
}

$body = json_decode($response->getBody(), true);

// fixed show header bug with weight usage
$returnData = null;
if ($this->showWeightUsage || $this->showHeader) {
$returnData['data'] = $body;
}

if ($this->showWeightUsage) {
$weights = [];
foreach ($response->getHeaders() as $name => $value) {
$name = strtolower($name);
if (strpos($name, 'x-mbx-used-weight') === 0 ||
strpos($name, 'x-mbx-order-count') === 0 ||
strpos($name, 'x-sapi-used') === 0) {
$weights[$name] = $value;
}
}

$returnData['weight_usage'] = $weights;
}

if ($this->showHeader) {
$returnData['header'] = $response->getHeaders();
}

return is_null($returnData) ? $body : $returnData;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.