'I have trouble with FTX api

I want to get my balance using the FTX api.

Refer to the Python sample code in the api docs and change it as follows.

But it returns an error message.

{"success":false,"error":"Not logged in: Invalid signature"}

I don't know why the signature is wrong.

Can someone please help?

import json
import hmac
import time
import requests

# API Keys
with open('../json/api.json', 'r') as f:
    api = json.load(f)
    accessKey = api['FTX']['ACCESS']
    secretKey = api['FTX']['SECRET']

endpoint = 'https://ftx.com/api'
url = '/wallet/balances'
method = 'GET'

ts = int(time.time() * 1000)
signature_payload = f'{ts}{method}{url}'.encode()
signature = hmac.new(secretKey.encode(), signature_payload, 'sha256').hexdigest()

headers = {
    'FTX-KEY': accessKey,
    'FTX-SIGN': signature,
    'FTX-TS': str(ts)
}

res = requests.request(method, endpoint+url, headers=headers)
print(res.text)

Reference

FTX API Authentication
FTX API Get Balance



Solution 1:[1]

Try changing the url to ftx.us and the headers to

'FTXUS-KEY': accessKey,
'FTXUS-SIGN': signature,
'FTXUS-TS': str(ts)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JJ-Pysquared