【发布时间】:2022-07-15 20:56:13
【问题描述】:
我想使用 FTX api 获取余额。
参考 api docs 中的Python示例代码,修改如下。
但它返回一条错误消息。
{"success":false,"error":"未登录:无效签名"}
不知道为什么签名不对。
有人可以帮忙吗?
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)
参考