# Oracle

The role of a price oracle is to provide prices for futures trading pairs. The platform classifies currencies into CEX currencies and DEX currencies based on their liquidity. Below, we will describe the oracle implementation for these two types of currencies.<br>

### CEX Currencies

CEX currencies are those primarily with liquidity concentrated on centralized exchanges. We'll use BTC as an example to explain the price feed mechanism.

1. **Calculate the USDT/USD price:**

The platform selects the USDT/USD prices from four exchanges (coinbase, kraken, bitfinex, crypto.com) and takes the median as the fair USDT/USD price.

2. **Calculate the BTC/USDT price:**

The platform selects the BTC/USDT prices from five exchanges (binance, okx, coinbase, bitget, gate), calculates the median price, and then applies an outlier handling mechanism to data with a difference from the median exceeding 3% (prices greater than 1.03 times the median are calculated as 1.03 times, and prices less than 0.97 times the median are calculated as 0.97 times). Finally, the mean is calculated as the fair BTC/USDT price.

3. **Calculate the BTC/USD price:**

The fair USDT/USD price and BTC/USDT price are multiplied to obtain the BTC/USD price.

We use Chainlink on-chain price feeds for oracle risk management. When the oracle price deviates by a certain threshold (adjusted based on different pairs and markets), it is rejected. This risk management measure effectively prevents the risk of abnormal oracle data.

### DEX Currencies

\
DEX currencies are those primarily with liquidity concentrated on decentralized exchanges. We'll use UNIBOT as an example to explain the price feed mechanism.

* **Calculate the UNIBOT/USD price:**

The platform selects the pool with the highest liquidity on Uniswap (e.g., UNIBOT/WETH v2 pool), retrieves the UNIBOT price, and converts it into USD price.


---

# Agent Instructions: 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.substancex.io/perpetual/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.
