Introduction

Order Book WebSocket API. This API allows real-time access to order book updates for specific instruments and currencies.

WebSocket Endpoint

wss://api.doppapp.com/v1/public/ws/get_order_book?currency={currency}&instrument_name={instrument_name}

Query Parameters

The WebSocket connection accepts the following optional query parameter:

  • currency: Filter updates by base currency.
  • instrument_name: Filter updates by instrument name.

Message Format

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

{
     "instrument_id": "0x06ab5246259e470647b5b2a471acca3889fc89667cebd10b9d440cafbee65d40",
     "strike_price": 67000.0,
     "base_currency": "BTC",
     "expiration_date": 1721980800,
     "side": "CALL",
     "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
     }
}

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"
    instrument_name = "BTC-26JUL24-67000-C"
    uri = f"wss://api.doppapp.com/v1/public/ws/get_order_book?currency={currency}&instrument_name={instrument_name}"

    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(main())

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 instrument name)
  • 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.