Getting started overview

Integrating with the Bitfinex API involves a sequence of steps, beginning with account creation and progressing to the generation of API credentials necessary for authenticated requests. The Bitfinex platform offers both REST and WebSocket APIs, enabling access to market data, trading functionalities, and account management. This guide focuses on the initial setup required to make a successful API call, providing a foundational understanding for further development.

The core process includes:

  1. Registering a Bitfinex account.
  2. Completing necessary verification steps (Know Your Customer/Anti-Money Laundering).
  3. Generating API keys and secrets within the account settings.
  4. Configuring API key permissions.
  5. Making an authenticated request using the generated credentials.

Bitfinex provides SDKs for several programming languages, including Node.js and Python, which can simplify API interaction by handling authentication and request formatting. While SDKs are available, understanding the underlying API authentication mechanism is beneficial for troubleshooting and custom implementations.

Quick Reference Table

Step What to do Where
1. Account Registration Create a new Bitfinex account. Bitfinex signup page
2. Verification Complete KYC/AML requirements. Bitfinex account verification section
3. API Key Generation Generate API key and secret. Bitfinex API Keys page
4. Permissions Configuration Set appropriate API key permissions. Bitfinex API Keys page
5. First Request Execute an authenticated API call. Your development environment

Create an account and get keys

To begin using the Bitfinex API, a registered account is required. Bitfinex, like many cryptocurrency exchanges, adheres to Anti-Money Laundering (AML) and Know Your Customer (KYC) regulations, which necessitate identity verification for most functionalities, including API access for trading. The specific verification level required for API access may vary depending on the desired permissions and geographical location, as detailed in the Bitfinex verification levels documentation.

Account Registration

  1. Navigate to the Bitfinex signup page.
  2. Provide a valid email address and create a strong password.
  3. Agree to the terms of service and privacy policy.
  4. Complete the email verification process by clicking the link sent to your registered email address.

Identity Verification (KYC/AML)

After initial registration, it is generally necessary to complete identity verification. This process typically involves submitting personal information and identification documents. The Bitfinex platform guides users through the specific requirements based on their chosen verification level, which impacts daily withdrawal limits and access to certain features. For API usage that involves trading or withdrawals, higher verification tiers are usually mandatory.

API Key Generation

Once your account is set up and any required verification is complete, you can generate API keys:

  1. Log in to your Bitfinex account.
  2. Navigate to the API Keys section, usually found under 'Manage Account' or 'Security'. The direct link is typically Bitfinex API Keys page.
  3. Click on 'Generate New Key'.
  4. You will be presented with an API Key and an API Secret. The API Secret is shown only once upon generation; it is crucial to save this securely, as it cannot be retrieved later. If lost, a new key pair must be generated.
  5. Configure the permissions for your new API key. Bitfinex allows granular control over what an API key can do, such as 'Read account info', 'Trade', 'Deposit', or 'Withdraw'. For a first test, 'Read account info' is often sufficient and carries lower risk. Ensure you grant only the necessary permissions for your intended use case.
  6. Confirm the generation, often requiring two-factor authentication (2FA) if enabled on your account.

For security, it is recommended to use separate API keys for different applications or purposes and to restrict their permissions to the minimum necessary. Many API providers, including Bitfinex, suggest IP whitelist restrictions for production environments, limiting API access to specific IP addresses.

Your first request

Making your first authenticated request to the Bitfinex API involves using the generated API Key and Secret to sign your request. Bitfinex's REST API uses a signature-based authentication scheme, which involves hashing the request payload with your API Secret. The general process described by Bitfinex API authentication documentation is similar to HMAC (Hash-based Message Authentication Code) mechanisms, a common practice for securing API calls, also employed by services like Stripe's API authentication.

Authentication Details

For private endpoints (those requiring authentication), Bitfinex uses the following headers:

  • bfx-nonce: A unique, incrementally increasing integer (or timestamp in milliseconds) for each request to prevent replay attacks.
  • bfx-apikey: Your generated API Key.
  • bfx-signature: The HMAC-SHA384 signature of the request payload.

The payload for signing typically consists of the request path, nonce, and request body (if a POST request). The exact string to sign is /api/v2/path_to_endpoint + bfx-nonce + request_body_as_json_string.

Example using Python SDK

Using an SDK simplifies the authentication process. Here's an example using the official Bitfinex Python SDK for REST API v2 to fetch account information:


import os
from bfxapi import Client

# Replace with your actual API Key and Secret
API_KEY = os.environ.get("BFX_API_KEY")
API_SECRET = os.environ.get("BFX_API_SECRET")

# Initialize the client
bfx = Client(API_KEY=API_KEY, API_SECRET=API_SECRET)

async def get_account_info():
    try:
        # Fetch account wallets
        wallets = await bfx.rest.get_wallets()
        print("Wallets:", wallets)

        # Fetch account funding info (example of another private endpoint)
        funding_info = await bfx.rest.get_funding_info()
        print("Funding Info:", funding_info)

    except Exception as e:
        print(f"An error occurred: {e}")

import asyncio
asyncio.run(get_account_info())

Before running this code:

  1. Install the SDK: pip install bfxapi
  2. Set environment variables: export BFX_API_KEY='your_api_key' and export BFX_API_SECRET='your_api_secret'.
  3. Ensure your API key has the necessary 'Read' permissions for wallets and funding information.

Example using Node.js SDK

For Node.js developers, the Bitfinex Node.js SDK provides a similar abstraction:


const { RESTv2 } = require('bfx-api-node-rest');
const API_KEY = process.env.BFX_API_KEY;
const API_SECRET = process.env.BFX_API_SECRET;

const rest = new RESTv2({
  apiKey: API_KEY,
  apiSecret: API_SECRET
});

async function getAccountInfo() {
  try {
    const wallets = await rest.wallets();
    console.log('Wallets:', wallets);

    const fundingInfo = await rest.fundingInfo();
    console.log('Funding Info:', fundingInfo);

  } catch (e) {
    console.error('An error occurred:', e);
  }
}

getAccountInfo();

Before running this code:

  1. Install the SDK: npm install bfx-api-node-rest
  2. Set environment variables: export BFX_API_KEY='your_api_key' and export BFX_API_SECRET='your_api_secret'.
  3. Verify API key permissions for 'Read' access.

Common next steps

After successfully making your first API call, you can explore various other functionalities offered by the Bitfinex API:

  • Market Data: Access real-time and historical market data for various trading pairs, including tickers, order books, and trades via Bitfinex public REST endpoints.
  • Trading: Place, cancel, and manage orders for spot, margin, and derivatives trading. This requires more extensive API key permissions.
  • Account Management: Retrieve detailed account balances, funding information, and transaction history.
  • WebSockets: For real-time updates on market data and private account events, consider integrating with the Bitfinex WebSocket API. WebSockets provide a persistent connection, reducing latency compared to repeated REST calls.
  • Error Handling: Implement robust error handling in your application to manage API rate limits, authentication failures, and other potential issues.
  • Security Best Practices: Review and implement best practices for API key management, such as IP whitelisting, regularly rotating keys, and securing your development environment.

Troubleshooting the first call

Encountering issues during your initial API call is common. Here are some troubleshooting steps:

  • Invalid API Key/Secret: Double-check that your API Key and Secret are copied correctly. Remember that the Secret is only shown once. If you suspect an error, generate a new key pair and update your code.
  • Incorrect Permissions: Ensure your API key has the necessary permissions for the endpoint you are trying to access. For example, 'Read account info' is needed for fetching wallets, while 'Write' permissions are required for placing orders. Review the Bitfinex API key permissions guide.
  • Nonce Issues: The bfx-nonce header must be a unique, strictly increasing integer (typically a timestamp in milliseconds) for each authenticated request. If you send the same nonce twice or a nonce that is lower than a previously used one, the API will reject the request. SDKs usually handle this automatically.
  • Signature Mismatch: The bfx-signature must be correctly generated using HMAC-SHA384. This is a common source of errors for manual implementations. Ensure the payload string being signed is accurate (path + nonce + body) and that the API Secret is used correctly as the HMAC key. Using an official SDK is highly recommended to avoid signature calculation errors.
  • Rate Limits: Bitfinex, like many platforms, imposes API rate limits to prevent abuse. If you make too many requests too quickly, your requests may be temporarily blocked. Check the HTTP response headers for rate limit information (e.g., X-RateLimit-Limit, X-RateLimit-Remaining).
  • Network or Firewall Issues: Verify that your network connection is stable and that no firewalls are blocking outgoing requests to api.bitfinex.com.
  • Endpoint Path: Ensure you are using the correct API endpoint path for the desired operation. Refer to the Bitfinex API reference documentation for exact paths.