2021年4月3日星期六

Coinlist exchange API authentication - Python

For the past month I've been trying to understand coinlist API (https://coinlist.co) since there is no API wrapper available it's been a hard task. I could figure it out that their API docs are really similar to coinbase exchange, and tried to extrapolate but with no success.

import json, hmac, hashlib, time, requests  from requests.auth import AuthBase    # Before implementation, set environmental variables with the names API_KEY and API_SECRET  API_KEY = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'  API_SECRET = 'xxxx/xxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxx=='    # Create custom authentication for Coinlist API  class CoinlistWalletAuth(AuthBase):      def __init__(self, api_key, secret_key):          self.api_key = api_key          self.secret_key = secret_key        def __call__(self, request):          timestamp = str(int(time.time()))          message = timestamp + request.method + request.path_url + (request.body or '')          signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()            request.headers.update({              'CL-ACCESS-SIGN': signature,              'CL-ACCESS-TIMESTAMP': timestamp,              'CL-ACCESS-KEY': self.api_key,          })          return request  
auth = CoinlistWalletAuth(API_KEY, API_SECRET)  #Test1 - Fetching account balance  response = requests.get('https://trade-api.coinlist.co/v1/accounts', auth=auth)  

I am getting this TypeError: key: expected bytes or bytearray, but got 'str' when calling for the response.

Docs say - You must base64-encode the signature (the output of the sha256 HMAC). Why is it failing?

https://stackoverflow.com/questions/66926284/coinlist-exchange-api-authentication-python April 03, 2021 at 07:14AM

没有评论:

发表评论