我可以从其他v1身份验证的端点获取数据,但是这个/ v1 / mytrades给了我无用的错误 请求:/ v1 / mytrades 回复代码:400 回复内容:b'{“message”:“关键符号不存在。”}'
代码几乎就是示例中的内容。 导入请求 导入json import base64 import hashlib 进口时间 导入hmac import configparser
# example source - https://gist.github.com/jordanbaucke/5812039
class BFXAuthClient():
def __init__ (self, key, secret):
self.key = key
self.secret = secret
self.request = ""
def orderHist (self):
self.request = "/v1/account_infos"
payload = {
'request': self.request,
'nonce': str (time.time())
}
self.Request (payload)
def myTrades (self):
self.request = "/v1/mytrades"
payload = {
'request': self.request,
'nonce': str (time.time()),
'currency': 'BTCETH'
}
self.Request (payload)
# Takes payload from other endpoint methods and sends a get/post request to bfx
def Request (self, payload):
print('Request: ' + self.request)
# Convert payload to JSON and hash it
payload_json = json.dumps (payload)
pay = base64.b64encode (bytes (payload_json, "utf-8"))
m = hmac.new (self.secret, pay, hashlib.sha384)
m = m.hexdigest ()
# Headers
# print(self.key)
# print(base64.b64encode (bytes (payload_json, "utf-8")))
# print(m)
headers = {'X-BFX-APIKEY': self.key, 'X-BFX-PAYLOAD': base64.b64encode (bytes (payload_json, "utf-8")),
'X-BFX-SIGNATURE': m}
# Print Response
r = requests.get ('https://api.bitfinex.com' + self.request, data={}, headers=headers)
print ('Response Code: ' + str (r.status_code))
# print('Response Header: ' + str(r.headers))
print ('Response Content: ' + str (r.content))
config = configparser.ConfigParser()
key="key"
secret=b"secret"
bfx = BFXAuthClient(key, secret)
bfx.orderHist()
bfx.myTrades()
我已经看过其他一些有关此错误的帖子,但在python中没有解决方案。 account_infos调用返回200和所有数据,所以我的身份验证和标题似乎没问题,不知道为什么这不起作用。