Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vovkapoc opened this issue Oct 18, 2023 · 0 comments
Open

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

vovkapoc opened this issue Oct 18, 2023 · 0 comments

Comments

@vovkapoc
Copy link

vovkapoc commented Oct 18, 2023

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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants