I am trying to make authenticated calls to bitfinex. I have this following code:
# pull current offers
def bitfinex_get_offers():
if lend_usd == True:
payloadObject_usd = {
'request': '/v1/offers',
'nonce': str(time.time() * 100000),
'options': {'symbol': 'USD'}
}
usd_offers_payload_json = json.dumps(payloadObject_usd)
usd_offers_payload = str(base64.b64encode(usd_offers_payload_json))
usd_offers_payload_encode = hmac.new(api_secret, usd_offers_payload, hashlib.sha384)
usd_offers_payload_encode = usd_offers_payload_encode.hexdigest()
headers_usd = {
'X-BFX-APIKEY': api_key,
'X-BFX-PAYLOAD': base64.b64encode(usd_offers_payload_json),
'X-BFX-SIGNATURE': usd_offers_payload_encode
}
usd_offers_request = requests.get(offers_url, data={}, headers = headers_usd)
return usd_offers_request.json()
else:
payloadObject_btc = {
'request': '/v1/offers',
'nonce': str(time.time() * 100000),
'options': {'symbol': 'BTC'}
}
btc_offers_payload_json = json.dumps(payloadObject_btc)
btc_offers_payload = str(base64.b64encode(btc_offers_payload_json))
btc_offers_payload_encode = hmac.new(api_secret, btc_offers_payload, hashlib.sha384)
btc_offers_payload_encode = btc_offers_payload_encode.hexdigest()
headers_btc = {
'X-BFX-APIKEY': api_key,
'X-BFX-PAYLOAD': base64.b64encode(btc_offers_payload_json),
'X-BFX-SIGNATURE': btc_offers_payload_encode
}
btc_offers_request = requests.get(offers_url, data={}, headers = headers_btc)
return btc_offers_request.json()
# pull current balances
def bitfinex_get_balance():
payloadObject_balance = {
'request': '/v1/balances',
'nonce': str(time.time() * 100000),
'options': ()
}
balance_payload_json = json.dumps(payloadObject_balance)
balance_payload = str(base64.b64encode(balance_payload_json))
balance_payload_encode = hmac.new(api_secret, balance_payload, hashlib.sha384)
balance_signature = balance_payload_encode.hexdigest()
headers_balance = {
'X-BFX-APIKEY': api_key,
'X-BFX-PAYLOAD': base64.b64encode(balance_payload_json),
'X-BFX-SIGNATURE': balance_signature
}
balance_request = requests.get(balance_url, data={}, headers = headers_balance)
print('Response Code: ' + str(balance_request.status_code))
print('Response Header: ' + str(balance_request.headers))
print('Response Content: '+ str(balance_request.content))
But I am getting invalid signature error