> For the complete documentation index, see [llms.txt](https://docs.outpoll.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.outpoll.com/api/futures-api/websockets/futures-market-data/trades.md).

# Trades

Real-time public trades and last traded price for futures pairs.

Use this stream for the recent-trades tape and the last traded price. Trades are delivered in small batches: each batch is a series of trade frames, oldest first, followed by one last-price frame.

## Endpoint

```
wss://futures-marketdata-service.outpoll.com/ws/trades/last
```

## Authentication

No authentication required.

## Message Envelope

The stream carries two frame shapes. Tell them apart by the keys: a trade frame has `id`; a last-price frame has `s`.

### Trade frame

| Field | Type    | Description                                            |
| ----- | ------- | ------------------------------------------------------ |
| `id`  | string  | Trade ID (of the newest fill in the frame)             |
| `pi`  | integer | Pair ID                                                |
| `p`   | number  | Trade price                                            |
| `v`   | number  | Trade size; for a merged frame, the total of its fills |
| `sd`  | string  | Taker side: `buy` or `sell`                            |
| `t`   | integer | Trade time, epoch ms                                   |

### Last-price frame

| Field | Type    | Description       |
| ----- | ------- | ----------------- |
| `s`   | integer | Pair ID           |
| `p`   | number  | Last traded price |

## Message Types

| Type                        | Direction       | Description                                                                                    |
| --------------------------- | --------------- | ---------------------------------------------------------------------------------------------- |
| `subscribe` / `unsubscribe` | Client → Server | Start or stop pairs                                                                            |
| Trade                       | Server → Client | One public trade: the fills of one taker side at one price and time, merged                    |
| Last price                  | Server → Client | Last traded price of a pair; sent after each batch of trades and on subscribe                  |
| Error                       | Server → Client | `{"er", "msg"}` — see [Errors](broken://pages/7b60c6363e2dcb27a5c7d2ef03222a2bd85342c5#errors) |
| `ping` / `pong`             | Both            | Plain-text keep-alive                                                                          |

## Subscribe

```json
{"act": "subscribe", "pi": 1}
```

Every pair:

```json
{"act": "subscribe", "all": true}
```

Server confirmation: there is no confirmation frame. When you subscribe by pair ID and the pair has traded, its last-price frame arrives immediately. Trades follow as they happen.

## Delivery

* Trades are batched per pair and flushed about four times a second; a trade reaches the stream within about half a second.
* Within a batch, trade frames arrive oldest first, then one last-price frame with the price of the newest trade.
* Fills with the same time, taker side and price that arrive one after another are merged into one trade frame; `v` is their total size. A market order that sweeps several price levels therefore shows as one frame per level.
* During a burst, a batch carries at most the **10 newest** trade frames; older frames of that burst are not sent on this stream. The stream is a live tape, not a complete trade history.
* The stream sends no history on subscribe — only the last price.

## Trade Payload

```json
{
  "id": "t_1843920117",
  "pi": 1,
  "p": 64250.5,
  "v": 0.015,
  "sd": "buy",
  "t": 1790662754945
}
```

| Field | Type    | Description                                                                                                                                                  |
| ----- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`  | string  | Unique ID of the frame: the ID of its newest fill. Usually `t_` followed by a number; may also start with `w_`. Use it to de-duplicate frames on this stream |
| `pi`  | integer | Pair ID                                                                                                                                                      |
| `p`   | number  | Trade price                                                                                                                                                  |
| `v`   | number  | Trade size; for a merged frame, the total of its fills                                                                                                       |
| `sd`  | string  | Taker (aggressor) side: `buy` = buyer took the ask, `sell` = seller hit the bid                                                                              |
| `t`   | integer | Trade time, epoch ms                                                                                                                                         |

## Last-Price Payload

```json
{
  "s": 1,
  "p": 64250.5
}
```

| Field | Type    | Description       |
| ----- | ------- | ----------------- |
| `s`   | integer | Pair ID           |
| `p`   | number  | Last traded price |

## Python Example

{% code title="trades.py" %}

```python
import asyncio
import json
from decimal import Decimal

import websockets

URL = "wss://futures-marketdata-service.outpoll.com/ws/trades/last"


async def main():
    seen = set()
    async with websockets.connect(URL) as ws:
        await ws.send(json.dumps({"act": "subscribe", "pi": 1}))
        async for raw in ws:
            if raw == "pong":
                continue
            msg = json.loads(raw, parse_float=Decimal)
            if "er" in msg:
                print("error:", msg)
            elif "id" in msg:
                if msg["id"] in seen:
                    continue
                seen.add(msg["id"])
                print(f"{msg['t']} {msg['sd']:>4} {msg['v']} @ {msg['p']}")
            elif "s" in msg:
                print(f"last price for pair {msg['s']}: {msg['p']}")


asyncio.run(main())
```

{% endcode %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.outpoll.com/api/futures-api/websockets/futures-market-data/trades.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
