> ## Documentation Index
> Fetch the complete documentation index at: https://docs.struct.to/llms.txt
> Use this file to discover all available pages before exploring further.

# Trader-token PnL

> Stream realized PnL per trader and token.

> [!NOTE]
>
> **Room ID:** `trader_token_pnl` \
> **Endpoint:** `wss://staging-api.struct.to/ws`

Live realized PnL for a trader in a single token, per timeframe. Each message is the full row: counts, volumes, average prices, fees, realized PnL, and first/last trade times.

## Subscribe

Match any of `traders` or `tokens`, capped at 500 combined.

### Filters

| Filter | Type | Required | Description |
| - | - | - | - |
| `chain` | `string` | No\* | Chain name: `solana`, `bnb`, `base`, `ethereum`, `robinhood`, `arc` |
| `chain_id` | `integer` | No\* | Chain id: `-1`, `56`, `8453`, `1`, `4663`, `5042` |
| `traders` | `string[]` | No | Trader wallet addresses |
| `tokens` | `string[]` | No | Token addresses |
| `timeframes` | `string[]` | No | `1d`, `3d`, `7d`, `14d`, `30d`, `lifetime`. Empty = all |
| `subscribe_all` | `boolean` | No | Receive every trader-token PnL update |

Provide either `chain` or `chain_id`. Do not send both.

### Example

```json theme={null}
{
  "type": "join_room",
  "payload": {
    "room_id": "trader_token_pnl"
  }
}
```

```json theme={null}
{
  "type": "room_message",
  "payload": {
    "room_id": "trader_token_pnl",
    "message": {
      "action": "subscribe",
      "chain": "solana",
      "traders": [
        "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
      ],
      "tokens": [
        "TokenMint111111111111111111111111111111111"
      ]
    }
  }
}
```

## Events

The room emits `trader_token_pnl_update`. Pick **Response (Long)** or **Response (Short)** in the right-hand panel. WebSocket defaults to short. See [long and short field names](https://docs.struct.to/api-reference/response-format.md#long-and-short-field-names).

```json Response (Long) theme={null}
{
  "type": "trader_token_pnl_update",
  "room_id": "trader_token_pnl",
  "data": {
    "chain_id": -1,
    "trader": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
    "token_address": "TokenMint111111111111111111111111111111111",
    "timeframe": "7d",
    "buy_count": 8,
    "sell_count": 5,
    "total_bought": 680000,
    "total_sold": 420000,
    "buy_native": 80.4,
    "sell_native": 103.2,
    "buy_usd": 12000,
    "sell_usd": 15400,
    "pnl_usd": 3400,
    "pnl_native": 22.8,
    "avg_buy_price_native": 0.00011824,
    "avg_buy_price_usd": 0.01765,
    "avg_sell_price_native": 0.00024571,
    "avg_sell_price_usd": 0.03667,
    "opening_price_native": 0.00011,
    "opening_price_usd": 0.0164,
    "closing_price_native": 0.00024571,
    "closing_price_usd": 0.03667,
    "high_price_native": 0.00028,
    "high_price_usd": 0.0416,
    "low_price_native": 9e-05,
    "low_price_usd": 0.0134,
    "avg_buy_market_cap_native": 118240,
    "avg_buy_market_cap_usd": 17650000,
    "avg_sell_market_cap_native": 245710,
    "avg_sell_market_cap_usd": 36670000,
    "total_priority_fees": 0.014,
    "total_bot_fees": 0.008,
    "total_tip_amount": 0.002,
    "first_trade_at": 1705000000000,
    "last_trade_at": 1710000000000,
    "last_pool": "7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj",
    "first_tx_hash": "5xFirstTx11111111111111111111111111111111111",
    "timestamp": 1710000000000
  }
}
```

```jsonc Response (Short) theme={null}
{
  "type": "trader_token_pnl_update",
  "room_id": "trader_token_pnl",
  "data": {
    "ci": -1,
    "tr": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
    "ta": "TokenMint111111111111111111111111111111111",
    "tf": "7d",
    "bc": 8,
    "sc": 5,
    "tbo": 680000,
    "tso": 420000,
    "bn": 80.4,
    "sn": 103.2,
    "bu": 12000,
    "su": 15400,
    "pu": 3400,
    "pnn": 22.8,
    "abpn": 0.00011824,
    "abpu": 0.01765,
    "aspn": 0.00024571,
    "aspu": 0.03667,
    "opn": 0.00011,
    "opu": 0.0164,
    "clpn": 0.00024571,
    "clpu": 0.03667,
    "hpn": 0.00028,
    "hpu": 0.0416,
    "lpn": 9e-05,
    "lpu": 0.0134,
    "abmcn": 118240,
    "abmcu": 17650000,
    "asmcn": 245710,
    "asmcu": 36670000,
    "tpf": 0.014,
    "tbf": 0.008,
    "tta": 0.002,
    "fta": 1705000000000,
    "lta": 1710000000000,
    "lpo": "7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj",
    "fth": "5xFirstTx11111111111111111111111111111111111",
    "t": 1710000000000
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.