> ## Documentation Index
> Fetch the complete documentation index at: https://docs.derivadex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Price Feeds and Mark Price Inputs

> DerivaDEX pricing reference for external spot sources, index-price aggregation, mark-price calculation, clamp bounds, and mark-dependent trading checks.

DerivaDEX prices each perpetual with two related values: the **index price** (a composite spot price from external feeds) and the **mark price** (the fair price used for margin, liquidation, funding, and mark-relative trading checks).

## Price types and what they are used for

| Price            | Definition                                                                            | Used for                                                                               |
| ---------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| Index price      | Composite spot price from the configured external feeds                               | External reference input to the mark price                                             |
| Mark price       | Index price plus a smoothed premium, clamped to `±50` basis points (`±0.5%`) of index | Margin, liquidation, funding, and price-band checks; fills still execute at book price |
| Last trade price | Price of the most recent fill on the DerivaDEX order book                             | Trade reporting and chart displays                                                     |
| Bankruptcy price | Price at which a strategy's collateral is fully consumed by position losses           | Liquidation spread and auto-deleveraging (ADL) pricing                                 |

The **mark price** (not the **last trade price**) determines risk checks.

## Index sources by market

By default, each listed perpetual uses three external spot feeds.

| Market | Underlying | External spot sources                                  |
| ------ | ---------- | ------------------------------------------------------ |
| `ETHP` | ETH        | Coinbase `ETH-USD`, Binance `ETHUSDC`, Gemini `ETHUSD` |
| `BTCP` | BTC        | Coinbase `BTC-USD`, Binance `BTCUSDC`, Gemini `BTCUSD` |

## Index price calculation

At each oracle update, typically once per second, DerivaDEX aggregates the latest source prices into one index price.

```text theme={null}
median_source_price = median(latest_source_prices)
clamped_source_i = clamp(source_i, 0.995 × median_source_price, 1.005 × median_source_price)
clamped_composite = average(clamped_source_1 ... clamped_source_n)
index_price_next = index_price_prev + alpha × (clamped_composite - index_price_prev)
alpha = 2 / (30 + 1)
```

| Parameter                       |                               Value | Notes                                                                |
| ------------------------------- | ----------------------------------: | -------------------------------------------------------------------- |
| Aggregation method              | Median anchor, then arithmetic mean | Outliers are clamped before averaging                                |
| Per-source outlier clamp        |           `±0.5%` around the median | Applied separately to each source price                              |
| EMA period                      |                        `30` updates | `alpha = 2 / (30 + 1)`                                               |
| Default oracle polling interval |                          `1` second | Source feeds are polled once per second in the default configuration |
| First published index price     |           Current clamped composite | No time smoothing applies until there is a prior published value     |

## Mark-price inputs

The mark price starts from the current index price and adds a smoothed premium derived from the DerivaDEX book.

| Input       | Definition                                               | Fallback behavior                                                                                              |
| ----------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| Index price | Current composite spot price from the external feeds     | Required base input                                                                                            |
| Fair price  | Best available book reference from DerivaDEX quotes      | Midpoint if both sides exist; bid if only bid exists; ask if only ask exists; index price if the book is empty |
| Premium EMA | Exponential moving average of `fair_price - index_price` | Carries forward the prior premium state between updates                                                        |

## Mark-price calculation

The mark price uses the fair-price premium, then clamps the result back to the index.

```text theme={null}
fair_price = (best_bid + best_ask) / 2        if both sides exist
fair_price = best_bid                           if only bid exists
fair_price = best_ask                           if only ask exists
fair_price = index_price                        if the book is empty

premium = fair_price - index_price
premium_ema_next = premium_ema_prev + alpha × (premium - premium_ema_prev)
mark_price = index_price + clamp(premium_ema_next, -0.005 × index_price, +0.005 × index_price)
```

| Parameter        |                              Value | Notes                                                                       |
| ---------------- | ---------------------------------: | --------------------------------------------------------------------------- |
| Premium input    |         `fair_price - index_price` | Tracks the DerivaDEX book relative to the external index                    |
| EMA period       |                       `30` updates | Uses the same smoothing constant as the index update                        |
| Mark-price clamp | `±50` bps (`±0.5%`) of index price | Prevents the mark from drifting arbitrarily far from the external reference |
| Realtime feed    |                       `MARK_PRICE` | Carries mark-price and funding-rate updates                                 |

## Mark-dependent trading checks

DerivaDEX uses the current mark price in both sequencing and matching.

| Check                              | What happens                                                                                                                                      |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Explicitly priced order validation | Sequencing rejects an explicitly priced order when its taker price breaches the product's `max_taker_price_deviation` from the current mark price |
| Market-order handling              | Market orders skip the sequencer deviation check because they have no explicit price                                                              |
| Matching price band                | When no explicit taker limit exists, matching derives a mark-price-relative limit from the product's `max_taker_price_deviation`                  |
| Residual beyond the band           | Any unmatched remainder is canceled rather than filled outside the effective band                                                                 |
| Missing mark price                 | Requests can fail with `MarketPriceNotAvailable` instead of trading without a current risk price                                                  |

## Worked pricing cases

These examples show which book price becomes the fair-price input before the premium EMA and mark-price clamp apply.

| Book state                         | Fair-price input    |
| ---------------------------------- | ------------------- |
| Best bid `2,000`, best ask `2,002` | Midpoint `2,001`    |
| Best bid `2,000`, no ask           | Bid `2,000`         |
| No bid, best ask `2,002`           | Ask `2,002`         |
| No bid and no ask                  | Current index price |

## Related references

Feed venues and polling intervals are governance-controlled and may change.

* [Product and Trading Specifications](/reference-public/product-and-trading-specifications)
* [Margin Requirements](/reference-public/margin-requirements)
* [Funding Rate Logic](/reference-public/funding-rate-logic)
* [Trading Safeties and Guards](/reference-public/trading-safeties-and-guards)
* [Order and Account Event Reference](/reference-public/order-and-account-event-reference)
* [Error Reference](/reference-public/error-reference)
