Introduction

Last User Trades by Instrument WebSocket API. This API allows real-time access to list all the latest trades depending on the currency updates for multiple instruments simultaneously, with optional filtering by currency.

WebSocket Endpoint

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

This endpoint provides updates for all last Trades matching the specified criteria.

Query Parameters

The WebSocket connection accepts the following optional query parameter:

  • wallet_address: Filter updates by wallet Address ID.
  • instrument_name: Filter updates by instrument name.

Message Format

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

[
  {
    "last_trades": [
      {
        "wallet_address": "string",
        "amount": 0,
        "base_currency": "string",
        "direction": "string",
        "fee": 0,
        "fee_currency": "string",
        "index_price": 0,
        "instrument_name": "string",
        "iv": 0,
        "liquidity": "string",
        "mark_price": 0,
        "order_id": 0,
        "order_type": "string",
        "price": 0,
        "tick_direction": 0,
        "timestamp": 0,
        "trade_direction": "string",
        "trade_id": "string",
        "trade_seq": 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():

    wallet_address = "test_wallet_address"
    instrument_name = "BTC-PERPETUAL"
    uri = f"wss://api.doppapp.com/v1/public/ws/get_user_trades_by_instrument?wallet_address={wallet_address}&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 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.