Alexander Thomsen
Alexander Thomsen

Reputation: 469

Kraken Futures API - authenticationError Python

I'm finding the Kraken Futures API confusing compared to other providers. Using a demo account I'm trying to make basic private requests and not working so far with authentication error. The code mainly comes from Kraken docs (non-futures)

Futures auth doc: https://support.kraken.com/hc/en-us/articles/360022635592-Generate-authentication-strings-REST-API-

api_sec = "MxA2FwIQxCxsfy2XDa4R8PwTjwLKjzT8GSOw+qOVuWGh3Lx6PtyW0f94J5XXKz9mP8bztRJSDQJVKBsHFicrDr/N"
api_url = "https://futures.kraken.com/derivatives/api/v3"
api_key = 'Y7kVv/hW0JWRRAhJtA8BuJkUX+E0gWmTL5NWf4lRPN8f+iYoJp9AoYwW'


def get_kraken_signature(urlpath, data, secret):

    postdata = urllib.parse.urlencode(data)
    encoded = (str(data['nonce']) + postdata).encode()
    message = urlpath.encode() + hashlib.sha256(encoded).digest()

    mac = hmac.new(base64.b64decode(secret), message, hashlib.sha256)
    sigdigest = base64.b64encode(mac.digest())
    return sigdigest.decode()

# Attaches auth headers and returns results of a get request
def kraken_request(uri_path, data, api_key, api_sec):
    headers = {}
    headers['API-Key'] = api_key
    # get_kraken_signature() as defined in the 'Authentication' section
    headers['API-Sign'] = get_kraken_signature(uri_path, data, api_sec)             
    req = requests.get((api_url + uri_path), headers=headers, data=data)
    return req

# Construct the request and print the result
resp = kraken_request('/accounts', {
    "nonce": str(int(1000*time.time()))
}, api_key, api_sec)

Output {"result":"error","error":"authenticationError","serverTime":"2022-05-13T10:14:50.838Z"}

Upvotes: 3

Views: 1044

Answers (1)

chainrunner_
chainrunner_

Reputation: 11

If you're trying to make private requests to your DEMO Kraken futures account:

  • first go to their GitHub (Crypto Facilities), then to the Rest-v3-Python repo and copy their code with all the API functions, or compare it to your own code make sure it does the same thing;
  • make sure you're using the right API url: notice that in OP's message, they use https://futures.kraken.com/... while if you want to trade using your demo account, the url should be "https://demo- futures.kraken.com/...". The endpoints stay the same between live and demo.
  • make sure to generate a keypair in your demo account and use this keypair in your code. Your futures.kraken.com API keys will not work on the demo.

Upvotes: 1

Related Questions