Python authenticated calls to bitfinex exchange

0 votes

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

Sep 7, 2018 in Blockchain by digger
• 26,720 points
437 views

1 answer to this question.

0 votes

You should use byte type api_secret.

api_secret = "ABCD"     # (X)
api_secret = b"ABCD"    # (O)
answered Sep 7, 2018 by slayer
• 29,310 points

Related Questions In Blockchain

+1 vote
1 answer
0 votes
1 answer

Is it possible to claim Bitcoin Cash from an exchange that does not support it?

You can't claim BCH without knowing private ...READ MORE

answered Jul 17, 2018 in Blockchain by aryya
• 7,440 points
248 views
0 votes
1 answer

I want to use Blockchain receive API without exchange rate

You are not using receive API you are using Exchange ...READ MORE

answered Aug 1, 2018 in Blockchain by Perry
• 17,100 points
233 views
+1 vote
4 answers
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
649 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,007 views
0 votes
1 answer
+2 votes
1 answer
0 votes
1 answer

Can't open a to big .csv file in python

You can't "split a file", but you can read ...READ MORE

answered Sep 3, 2018 in Blockchain by slayer
• 29,310 points
300 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP