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

# Activity Feed WebSocket

> Real-time trade activity stream.

The Activity WebSocket provides live trade updates filtered by market or user.

***

## Connection

```
wss://api.orica.markets/ws/activity
```

After connecting, you must send a filter message to specify what activity to receive.

***

## Filter Types

> [tab] Market Filter
>
> Receive trades for a specific market.
>
> ```json theme={"dark"}
> {
>   "type": "market",
>   "address": "ABC123..."
> }
> ```

> [tab] User Filter
>
> Receive trades for a specific user.
>
> ```json theme={"dark"}
> {
>   "type": "user",
>   "address": "User456..."
> }
> ```

> [!WARNING]
>
> You must send a filter within 30 seconds of connecting or the connection will be closed.

***

## Message Types

### Server Messages

> [tab] history
>
> Sent after filter is set with recent trades.
>
> ```json theme={"dark"}
> {
>   "type": "history",
>   "data": [
>     {
>       "signature": "5K7x...",
>       "market_address": "ABC123...",
>       "user_address": "User456...",
>       "trade_type": "buy",
>       "outcome_index": 0,
>       "amount_usdc": 100.50,
>       "shares": 9850,
>       "price": 0.0102,
>       "market_cap_at_trade": 1250.75,
>       "timestamp": 1704067200,
>       "fees_paid_usdc": 1.71
>     }
>   ]
> }
> ```

> [tab] trade
>
> Sent when a new trade occurs matching your filter.
>
> ```json theme={"dark"}
> {
>   "type": "trade",
>   "data": {
>     "signature": "5K7x...",
>     "market_address": "ABC123...",
>     "user_address": "User456...",
>     "trade_type": "buy",
>     ...
>   }
> }
> ```

> [tab] pong
>
> Response to client ping.
>
> ```json theme={"dark"}
> {
>   "type": "pong"
> }
> ```

> [tab] error
>
> Error message.
>
> ```json theme={"dark"}
> {
>   "type": "error",
>   "message": "Invalid filter"
> }
> ```

### Client Messages

> [tab] history
>
> Request additional history with filters.
>
> ```json theme={"dark"}
> {
>   "action": "history",
>   "trade_type": "buy",
>   "limit": 50,
>   "offset": 0
> }
> ```
>
> * `trade_type`: Optional filter (`buy`, `sell`, `redeem`)
> * `limit`: Number of trades (default 50, max 1000)
> * `offset`: Pagination offset

> [tab] ping
>
> Keep connection alive.
>
> ```json theme={"dark"}
> {
>   "action": "ping"
> }
> ```

***

## Connection Example

```typescript theme={"dark"}
const ws = new WebSocket("wss://api.orica.markets/ws/activity");

ws.onopen = () => {
  // Filter by market
  ws.send(JSON.stringify({
    type: "market",
    address: "ABC123..."
  }));
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  
  switch (message.type) {
    case "history":
      console.log(`Received ${message.data.length} historical trades`);
      message.data.forEach(trade => {
        console.log(`${trade.trade_type}: ${trade.amount_usdc} USDC`);
      });
      break;
      
    case "trade":
      console.log("New trade:", message.data);
      // Update UI with new trade
      break;
      
    case "error":
      console.error("Error:", message.message);
      break;
  }
};

// Request only buy trades
ws.send(JSON.stringify({
  action: "history",
  trade_type: "buy",
  limit: 100
}));
```

***

## Trade Data Structure

| Field | Type | Description |
| - | - | - |
| `signature` | `string` | Solana transaction signature |
| `market_address` | `string` | Market where trade occurred |
| `user_address` | `string` | Trader's wallet |
| `trade_type` | `string` | `buy`, `sell`, or `redeem` |
| `outcome_index` | `number` | Outcome traded |
| `amount_usdc` | `number` | USDC amount |
| `shares` | `number` | Shares traded |
| `price` | `number` | Price per share |
| `market_cap_at_trade` | `number` | Market cap at trade time |
| `timestamp` | `number` | Unix timestamp |
| `fees_paid_usdc` | `number` | Fees paid |

***

## Use Cases

> [card] Trade Feed
>
> Display live trades for a market in a dashboard.

> [card] User History
>
> Track a user's trading activity in real-time.

> [card] Analytics
>
> Build real-time analytics on trading patterns.

> [card] Alerts
>
> Trigger notifications on specific trade events.


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