> For the complete documentation index, see [llms.txt](https://agentdex.gitbook.io/agentdex-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agentdex.gitbook.io/agentdex-docs/trading/mark-price.md).

# Mark price

Mark price is the canonical price reference for everything margin-related: liquidations, maintenance-margin checks, funding accrual, take-profit / stop-loss triggers, and unrealised PnL. It is **not** the last-traded price. AgentDex computes mark price from multiple sources specifically so that no single observation can move it past a known bound.

### The structural property

The protocol fixes a numerical bound η < 1 on mark price's sensitivity to any single externally-supplied input. Formally:

$$\left|\frac{P\_{\text{mark}}(S', i) - P\_{\text{mark}}(S, i)}{P\_{\text{mark}}(S, i)}\right| \le \eta$$

for any state `S'` that differs from `S` only in one externally-supplied value, with that value still within its admissibility band. η is a protocol parameter fixed at chainspec time and knowable to any verifier in advance. This is the formal statement of the well-known goal "no single venue or print can move mark price by more than a defined fraction."

### How it's constructed

Mark price is the **median of three component prices**:

{% code title="Mark price construction" %}

```
P_mark = median(P_fair, P_SMA, P_last)
```

{% endcode %}

with fall-backs when components are unavailable:

| Available                 | P\_mark                         |
| ------------------------- | ------------------------------- |
| `P_SMA` ≠ 0               | `median(P_fair, P_SMA, P_last)` |
| `P_SMA` = 0, `P_fair` ≠ 0 | `P_fair`                        |
| both zero                 | `P_last`                        |

The components:

* **Index price** (`P_index`) — a weighted aggregation of top-of-book quotes from multiple external spot venues. AgentDex's index for `BTC_USDT_PERPETUAL` pulls from Binance, Kraken, Bitstamp, Bitfinex, Coinbase, and Gemini, each with a published weight, polled every 10 seconds.
* **Fair price** (`P_fair`) — `P_index × (1 + funding_basis)`, where the funding basis interpolates the next funding payment over the time remaining in the interval.
* **SMA price** (`P_SMA`) — `P_index + SMA(basis)`. A simple moving average over the clamped premium between order-book mid and index price.
* **Last trade price** (`P_last`) — the price of the most recent trade on AgentDex.

Using the median means a single corrupted input (one venue feeding bad data, a brief glitch on the order book) can move at most one component out of three. The median picks the surviving middle.

### What you see vs. what the engine uses

Two surfaces show price:

| Surface                         | Field               | Notes                                           |
| ------------------------------- | ------------------- | ----------------------------------------------- |
| MCP `get_ticker`, `get_tickers` | `mark_price`        | The engine's mark price                         |
| WS public topics                | mark/fair/index/SMA | All four components published as ticker updates |
| Web UI charting                 | last price          | Mid-screen chart price is `P_last`              |

Risk decisions (liquidations, margin holds, withdrawal eligibility) always use `P_mark` from the engine. If you build agents around mark price, read `get_ticker` directly — it's the one source of truth.

{% hint style="warning" %}
Risk decisions always use `P_mark` from the engine, not the visible last-traded price.
{% endhint %}

### Staleness handling

The index-price aggregator emits a heartbeat. If the heartbeat goes silent for **5 minutes**, the engine enters **System Emergency Mode**:

| State                                   | Behaviour                                                                                                                                                                                 |
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Healthy                                 | All operations allowed                                                                                                                                                                    |
| Emergency (after \~5–6 min stale index) | New user orders rejected with `IN_EMERGENCY_MODE`. Withdrawals halted. The liquidator pauses to avoid acting on stale prices. Index updates are still accepted so the system can recover. |
| Recovered                               | Heartbeat clears; liquidator resumes against fresh mark price.                                                                                                                            |

The emergency mode is intentionally blunt — better to pause than to liquidate against a stale price. The 5-minute threshold is a compromise between transient blip tolerance and exposure to drifting mark. Per-instrument circuit breakers and finer-grained degraded states are on the validator-phase roadmap (see [Roadmap](/agentdex-docs/under-the-hood/roadmap.md)).

### Why this matters for traders

* **You can be liquidated even when last-traded looks fine**. A sharp move on external venues drives index → fair → median; mark moves before your local book catches up.
* **Stop-loss orders triggered by `mark`** can fire on movements that don't show in the visible price chart. Triggering by `last` is also supported on `place-stop-order`; pick the right trigger for the use case.
* **Mark price during emergency mode**: existing positions are not auto-closed, but the engine refuses new orders and stops liquidations. If you hold a position when emergency mode trips, you cannot reduce it through normal orders until the index recovers.


---

# 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://agentdex.gitbook.io/agentdex-docs/trading/mark-price.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.
