Crypto-toolbox/bitex

binance exchange: 403 responses (dev branch)

Opened this issue · 1 comments

Hi,

can somebody please test the binance exchange api on the dev branch?

Public endpoints (ticker etc. work) but as soon as I try something related to my account I get 403 responses.

E.g. try the wallet method. I think the problem is related on how the request is signed.
I tried my api key/secret using a different library (python-binance) and on that one it works perfectly.

I compared how request signing is done on python-binance and on bitex and they are slightly different (check in particular params in kwargs).

I'll investigate this further but I'd like somebody else to do a quick test and confirm it's a reproducible bug and not just on my side... just to be sure. THX

To test, try:

api = bitex.Binance('apiKey', 'apiSecret')
wallet = api.wallet().json()
print(wallet)

There were several issues. The hardest to find was the one generated by this call:

req_kwargs = super(BinanceREST, self).sign_request_kwargs(endpoint, **kwargs)

    def sign_request_kwargs(self, endpoint, **kwargs):
        """
        Generate dummy Request Kwarg Signature.

        Extend this to implement signing of requests for private API calls. By default, it supplies
        a default URL using generate_uri and generate_url.

        :param endpoint: str, API Endpoint
        :param kwargs: Kwargs meant for requests.Request()
        :return: dict, request kwargs
        """
        uri = self.generate_uri(endpoint)
        url = self.generate_url(uri)
        template = {'url': url, 'headers': {}, 'files': {},
                    'data': {}, 'params': {}, 'auth': {}, 'cookies': {},
                    'hooks': {}, 'json': {}}
        template.update(kwargs)
        return template

The template returned had many empty dictionaries, one or all of them were causing the 403 errors.

Also the req_string for the GET calls was not including all the parameters.

See my PR. I tested basically all the methods, even did an bid request and cancel order. Everything works for me.