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

# Market Price Oracle

Before every batch, Turbine determines a reference mid-price for each token pair. All orders and LP are offset from this price by the user-defined spread.

**Cross-venue mid-price**

The pair mid-price is the median of all valid per-venue prices. Turbine prunes outliers iteratively: at each step it removes the price furthest from the median while either condition below holds. It stops once neither holds, or once two prices remain.

* **Mean–median divergence**: mean and median differ by more than `mean_median_threshold` (1%).
* **Individual deviation**: some price is further from the median than `max_price_deviation × median` (0.1%).

A single batch snapshot makes the conversion easier to see: venue prices are placed around the final mid, off-market venues are pruned, and the median of the accepted prices becomes Turbine's batch mid-price.

<figure><img src="/files/nO4i0PLoFL5Z2Upmhn3q" alt="AAVE-USDC oracle venue prices converted into Turbine&#x27;s median mid-price"><figcaption><p>Real AAVE/USDC oracle snapshot from Grafana. Mint dots are accepted venue prices inside the +/-10 bps guardrail, red crosses are pruned venues, and the yellow line is the median mid-price used for the batch.</p></figcaption></figure>

**Pause on invalid price**: if fewer than `min_valid` (3) venues produce a fresh, non-outlier price for a pair, Turbine excludes all orders and LP on that pair from the current batch.

<figure><img src="/files/Vl5WZlwwzOyZXR7Xele1" alt="AAVE-USDC oracle guardrails with per-venue prices, pruned samples, and accepted venue count"><figcaption><p>Real AAVE/USDC oracle sample from Grafana. Venue prices are shown as bps from Turbine's median oracle price; dashed lines show the +/-10 bps threshold, red markers are in-range pruned samples, and the lower panel shows how many venues remain after pruning.</p></figcaption></figure>

**Per-venue prices**

Turbine sources prices from live WebSocket order-book feeds: Binance, Bingx, Bitget, Coinbase, Hyperliquid, Kraken, Kucoin, Lighter, and Okx.

<figure><img src="/files/GDezoWgxS9LBYGYkfmTn" alt="How Turbine calculates a venue mid-price from order-book depth samples"><figcaption><p>Illustrative AAVE/USDC venue calculation. Turbine walks both sides of the order book to several quote sizes, computes a depth-anchored midpoint for each size, takes the median across size samples, then reports the median across recent snapshots.</p></figcaption></figure>

The per-token mid on a venue is built in two steps:

1. **Depth-anchored mid per snapshot.** For each book update, Turbine walks both sides until a target trade size (in the venue's quote currency) is consumed, then takes the midpoint of the worst bid and ask reached. This reflects the cost of trading at that size, not just the top-of-book spread. To remove sensitivity to a single size, Turbine samples 5 log-spaced sizes between $1,000 and the smaller of total bid/ask depth, and takes the median across them. Books with under $1,000 on either side are skipped.
2. **Temporal median across recent snapshots.** The depth-anchored mid is appended to a per-token buffer. The venue's reported price is the median of samples within the last 500 ms; if fewer than two samples are that recent, it falls back to the most recent sample. This smooths sub-second spoofing attempts on fast feeds while remaining usable for slower or stable ones.

A venue's pair price is rejected only if either leg lacks a fresh sample.


---

# 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.turbine.exchange/features/market-price-oracle.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.
