> For the complete documentation index, see [llms.txt](https://docs.opinion.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opinion.trade/developer-guide/opinion-websocket/market-channels.md).

# Market Channels

## Orderbook Change

### Subscribe

Message will be sent once the orderbook has any change (new/cancel/match order).

<table><thead><tr><th width="150">Field</th><th width="200">Value</th><th>Description</th></tr></thead><tbody><tr><td>channel</td><td>market.depth.diff</td><td>Channel of orderbook change</td></tr><tr><td>marketId</td><td>{MARKET_ID}</td><td>MarketId of subscribed market</td></tr></tbody></table>

{% hint style="info" %}
Orderbook Change applied to a single binary market only.

For categorical market, you should subscribe each `market_id` individually.
{% endhint %}

{% code title="Example" %}

```
{"action":"SUBSCRIBE","channel":"market.depth.diff","marketId":1274}
```

{% endcode %}

### Structure

<table><thead><tr><th width="180">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>marketId</td><td>number</td><td>market id</td></tr><tr><td>rootMarketId</td><td>number</td><td>root market id if belongs to a categorical market</td></tr><tr><td>tokenId</td><td>string</td><td>token id of updated conditional token</td></tr><tr><td>outcomeSide</td><td>number</td><td>1 - yes, 2 - no</td></tr><tr><td>side</td><td>string</td><td>bids | asks</td></tr><tr><td>price</td><td>string</td><td>price</td></tr><tr><td>size</td><td>string</td><td>shares of conditional tokens</td></tr></tbody></table>

<pre class="language-json" data-title="Sample message" data-expandable="true"><code class="lang-json">{
<strong>    "marketId": 2764, 
</strong>    "tokenId": "19120407572139442221452465677574895365338028945317996490376653704877573103648", 
    "outcomeSide": 1, 
    "side": "bids", 
    "price": "0.2", 
    "size": "50", 
    "msgType": "market.depth.diff"
}
</code></pre>

## Market Price Change

Message will be sent once the latest match price has changed.

### Subscribe

<table><thead><tr><th width="150">Field</th><th width="200">Value</th><th>Description</th></tr></thead><tbody><tr><td>channel</td><td>market.last.price</td><td>Channel of market price change </td></tr><tr><td>marketId</td><td>{MARKET_ID}</td><td>MarketId of subscribed binary market</td></tr><tr><td>rootMarketId</td><td>{ROOT_MARKET_ID}</td><td>MarketId of subscribed categorical market</td></tr></tbody></table>

{% hint style="info" %}
If `rootMarketId` is defined, `marketId` will be omitted.

Subscribing root market will receive messages of all of its sub-markets.
{% endhint %}

<pre data-title="Example"><code><strong>For Binary market:
</strong>{"action":"SUBSCRIBE","channel":"market.last.price","marketId":1274}
For Categorical market:
{"action":"SUBSCRIBE","channel":"market.last.price","rootMarketId":61}
</code></pre>

### Structure

<table><thead><tr><th width="180">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>marketId</td><td>number</td><td>market id</td></tr><tr><td>rootMarketId</td><td>number</td><td>root market id if belongs to a categorical market</td></tr><tr><td>tokenId</td><td>string</td><td>token id of updated conditional token</td></tr><tr><td>price</td><td>string</td><td>price</td></tr><tr><td>outcomeSide</td><td>number</td><td>1 - yes, 2 - no</td></tr></tbody></table>

{% code title="Sample message" expandable="true" %}

```json
{
    "tokenId": "19120407572139442221452465677574895365338028945317996490376653704877573103648", 
    "outcomeSide": 1, 
    "price": "0.85", 
    "marketId": 2764, 
    "msgType": "market.last.price"
}
```

{% endcode %}

## Market Last Trade

### Subscribe

Message will be sent once a trade matched in this market.

{% hint style="warning" %}
Please note that the matched trade does not guarantee successful execution on-chain.

And the final on-chain amount/share may vary if fee applied.
{% endhint %}

<table><thead><tr><th width="150">Field</th><th width="200">Value</th><th>Description</th></tr></thead><tbody><tr><td>channel</td><td>market.last.trade</td><td>Channel of market last trade </td></tr><tr><td>marketId</td><td>{MARKET_ID}</td><td>MarketId of subscribed binary market</td></tr><tr><td>rootMarketId</td><td>{ROOT_MARKET_ID}</td><td>MarketId of subscribed categorical market</td></tr></tbody></table>

{% hint style="info" %}
If `rootMarketId` is defined, `marketId` will be omitted.

Subscribing root market will receive messages of all of its sub-markets.
{% endhint %}

{% code title="Example" %}

```
For Binary market:
{"action":"SUBSCRIBE","channel":"market.last.trade","marketId":1274}
For Categorical market:
{"action":"SUBSCRIBE","channel":"market.last.trade","rootMarketId":61}
```

{% endcode %}

### Structure

<table><thead><tr><th width="180">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>marketId</td><td>number</td><td>market id</td></tr><tr><td>rootMarketId</td><td>number</td><td>root market id if belongs to a categorical market</td></tr><tr><td>tokenId</td><td>string</td><td>token id of updated conditional token</td></tr><tr><td>side</td><td>string</td><td>Buy | Sell | Split | Merge</td></tr><tr><td>outcomeSide</td><td>number</td><td>1 - yes, 2 - no</td></tr><tr><td>price</td><td>string</td><td>price</td></tr><tr><td>shares</td><td>string</td><td>amount of conditional token</td></tr><tr><td>amount</td><td>string</td><td>amount of quote token</td></tr></tbody></table>

{% code title="Sample message" expandable="true" %}

```json
{
    "tokenId": "19120407572139442221452465677574895365338028945317996490376653704877573103648", 
    "side": "Buy", 
    "outcomeSide": 1, 
    "price": "0.85", 
    "shares": "10", 
    "amount": "8.5", 
    "marketId": 2764, 
    "msgType": "market.last.trade"
}
```

{% 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 dynamically by asking a question.

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

```
GET https://docs.opinion.trade/developer-guide/opinion-websocket/market-channels.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 `build a script that syncs our docs to a CMS` 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.
