Kucoin / kucoin-python-sdk

MIT License
40 stars 11 forks source link

400 status code on deposits list endpoint #95

Open FV-Transfero opened 1 year ago

FV-Transfero commented 1 year ago

Hey everyone, I've been trying to access /api/v1/deposits endpoint to retrieve the data for my account deposits, but keep getting Invalid KC-API-SIGN on the response object.

The weird part is that when I access the balances endpoint /api/v1/accounts, inside the same script I ran to fetch the deposits, it returns me the information desired with a 200 code. Are there differences between the endpoints in terms of siging the request?

The code bellow is how I'm signing the request, I believe it's correct, specially since I can retrieve the balances information.

def _nonce(self):
        return int(time.time() * 1000)    

def _headers(self, path, body= ""):
        str_to_sign = str(self._nonce()) + 'GET' + path + body
        sign = base64.b64encode(
                hmac.new(self.api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest())

        headers = {
                "KC-API-SIGN": sign,
                "KC-API-TIMESTAMP": str(self._nonce()),
                "KC-API-KEY": self.api_key,
                "KC-API-PASSPHRASE": self.passphrase,
                "Content-Type": "application/json"
        }
        logging.info("Headers:")
        logging.info(headers)

        return headers

def _req(self, path, params={}):
        url = self.BASE_URL + path
        response = requests.request('get', url, headers=self._headers(path = path), params=params)
        return response

The request to the deposits endpoint is shown bellow:

def get_successful_deposits(self, currency, timespan):
        params= {
            'currency': currency,
            'startAt': timespan['startAt'],
            'endAt': timespan['endAt'],
            'status': 'SUCCESS'
        }
        response= self._req(path= '/api/v1/deposits', params= params)
        return response.json()