> For the complete documentation index, see [llms.txt](https://xdex.gitbook.io/xdex/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xdex.gitbook.io/xdex/star-here/trading-perpetual-contracts/last-price-index-price-and-oracle-price.md).

# Last Price, Index Price & Oracle Price

LastXDEX utilizes three (3) different prices: Last Price, Index Price and Oracle Price.Reference and indexed price feeds for XDEX markets.

**Last Price**

This refers to the latest price at which a contract is trading at real-time and is reflected on the order book. Traders will have their orders executed based on the last price as shown on the order book interface.

**Index Price**

Index Price is the sum of prices pulled from multiple crypto spot exchanges, then calculated based on weighted average. It is used to derive funding fees.

**Oracle Price**

XDEX Oracles play a crucial role in a decentralized exchange (DEX), functioning as the pathway for XDEX’s on-chain contracts to access existing data sources (e.g., prices) off-chain and execute advanced computations on-chain. XDEX’s high-performance exchange design requires an oracle architecture developed for ultra-low-latency and robust oracle feeds across the long tail of market pairs.

On a performant DEX, oracles need to deliver price feeds for each market on the exchange with several core properties, including:

* **Decentralized**
* **Robust**
* **Low-Latency**
* **Cost-Efficient**

Price feeds for various exchange assets help calculate intricate functions, including account collateralization, perpetual funding rates, and more. Oracle price referencing also needs to maintain redundancy across data publishers, meaning that data feeds are defensible to stale prices from reference providers (e.g., third-party exchanges) and can operate without a single point of failure.

**Stork is an ultra-low-latency, decentralized, hybrid oracle network for EVM-compatible price feeds**.

Stork’s oracle architecture prioritizes performance, congruent with XDEX’s low-latency order-matching and emphasis on CEX-grade execution speeds. Using ultra-fast WebSockets across multiple regions and node providers, Stork can ensure that XDEX’s reference prices are available on the millisecond level, comparable to the data velocity used on CEXs and TradFi exchange venues.

Stork also empowers XDEX with its [hybrid on/off-chain architecture](https://docs.stork.network/hybrid-oracle-architecture), unlocking the ability to perform initial processing off-chain and subsequently push price updates on-chain specific to each product – such as perpetuals.

With the XDEX sequencer, price updates are bundled off-chain with each sequence of actions submitted before being pushed on-chain, enabling continuous reference prices at lower costs and computational complexity. This is necessary for a performant DEX relative to other, pure on-chain oracle providers that push price updates less frequently\[1].

Scarcer price updates in pure on-chain oracle models reduce the ability to support long-tail assets where gas fees are not justified relative to the on-chain demand for the corresponding asset. Less frequent price updates also do not function as effectively as hybrid on/off-chain oracle models amid significant market volatility.

With Stork, XDEX can achieve robust, low-cost, and high-performance price referencing and correlated on-chain calculations (e.g., perpetual funding) while minimizing pricing vulnerabilities across the long tail of assets.

{% hint style="info" %} <mark style="color:orange;">Please refer to their documentation</mark> <mark style="color:purple;">here</mark> <mark style="color:orange;">for more information on the Stork oracle architecture.</mark>
{% endhint %}

## **XDEX & Stork Oracle 架构**

Stork publishers and data sources are chosen for their ability to provide low-latency price updates reliably. The methodologies are chosen to enable Stork clients to achieve specific results and will evolve over time.

Each publisher can contribute an index price for the markets supported by Stork. Currently, implementing the index calculation is at each publisher’s discretion; ergo, not every publisher will converge their price.

On XDEX, three different Oracle price feeds exist via Stork, all of which are instantaneous per market. These include:

### **1.Spot Oracle Prices (spot on centralized exchanges):**

The spot oracle prices from Stork comprise an index of the reference spot exchanges to price against XDEX perpetual products using a TWAP of the index price across the *Median of the Last Trade Price* from supported exchanges. Supported exchanges (exchanges with major USD or BUSD markets):

* **Binance**
* **Coinbase Pro**
* **Kraken**

### [**2.** **Perpetual Prices (centralized exchanges)**:](#user-content-fn-1)[^1]

Continuous LP-based perpetual prices; these serve as the reference prices for calculating funding for the perpetual futures. A closed-loop funding rate option is used, where both the exchange’s (i.e., XDEX's) own mark price and the spot index price TWAPs are captured by Stork, reducing centralization and the cost of storing and computing the funding fee on-chain.

The XDEX *Perpetual Index* price is a volume-weighted perpetual price across supported exchanges, converted from USDT to USD using a volume-weighted average of USDC-USDT and BUSD-USDT spot markets.

* **Exchanges**: Binance, ByBit, OKX.
* **Markets**: Markets quoted in USDT and converted to USD using volume-weighted spot prices for USDC-USDT and BUSD-USDT markets.
* **Volume**: Trailing four (4) hours trailing volume for each perpetual market.

**3**. **Orderbook Price on XDEX.**

> For *liquidations*, XDEX uses the **Spot Oracle Price** (**#1**) and the **Perp Oracle Price** (**#2**) to calculate a trader's account value. You can find the liquidation calculations [here](https://docs.vertexprotocol.com/basics/liquidations-and-insurance-fund).

> For *funding*, XDEX uses a TWAP of the **Orderbook Price on XDEX** (**#3**), known as the mark price, and a TWAP of the **Spot Oracle Price** (**#1**). More details on the funding rate calculations can be found [here](https://docs.vertexprotocol.com/basics/funding-rates).

{% hint style="info" %}
For an in-depth description of the *Liquidation* calculations, please refer to the [*Basics – Liquidations*](https://docs.vertexprotocol.com/basics/liquidations-and-insurance-fund) section.
{% endhint %}

Unlike the index price, every Stork publisher follows the same calculation for the perpetual index price.

* **Funding Rate Calculations**: The spot index price and XDEX’s perpetual contract price (e.g., mark price) calculate the funding rate.
* **Calculating Liquidations**: The spot oracle price is used for liquidations. You can find the liquidation calculations [here](https://docs.vertexprotocol.com/basics/liquidations-and-insurance-fund).

{% hint style="info" %}
For liquidations, the **Spot Oracle Price is what's utilized for liquidations and displayed on the XEDX front-end**.
{% endhint %}

An independent oracle price also exists for USDC, which will allow for functional [health calculations](https://docs.vertexprotocol.com/basics/subaccounts-isolated-margin-and-health#health) and trading behavior even in the case of USDC de-pegging.

> The XDEX front-end will always display prices quoted against USDC (***NOT*** USD), and there are **NO assumptions** within the protocol where 1 USDC = 1 USD.

{% hint style="info" %}
*XDEX removes the ability to submit relative orders, where trades are executed when the market price deviates X amount from the oracle price. This is because it significantly reduces complexity, and the use case of relative orders is niche.*
{% endhint %}

[^1]:
