> For the complete documentation index, see [llms.txt](https://noodles-finance.gitbook.io/docs.noodles.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://noodles-finance.gitbook.io/docs.noodles.fi/websocket/room-trades.md).

# Room TRADE

## Overview

The TRADES room provides real-time trading transaction data for specific coins. Subscribe to this room to receive live trade information including buy/sell/add\_liquidity/remove\_liquidity actions, amounts, prices, and transaction details.

## Subscription

**See:** [WebSocket Setup](/docs.noodles.fi/websocket/websocket-setup.md) for general WebSocket connection and management details.

### Client Subscription Message

```json
{
  "type": "subscribe",
  "room": "TRADES",
  "data": {
    "coin": "0x2::sui::SUI"
  }
}
```

## Server Response Data Format

```json
{
  "type": "data",
  "channel": "TRADES-0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
  "room": "TRADES",
  "data": [
    {
      "action": "buy",
      "amount_in": 272.00531441,
      "amount_out": 687.537791,
      "from_coin_ident": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
      "from_coin_name": "Sui",
      "from_coin_symbol": "SUI",
      "id": 483579346,
      "price": 0.998,
      "protocol": "cetus-clmm",
      "sender": "0x7744ada2af3b150820b7bababee72b393e5c279f8d196064c3825b561ca7c7fa",
      "source": "cetus",
      "timestamp": 1761018726408,
      "to_coin_ident": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
      "to_coin_name": "USDC",
      "to_coin_symbol": "USDC",
      "tx_digest": "9ywRPpKdJ2gReSxHYbAazNY1QpzBsCSt3gy51bvBE4mx",
      "usd_value": 687.63
    },
    {
      "action": "buy",
      "amount_in": 100,
      "amount_out": 252.790872,
      "from_coin_ident": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
      "from_coin_name": "Sui",
      "from_coin_symbol": "SUI",
      "id": 483579347,
      "price": 0.998,
      "protocol": "magma-clmm",
      "sender": "0x8cfc595dcf6fcd6c1b10e6746b74d440a8118a85a196c06b084e1e3b4b0d703b",
      "source": null,
      "timestamp": 1761018726408,
      "to_coin_ident": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
      "to_coin_name": "USDC",
      "to_coin_symbol": "USDC",
      "tx_digest": "9ywRPpKdJ2gReSxHYbAazNY1QpzBsCSt3gy51bvBE4mx",
      "usd_value": 252.8
    }
  ]
}
```

## Data Fields

| Field              | Type   | Description                                                                                          |
| ------------------ | ------ | ---------------------------------------------------------------------------------------------------- |
| `action`           | string | Trade action: `buy` or `sell`. Liquidity action: `join` (add liquidity) or `exit` (remove liquidity) |
| `amount_in`        | number | Input amount of tokens                                                                               |
| `amount_out`       | number | Output amount of tokens                                                                              |
| `from_coin_ident`  | string | Source coin identifier                                                                               |
| `from_coin_name`   | string | Source coin name                                                                                     |
| `from_coin_symbol` | string | Source coin symbol                                                                                   |
| `to_coin_ident`    | string | Destination coin identifier                                                                          |
| `to_coin_name`     | string | Destination coin name                                                                                |
| `to_coin_symbol`   | string | Destination coin symbol                                                                              |
| `id`               | number | Unique trade ID                                                                                      |
| `price`            | number | Trade price                                                                                          |
| `protocol`         | string | Protocol used (e.g., "cetus-clmm", "magma-clmm")                                                     |
| `sender`           | string | Wallet address of sender                                                                             |
| `source`           | string | Source exchange/platform                                                                             |
| `timestamp`        | number | Trade timestamp in milliseconds                                                                      |
| `tx_digest`        | string | Transaction digest/hash                                                                              |
| `usd_value`        | number | USD value of the trade                                                                               |

**Note**: With liquidity actions (`join` and `exit`):

* `amount_in` represents the amount of token `from_coin_ident` added/removed
* `amount_out` represents the amount of token `to_coin_ident` added/removed.

## Example Usage

### JavaScript

```javascript
const ws = new WebSocket('wss://ws.noodles.fi/ws/coin-update');

ws.onopen = function() {
    // Subscribe to SUI trades
    ws.send(JSON.stringify({
        type: 'subscribe',
        room: 'TRADES',
        data: {
            coin: '0x2::sui::SUI'
        }
    }));
};

ws.onmessage = function(event) {
    const message = JSON.parse(event.data);
    
    if (message.type === 'data' && message.room === 'TRADES') {
        const trades = message.data;
        trades.forEach(trade => {
            console.log(`${trade.action.toUpperCase()}: ${trade.amount_out} ${trade.to_coin_symbol} at $${trade.price}`);
            console.log(`USD Value: $${trade.usd_value}`);
            console.log(`Protocol: ${trade.protocol}`);
            console.log(`TX: ${trade.tx_digest}`);
        });
    }
};
```

### TypeScript

```typescript
interface TradeData {
  action: 'buy' | 'sell';
  amount_in: number;
  amount_out: number;
  from_coin_ident: string;
  from_coin_name: string;
  from_coin_symbol: string;
  to_coin_ident: string;
  to_coin_name: string;
  to_coin_symbol: string;
  id: number;
  price: number;
  protocol: string;
  sender: string;
  source: string | null;
  timestamp: number;
  tx_digest: string;
  usd_value: number;
}

client.onTradeData = (channel: string, trades: TradeData[]) => {
  trades.forEach(trade => {
    console.log(`New ${trade.action} trade:`, {
      pair: `${trade.from_coin_symbol}/${trade.to_coin_symbol}`,
      price: trade.price,
      amount: trade.amount_out,
      usdValue: trade.usd_value,
      protocol: trade.protocol
    });
  });
};

client.subscribe('TRADES', '0x2::sui::SUI');
```

## Unsubscription

### Client Unsubscription Message

```json
{
  "type": "unsubscribe",
  "room": "TRADES",
  "data": {
    "coin": "0x2::sui::SUI"
  }
}
```

> **See also:** [WebSocket Setup](/docs.noodles.fi/websocket/websocket-setup.md) for general WebSocket connection and management details.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://noodles-finance.gitbook.io/docs.noodles.fi/websocket/room-trades.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
