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

# Mark Price and Oracle Price

TxFlow uses two reference prices to ensure market integrity and prevent manipulation.

<table><thead><tr><th>Price</th><th width="280.765625">Source</th><th>Used for</th></tr></thead><tbody><tr><td><strong>Oracle Price</strong></td><td>Weighted median of spot prices from major CEXs</td><td>Funding rate calculation, slippage protection</td></tr><tr><td><strong>Mark Price</strong></td><td>Oracle Price + 30-second smoothed premium</td><td>Liquidations, unrealized PnL, margin, TP/SL triggers</td></tr></tbody></table>

### Oracle Price

The Oracle Price is the external spot reference for a market. It is fully independent of TxFlow's order book, making it highly resistant to manipulation.

**Calculation:**

```
Oracle Price = Weighted Median(P₁, P₂, ..., Pₙ)
```

Where `P₁...Pₙ` are spot mid-prices from major CEXs (e.g., Binance, Coinbase, OKX, Kraken), weighted by each exchange's trading volume and reliability.

* **Update frequency:** \~every 3 seconds, published by validators
* **Why weighted median?** Unlike a simple average, the median is robust against outliers — a single exchange reporting an erroneous price cannot skew the result.

### Mark Price

The Mark Price is TxFlow's fair-value estimate of the perpetual contract. It is derived from the Oracle Price plus a smoothed market premium that filters out short-term noise.

**Calculation:**

```
Mark Price = Oracle Price + Average Premium
```

Where **Average Premium** is the moving average of:

```
Average Premium = Average of ((bid 1 + ask 1) ÷ 2 − Oracle Price)
```

Sampled every second over a **30-second window** (`= 30 samples`).

* **Update frequency:** \~every 3 seconds, synced with Oracle updates
* **Why include premium?** It reflects TxFlow's market sentiment relative to spot. Smoothing over 30 seconds prevents manipulation via short-term order book spoofing.

### When each price is used

<table><thead><tr><th width="222.01953125">Use Case</th><th width="124.015625">Price Used</th><th width="462.32421875">Reason</th></tr></thead><tbody><tr><td>Liquidations</td><td>Mark Price</td><td>Prevents manipulation; smooths volatility</td></tr><tr><td>Unrealized PnL</td><td>Mark Price</td><td>Fair valuation consistent with liquidation logic</td></tr><tr><td>Margin requirements</td><td>Mark Price</td><td>Consistent with liquidation logic</td></tr><tr><td>Funding rate calculation</td><td>Oracle Price</td><td>Independent reference; prevents funding manipulation</td></tr><tr><td>Slippage protection (market orders)</td><td>Oracle Price</td><td>Detects extreme execution prices vs. external reference</td></tr><tr><td>TP/SL triggers</td><td>Mark Price</td><td>Consistent with PnL calculations</td></tr></tbody></table>

### Related Pages

<table><thead><tr><th width="154.7265625">Pages</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/z986rTaJ8Z98daTE3x0N">Liquidation</a></td><td>Detailed liquidation mechanics</td></tr><tr><td><a href="/pages/JCOc7dDxeSdSQSf2US8e">Funding</a></td><td>Funding fees</td></tr></tbody></table>


---

# 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:

```
GET https://docs.txflow.com/perp/mark-price-and-oracle-price.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
