For the List Accounts endpoint, when I don’t pass any params I get a good response. When I pass either of the two optional params, limit or cursor, I get Unauthorized. Is this a bug?
auth.py
import time, hmac, hashlib
class Auth:
def __init__(self):
self.API_KEY = ''
self.SECRET = ''
def __call__(self, message):
timestamp = str(int(time.time()))
signature = hmac.new(self.SECRET.encode('utf-8'), (timestamp + message).encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
headers = {
'CB-ACCESS-KEY': self.API_KEY,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-SIGN': signature,
'Content-Type': 'application/json'
}
return headers, signature, self.API_KEY, timestamp
main.py
import json, http.client
import numpy as np
from auth import Auth
def send_request(method, path, payload):
auth = Auth()
headers = auth(method + path + payload)[0]
conn = http.client.HTTPSConnection('api.coinbase.com')
conn.request(method, path, payload, headers)
res = conn.getresponse()
data = res.read()
return data
def list_accounts():
method = 'GET'
path = '/api/v3/brokerage/accounts'
#path = '/api/v3/brokerage/accounts?limit=250'
#cursor = '***'
#path = '/api/v3/brokerage/accounts?cursor=' + cursor
payload = ''
data = send_request(method, path, payload)
print(data)
list_accounts()