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

# Completed Trades

> Subscribe to completed trades streams over the /ws multiplex WebSocket.

<Warning>
  **Not served by the public endpoint today.** A `subscribe` with this type is answered with
  `{"type":"error","message":"Unsupported subscription: completed_trades"}` on `wss://api.hypedexer.com/ws`
  (checked 19 September 2026). Use the REST equivalent below, or
  [contact us](https://t.me/EnigmaValidatorCommunity/1) if you need this stream.
</Warning>

REST equivalent: [`GET /completed-trades/`](/api-reference/completed-trades/list-completed-trades), with `start_time` and `end_time`.

# Completed Trades

The completed trades stream uses the **multiplex WebSocket endpoint**:

```text theme={null}
wss://api.hypedexer.com/ws
```

All subscriptions go through `/ws`.\
You authenticate using `X-API-Key` during the WebSocket handshake.

***

## 1. Subscription schema

All client messages follow the same structure:

```json theme={null}
{
  "method": "subscribe | unsubscribe | list_subscriptions",
  "subscription": {
    "type": "completed_trades",
    "user": "optional user address filter"
  }
}
```

### Available filters

For `type = "completed_trades"` the server currently supports:

* `user` *(optional, string)* → only stream completed trades for this user address

If `user` is omitted, you receive all completed trades.

***

## 2. Subscribe: All completed trades

### Client message

```json theme={null}
{
  "method": "subscribe",
  "subscription": {
    "type": "completed_trades"
  }
}
```

### Example server event

```json theme={null}
{
  "type": "completed_trades",
  "count": 1,
  "data": [
    {
      "user": "0x32a71f839c54b4e5290d2abefccb9094529faacc",
      "coin": "xyz:XYZ100",
      "direction": "short",
      "start_time": "2025-11-21T17:35:16.266000",
      "end_time": "2025-11-21T17:35:18.714000",
      "duration_s": 2.0,
      "entry_price": 24324.0,
      "exit_price": 24325.0,
      "size_open": 0.0034,
      "size_close": 0.0034,
      "pnl_realized": -0.0034,
      "pnl_percentage": -0.0041111659266568,
      "leverage_type": "cross",
      "leverage_value": 0.0,
      "margin_used": 0.0,
      "position_value": 82.7016,
      "funding_all_time": 0.0,
      "funding_since_open": 0.0,
      "liquidation_price": 0.0,
      "max_leverage": 0.0,
      "total_fills": 2,
      "total_fees": 0.142911,
      "avg_fill_price": 24324.5,
      "first_fill_time": "2025-11-21T17:35:16.266000",
      "last_fill_time": "2025-11-21T17:35:18.714000",
      "total_volume": 165.4066,
      "counterparty": "",
      "counterparty_oid": "0",
      "trade_id": "trade_xyz:XYZ100_3af1dd6e",
      "close_hash": "0xf23dcae0f9265cfdf3b7042febd2100206ea00c694297bd096067633b82a36e8",
      "created_at": "2025-11-21T17:35:19.474000"
    }
  ]
}
```

***

## 3. Subscribe: Completed trades for a specific user

### Client message

```json theme={null}
{
  "method": "subscribe",
  "subscription": {
    "type": "completed_trades",
    "user": "0x8fcc8f55d7a8cdaee770a9e4112725d4a2c60492"
  }
}
```

***

## 4. Unsubscribe

To stop receiving completed trades on this connection:

```json theme={null}
{
  "method": "unsubscribe",
  "subscription": {
    "type": "completed_trades"
  }
}
```

Example confirmation:

```json theme={null}
{
  "type": "subscription_removed",
  "subscription": {
    "type": "completed_trades",
    "status": "inactive"
  },
  "active_subscriptions": []
}
```

***

## 5. wscat examples

### All completed trades

```bash theme={null}
wscat -H "X-API-Key: <your_api_key>" \
  -c wss://api.hypedexer.com/ws

# then paste:
# {"method":"subscribe","subscription":{"type":"completed_trades"}}
```

### Completed trades for a user

```bash theme={null}
wscat -H "X-API-Key: <your_api_key>" \
  -c wss://api.hypedexer.com/ws

# then paste:
# {"method":"subscribe","subscription":{"type":"completed_trades","user":"0x8fcc8f55d7a8cdaee770a9e4112725d4a2c60492"}}
```


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