Author

Topic: Bitfinex Api - "must specify a request field.." (Read 4117 times)

newbie
Activity: 19
Merit: 0
October 26, 2017, 11:42:13 AM
#5
Help me, please. What i doing wrong?

Code:
api_key = 'some key'
api_secret = 'some secret'
api_url = 'https://api.bitfinex.com/v1'

def Balances():
    nonce = str(long(time.time() * 100000))
    payloadObject = {
        'request':'/balances',
        'nonce': nonce,
        'options':{}
        }
    payload_json = json.dumps(payloadObject)
    payload = str(base64.b64encode(payload_json))
    parms = urllib.urlencode(payloadObject)
    signature = hmac.new(api_secret, parms, hashlib.sha384).hexdigest()
    headers = {"X-BFX-APIKEY": api_key,
               'X-BFX-PAYLOAD': payload,
               "X-BFX-SIGNATURE": signature,
               }

    public = urllib2.urlopen(urllib2.Request(api_url + '/balances', headers))
    balances = json.load(public)
    return balances
member
Activity: 78
Merit: 11
I know this is an old topic, but in case anyone is having problems with the Bitfinex API:

In the documentation it shows all authenticated actions as using verb POST.  This is NOT correct as you can see by the above code.  Use GET.  Using POST will give you a 400 error.

I wasted a couple of hours on this problem, hope it saves someone else some time.
sr. member
Activity: 288
Merit: 250
ManualMiner
thx!  helped Smiley

changed nonce too, code now works:

Code:
url = 'https://api.bitfinex.com/v1/balances'
payloadObject = {
'request':'/v1/balances',
'nonce':str(long(time.time() * 100000)),
'options':{}
}
payload_json = json.dumps(payloadObject)
#print payload_json
payload = str(base64.b64encode(payload_json))
#print payload
api_secret="..."
api_key=".."
m=hmac.new(api_secret, payload, hashlib.sha384)
signature=m.hexdigest()
print signature
headers = {
'X-BFX-APIKEY' : api_key,
'X-BFX-PAYLOAD' : base64.b64encode(payload_json),
'X-BFX-SIGNATURE' : signature
}
r = requests.get(url, data={}, headers=headers)
print 'Response Code: ' + str(r.status_code)
print 'Response Header: ' + str(r.headers)
print 'Response Content: '+ str(r.content)

hero member
Activity: 868
Merit: 1000
Hello Wilfried,

Well, it seems we need to update the api.

The URL to use now it:

api.bitfinex.com/v1/

As such, the parameter
"request" that you send must be

Quote
'request':'/v1/'

instead of

Quote
'request':'/api/v1/'


Let me know if it helps, I'll update the wiki soon.

Raphael
Bitfinex team
sr. member
Activity: 288
Merit: 250
ManualMiner
Hy,

When making authenticated calls to the bitfinex api  (orders, balances) i get this message:

Code:
Response Content: {"message":"Must specify a 'request' field in the payload that
 matches the URL path."}

Whats that about?Huh

The examples I tried (Python):
https://community.bitfinex.com/showwiki.php?title=Sample+API+Code
https://gist.github.com/jordanbaucke/5812039

Code:
url = 'https://bitfinex.com/api/v1/balances'
payloadObject = {
'request':'/api/v1/balances',
'nonce':time.time(),
'options':{}
}
payload_json = json.dumps(payloadObject)
#print payload_json
payload = str(base64.b64encode(payload_json))
#print payload
api_secret="..."
api_key="..."
m=hmac.new(api_secret, payload, hashlib.sha384)
signature=m.hexdigest()
print signature
headers = {
'X-BFX-APIKEY' : api_key,
'X-BFX-PAYLOAD' : base64.b64encode(payload_json),
'X-BFX-SIGNATURE' : signature
}
r = requests.get(url, data={}, headers=headers)
print 'Response Code: ' + str(r.status_code)
print 'Response Header: ' + str(r.headers)
print 'Response Content: '+ str(r.content)





Jump to: