binance-connector-php
binance-connector-php copied to clipboard
Fix bug with showHeader => true and weightUsage => true
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;
}