Introduction

The Bitfinex API’s are designed to allow access to all of the features of the Bitfinex platform. The end goal is to allow people to potentially recreate the entire platform on their own.

If you would like to suggest changes to the documentation, please see the github at https://github.com/bitfinexcom/api_docs

Open Source Libraries

The following open source projects are works in progress. We will be continually improving them, but we want to release them early so that the community can take a look, make use of them, and offer pull requests. Nothing in the Bitcoin world exists in isolation.

Get Started    

Authenticated Endpoints

All examples assume the following:

  1. You are using the provided example request object
  2. You use your API key and secret
  3. BTCUSD is the default symbol
const crypto = require('crypto')
const request = require('request')

const apiKey = '<Your API key here>'
const apiSecret = '<Your API secret here>'

const apiPath = 'v2/auth/r/alerts'
const nonce = Date.now().toString()
const body = { "type": "price" }
const rawBody = JSON.stringify(body)
let signature = `/api/${apiPath}${nonce}${rawBody}`

signature = crypto
  .createHmac('sha384', apiSecret)
  .update(signature)
  .digest('hex')

const options = {
  url: `https://api.bitfinex.com/${apiPath}`,
  headers: {
    'bfx-nonce': nonce,
    'bfx-apikey': apiKey,
    'bfx-signature': signature
  },
  body: body,
  json: true
}
request.post(options, (error, response, body) => {
  console.log(body);
})
import requests  # pip install requests
import json
import base64
import hashlib
import hmac
import time #for nonce

class BitfinexClient(object):
    BASE_URL = "https://api.bitfinex.com/"
    KEY=""
    SECRET=""

    def _nonce(self):
        """
        Returns a nonce
        Used in authentication
        """
        return str(int(round(time.time() * 1000)))

    def _headers(self, path, nonce, body):

        signature = "/api/" + path + nonce + body
        print "Signing: " + signature
        h = hmac.new(self.SECRET, signature, hashlib.sha384)
        signature = h.hexdigest()

        return {
            "bfx-nonce": nonce,
            "bfx-apikey": self.KEY,
            "bfx-signature": signature,
            "content-type": "application/json"
        }

    def active_orders(self):
        """
        Fetch active orders
        """
        nonce = self._nonce()
        body = {}
        rawBody = json.dumps(body)
        path = "v2/auth/r/orders"


        print(self.BASE_URL + path)
        print(nonce)


        headers = self._headers(path, nonce, rawBody)

        print(headers)
        print(rawBody)


        print("requests.post("+self.BASE_URL + path + ", headers=" + str(headers) + ", data=" + rawBody + ", verify=True)")
        r = requests.post(self.BASE_URL + path, headers=headers, data=rawBody, verify=True)

        if r.status_code == 200:
          return r.json()
        else:
          print r.status_code
          print r
          return ''

print BitfinexClient().active_orders()

Authentication is done using an API key and a secret. To generate this pair, go to the API Access page.

As an example of how to authenticate, we can look at the "account_infos" endpoint.
Take the example payload above.

These are encoded as HTTP headers named:

  • bfx-nonce
  • bfx-apikey
  • bfx-signature

NOTE

Make sure that the header of the request contains the "content-type" property set to application/json

Nonce

The nonce provided must be strictly increasing.

REST CALCULATION ENDPOINTS

REST AUTHENTICATED ENDPOINTS

Authenticated Endpoints