根据给出的错误信息 "Bitfinex Api v2 [ 'error', 10112, '签名无效' ]",该错误表示签名无效。在使用Bitfinex API进行请求时,需要正确地签名请求参数。
以下是一个示例代码来解决该问题:
import requests
import json
import hashlib
import hmac
import time
# 定义API密钥和密钥
API_KEY = 'your_api_key'
API_SECRET = 'your_api_secret'
# 定义请求方法
def post_request(url, params):
nonce = str(int(time.time() * 1000000))
body = json.dumps(params)
signature = '/api/v2' + url + nonce + body
sha384 = hmac.new(API_SECRET.encode(), signature.encode(), hashlib.sha384).hexdigest()
headers = {
'Content-Type': 'application/json',
'bfx-nonce': nonce,
'bfx-apikey': API_KEY,
'bfx-signature': sha384
}
response = requests.post('https://api.bitfinex.com' + url, headers=headers, data=body)
return response.json()
# 示例请求
url = '/v2/auth/r/orders/tBTCUSD/hist'
params = {
'limit': 10,
'start': 1612345678000,
'end': 1612345679000,
'sort': 1
}
response = post_request(url, params)
print(response)
请确保将 your_api_key
和 your_api_secret
替换为您自己的API密钥和密钥。此示例代码将发送一个POST请求到Bitfinex API的 /v2/auth/r/orders/tBTCUSD/hist
端点,并返回该请求的响应。
如果您仍然遇到签名无效的错误,请确保API密钥和密钥的正确性,并检查签名生成的步骤是否正确。