Bitvavo API Documentation

website·Indexed 40 days ago

https://docs.bitvavo.com/releases/v2.2.1/

Comprehensive documentation for the Bitvavo API ecosystem, including the Exchange REST API, Exchange WebSocket API, FIX API, Market Data Pro WebSocket API, and Account Management REST API for institutional users.

Tokens
22K
Snippets
75
Records
145
Agent score
14%

What's inside Bitvavo

  1. Overview of Bitvavo API offerings

    Bitvavo provides several APIs for automated trading, real-time market data, and account management. All APIs use HMAC-SHA256 signatures for authentication, though the signing process varies by protocol (REST signs each request, WebSocket signs an authentication message, and FIX signs the Logon message).

    Available APIs include:

    • Exchange REST API: Synchronous request-response for order management, account queries, and historical data.
    • Exchange WebSocket API: Event-driven for real-time market data and account events.
    • FIX API: Low-latency, session-based protocol for high-frequency and institutional trading.
    • Market Data Pro WebSocket API: High-throughput, full-depth real-time market data streams.
    • Account Management REST API: Institutional tool for managing multiple accounts and consolidated balances.
    • Subaccounts REST API: Access to balances and transaction history for individual subaccounts.
  2. Retrieve market information

    Use the GET /markets public endpoint to return information about one or all markets. Use the market query parameter to specify a single market. Authenticating the request provides a higher rate limit. Rate limit weight: 1.
    from python_bitvavo_api.bitvavo import Bitvavo
    
    bitvavo = Bitvavo()
    response = bitvavo.markets({})
    for market in response:
      print(market)
  3. Retrieve multiple orders

    Get information about multiple orders using GET /orders. This is a private endpoint. Rate limit weight: 5.

    Parameters:

    • market (query, required): The market to query.
    • limit (query, optional): Max number of orders to return.
    • start / end (query, optional): Unix timestamps for the time range.
    • orderIdFrom / orderIdTo (query, optional): Order identifiers to bound the results.
    from python_bitvavo_api.bitvavo import Bitvavo
    
    bitvavo = Bitvavo({
        'APIKEY': '<APIKEY>',
        'APISECRET': '<APISECRET>'
    })
    response = bitvavo.getOrders('BTC-EUR', {})
    for item in response:
      print(item)
  4. Manage orders via Exchange WebSocket API

    The Exchange WebSocket API allows for retrieving, canceling, and atomically clearing orders. Most of these actions require authentication.

    • Get orders: Returns information about multiple orders. (Weight: 5)
    • Cancel orders: Cancels multiple orders. Weight is 25 if market is specified, otherwise 100.
    • Atomic cancel orders: Cancels all open buy/sell orders in a specific market as a single atomic request. (Weight: 100)
    • Cancel orders after: Sets a countdown timer for automatic cancellation of a group of open orders. (Weight: 5). Only one group can be created unless enabled by Bitvavo support.
  5. Retrieve asset data

    Use the GET /assets public endpoint to return information about specified assets. If the symbol query parameter is omitted, all supported assets are returned. Authenticating the request provides a higher rate limit. Rate limit weight: 1.
    from python_bitvavo_api.bitvavo import Bitvavo
    
    bitvavo = Bitvavo()
    response = bitvavo.assets({})
    for asset in response:
      print(asset)
  6. Retrieve market and fee data via Exchange WebSocket API

    Access public and private market data. Some endpoints are public, while fee-related endpoints require authentication.

    • Get markets: Information about one or all markets. (Weight: 1)
    • Get asset data: Information about specified assets. (Weight: 1)
    • Get server time: Returns current Unix timestamp of Bitvavo servers. (Weight: 1)
    • Get account fees: Returns current trading fees based on Category A volume. (Weight: 1, Auth required)
    • Get market fees: Returns trading fees for a specific market category. (Weight: 1, Auth required)
  7. Use WS Market Data Pro for high-fidelity order books

    The WS Market Data Pro API provides non-conflated Level 2 (L2) market data with sequence numbering. It is designed for users needing real-time, full-fidelity data and automatic detection of missed updates. It is approximately 47.5ms faster than the standard WebSocket API and provides significantly higher message frequency (~9.1 messages per 100ms vs 1 message per 100ms).
  8. Authenticate Bitvavo WebSocket API connection

    To authenticate a WebSocket connection to wss://ws.bitvavo.com/v2/, you must send an authenticate action containing a signature created via HMAC-SHA256.

    Signature Generation Process:

    1. Concatenate the timestamp (Unix milliseconds), the HTTP method (e.g., 'GET'), and the path (e.g., '/v2/websocket') without delimiters.
    2. Encode this concatenated string using HMAC-SHA256 with your API secret as the key.
    3. The resulting signature must be hex-encoded.

    Authentication Message Parameters:

    • action: Must be authenticate.
    • key: Your Bitvavo API key.
    • signature: The hex-encoded HMAC-SHA256 signature.
    • timestamp: The Unix timestamp in milliseconds used to create the signature.
    • window (optional): Time window in milliseconds for request validity. Default is 10000, maximum is 60000.
    import hashlib
    import hmac
    import json
    import websocket
    import time
    
    class BitvavoWebSocketClient:
        def __init__(self, api_key: str, api_secret: str, access_window: int = 10000):
            self.api_key = api_key
            self.api_secret = api_secret
            self.access_window = access_window
            self.endpoint = 'wss://ws.bitvavo.com/v2/'
            self.request_id = 0
            self.ws = None
        
        def authenticate(self):
            timestamp = int(time.time() * 1000)
            body = {
              'key': self.api_key,
              'signature': self.create_signature(timestamp),
              'timestamp': timestamp,
              'window': self.access_window,
            }
            self.call_action(action='authenticate', body=body)
        
        def create_signature(self, timestamp: int):
            # Concatenate timestamp + method + path
            string = str(timestamp) + 'GET' + '/v2/websocket'
            signature = hmac.new(self.api_secret.encode('utf-8'), string.encode('utf-8'), hashlib.sha256).hexdigest()
            return signature
        
        def call_action(self, action: str, body: dict):
            request_id = self.request_id
            self.request_id += 1
            body['action'] = action
            body['requestId'] = request_id
            self.send_message(body)
        
        def send_message(self, message: dict):
            if self.ws is None:
                self.ws = websocket.create_connection(self.endpoint)
            self.ws.send(json.dumps(message))
  9. Request API rate limit increases

    Users requiring higher volume trading can request an increase in their API key rate limits by contacting the Bitvavo Support Team and specifying the expected trading volume.
  10. Authenticate Exchange REST API requests

    All requests to the Bitvavo REST API must be authenticated using a signature passed in the HTTP headers. The signature is an HMAC-SHA256 hex-encoded string created by concatenating the timestamp, HTTP method, API path, and request body (empty string for GET requests) without a delimiter, using the API secret as the key.

    Required Headers

    • Bitvavo-Access-Key: Your API Key.
    • Bitvavo-Access-Timestamp: Unix timestamp in milliseconds.
    • Bitvavo-Access-Signature: HMAC-SHA256 hex-encoded string.

    Optional Header

    • Bitvavo-Access-Window: Execution timeout in ms (Default: 10000, Max: 60000).

    Signature Construction

    Concatenate: timestamp + method + path + body Example values:

    • timestamp: 1548172481125
    • method: POST
    • path: /v2/order
    • body: {"market":"BTC-EUR","side":"buy","price":"5000","amount":"1.23","orderType":"limit"}
  11. Synchronize a local order book using WS Market Data Pro API

    To maintain a synchronized local order book using the WS Market Data Pro API, follow this sequence:

    1. Subscribe to updates: Connect to wss://ws-mdpro.bitvavo.com/v2/ and subscribe to the book channel for a specific market (e.g., BTC-EUR). You will receive book events containing startMdSeqNo and endMdSeqNo.
    2. Get a snapshot: Request a current order book snapshot using the getBook action. Save the mdSeqNo from the response to establish your initial local state.
    3. Align sequence numbers: Compare the snapshot's mdSeqNo with the startMdSeqNo of the next incoming book event.
      • If startMdSeqNo ≤ snapshot mdSeqNo: Skip the event.
      • If startMdSeqNo == snapshot mdSeqNo + 1: Start applying updates.
    4. Apply updates: Update local bids and asks. After each event, update your local mdSeqNo to the event's endMdSeqNo.

    Recovery: If a gap in sequence numbers is detected (where startMdSeqNo is not exactly one higher than your local mdSeqNo), discard the local order book, re-subscribe to the channel, and request a new snapshot.

    // Step 1: Subscribe to book updates
    {
      "action": "subscribe",
      "channels": [
        {
          "name": "book",
          "markets": ["BTC-EUR"]
        }
      ]
    }
    
    // Step 2: Request snapshot
    {
      "action": "getBook",
      "requestId": 1,
      "market": "BTC-EUR",
      "depth": 1000
    }
  12. Authenticate Exchange WebSocket API

    The Exchange WebSocket API requires authentication for trading, transfers, and account management. To authenticate a connection, you must first create a signature and then send an authentication action message to the WebSocket API.