Introduction

List Order Books WebSocket API. This API allows real-time access to order book updates for multiple instruments simultaneously, with optional filtering by currency.

WebSocket Endpoint

wss://api.doppapp.comp.com/v1/public/ws/get_all_order_books?currency={currency}

This endpoint provides updates for all order books matching the specified criteria.

Query Parameters

The WebSocket connection accepts the following optional query parameter:

  • currency: Filter updates by base currency.

Message Format

The server sends messages in JSON format. Each message represents an order book update and has the following structure:

{
    "BTC-26JUL24-30000-P": [
        {
            "instrument_id": "0x06ab5246259e470647b5b2a471acca3889fc89667cebd10b9d440cafbee65d40",
            "strike_price": 30000.0,
            "base_currency": "BTC",
            "expiration_date": 1721980800,
            "side": "PUT",
            "mark_price": 0.04285714285714286,
            "best_bid_price": 0,
            "best_bid_amount": 0,
            "best_ask_price": 0,
            "best_ask_amount": 0,
            "bids_prices": [],
            "bids_amounts": [],
            "asks_prices": [],
            "asks_amounts": [],
            "bid_iv": 0,
            "ask_iv": 0,
            "greeks": {
                "delta": 0,
                "gamma": 0,
                "vega": 0,
                "theta": 0,
                "rho": 0
            }
        },
        ....
    ],
    "BTC-26JUL24-40000-C": [...]
}

Examples

Python

Here’s an example of how to connect to the WebSocket and receive updates using Python:

import websockets
import asyncio
import json

async def main():
    
    currency = "BTC"
    uri = f"wss://api.doppapp.comp.com/v1/public/ws/get_all_order_books?currency={currency}"

    async with websockets.connect(uri) as websocket:
        print("Connected to WebSocket")

        while True:
            try:
                message = await websocket.recv()
                data = json.loads(message)
                print(f"Received update: {data}")
            except websockets.exceptions.ConnectionClosed:
                print("WebSocket connection closed")
                break

asyncio.get_event_loop().run_until_complete(connect_to_orderbooks())

To run this example:

  1. Install the required library: pip install websockets
  2. Save the code to a file (e.g., main.py)
  3. Run the script: python main.py

Error Handling

The WebSocket may close the connection with specific codes in case of errors:

  • 1000: Normal closure
  • 1008: Policy violation (e.g., invalid filter)
  • 1011: Internal server error

Clients should be prepared to handle these closure codes and implement appropriate reconnection logic.

Rate Limiting

To prevent abuse, the API implements rate limiting. Clients that exceed the allowed number of connection attempts may be temporarily blocked. Implement exponential backoff in your client applications to handle rate limiting gracefully.