【问题标题】:I have trouble with FTX api我在使用 FTX api 时遇到问题
【发布时间】: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)

参考

FTX API Authentication
FTX API Get Balance

【问题讨论】:

    标签: python api python-requests


    【解决方案1】:

    尝试将 url 更改为 ftx.us 和标题

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

    【讨论】:

      【解决方案2】:

      signature_payload = f'{ts}{method}{url}'.encode()

      其中 url => '/api/wallet/balances'

      您需要在 url 中包含“/api”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-09
        • 1970-01-01
        • 1970-01-01
        • 2023-02-13
        • 2020-12-23
        • 2021-11-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多