Skip to main content
Subscribe to real-time user position updates. Account-specific channel. WebSocket URL: wss://api.hotstuff.trade/ws Channel: positions

Parameters

ParameterTypeRequiredDescriptionExample
jsonrpcstringYesJSON-RPC version"2.0"
idstringYesRequest identifier for tracking"1"
methodstringYesAction to perform"subscribe" or "unsubscribe"
channelstringYesChannel name"positions"
userstringYesUser wallet address"0xxxx"

Supported Methods

  • subscribe - Subscribe to user position updates
  • unsubscribe - Unsubscribe from user position updates

Authentication

This endpoint requires a valid user wallet address to receive account-specific position updates.

Example Request

{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "positions",
    "user": "0xxxx"
  }
}

Example Response

{
    "jsonrpc": "2.0",
    "method": "event",
    "params": {
        "channel": "positions@0x42C183edba036906447372a7c81Eb89D0B9f2175",
        "data": {
            "account": "0x42C183edba036906447372a7c81Eb89D0B9f2175",
            "instrument_id": 10,
            "instrument": "TSLA-PERP",
            "position_type": "oneWay",
            "old_position": {
                "size": 0.833,
                "entry_price": 420
            },
            "position_side_updated": "BOTH",
            "realized_pnl": 0,
            "legs": [
                {
                    "side": "BOTH",
                    "size": 0.833,
                    "entry_price": 420,
                    "leverage": {
                        "type": "isolated",
                        "value": 10,
                        "margin": "53.477383"
                    },
                    "position_value": 349.86
                }
            ],
            "block_timestamp": 1770853898179
        }
    }
}

WebSocket Client Examples

Python

import websocket
import json

def on_message(ws, message):
    print(f"Received: {message}")

def on_open(ws):
    subscribe_msg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "positions",
            "user": "0xxxx"
        }
    }
    ws.send(json.dumps(subscribe_msg))

ws = websocket.WebSocketApp("wss://api.hotstuff.trade/ws",
                          on_message=on_message,
                          on_open=on_open)
ws.run_forever()

JavaScript

const ws = new WebSocket('wss://api.hotstuff.trade/ws');

ws.onopen = function() {
    const subscribeMsg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "positions",
            "user": "0xxxx"
        }
    };
    ws.send(JSON.stringify(subscribeMsg));
};

ws.onmessage = function(event) {
    console.log('Received:', event.data);
};