FTX使用Python获取帐户信息时出现未登录错误

2024-05-23 18:35:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Python连接到FTX以获取帐户信息,但它一直给我未登录错误;我的代码如下所示:

from requests import Request, Session
import time
import hmac

method = 'GET'
ENDPOINT = 'https://ftx.com/api/'
# ENDPOINT = 'https://ftx.us/api/'
path = 'account'

API_KEY = '...'
API_SECRET = '...'

request = Request(method, ENDPOINT + path)

ts = int(time.time() * 1000)
prepared = request.prepare()
print('{0}{1}{2}'.format(ts, prepared.method, prepared.path_url))
signature_payload = '{0}{1}{2}'.format(ts, prepared.method, prepared.path_url).encode()
if prepared.body:
    signature_payload += prepared.body
signature = hmac.new(API_SECRET.encode(), signature_payload, 'sha256').hexdigest()

request.headers['FTX-KEY'] = API_KEY
request.headers['FTX-SIGN'] = signature
request.headers['FTX-TS'] = str(ts)

# get data...
request1 = request.prepare()
print('{0}{1}{2}'.format(ts, request1.method, request1.path_url))
response = Session().send(request1)
data = response.json()

数据告诉我:

{'success': False, 'error': 'Not logged in'}

我想知道我哪里做错了?我在美国的定位是这可能会引起问题吗?我的账户还没有进行任何交易,我不确定这是否是问题所在


Tags: pathkeyimportapiformaturltimerequest