Index Price

Note: Index, also called Oracle, is an index that reflects changes in cryptocurrency prices.

What is index price?

Index prices widely exist in contract transactions, and the target of its rivets is the spot price. The spot price is different in each exchange, so there needs to be a unified value to quantify the price of each currency pair, which is the index price. Index prices represent fair prices in the market. Take the weighted average of the spot prices of each major exchange, and handle exceptions to obtain fair, stable, and accurate index prices.

Calculation of index price

1. Find the source exchange and set the weight

Choose the BTC/USDT trading pair as an example:

Take Binance, OKX, Coinbase, and Huobi as the source of index prices, and set the following weights:

2. Record Index Price

The system will record all the transaction prices of the source exchange for a period of time every second, and perform a calculation, and the result will be the last price of the source exchange. This is to make the last price closer to the actual price. If there is no last transaction for a long time, the last transaction price at this time will not be the last market price.

The last price of the source exchange = median (bid 1 price, ask 1 price, the last transaction price)

3. Abnormal price processing

Expiration time

When the price of a source exchange is not updated within the expiration time, we will consider the price to have expired, and it will not be used in the calculation this time.

e.g. expiration time = 40,000ms

Wrong price ratio

When the price of a certain source exchange deviates too much from the last price, we will think that this price has no reference value and will not be adopted in this calculation.

e.g. wrong price ratio = 10%

Price deviation = ABS(latest source price - last source price) / last source price

When the price deviates >= 10%: will not adopt this price

Price deviation correction

When the price of a source exchange deviates too much from the median price of other exchanges, it will be considered too extreme (may be caused by market fluctuations or market orders), and it can only be included in the calculation after correction.

The correction rule: If it is less than the median of other exchanges and the difference between the two is greater than 3%, it will be calculated according to the median price of other sources * 0.97; if it is greater than the median of other exchanges and the difference between the two is greater than 3%, it will be calculated according to the price of other sources Median*1.03 calculation.

e.g. price deviation correction = 3%

Price deviation = ABS(price from this source - median price from other sources) / median price from other sources

When the price deviates > 3%:

Corrected price = clamp(median price from other sources0.97, median price from other sources1.03, price from the source)

4. Index-weighted calculation

Weighted calculation

Every second, according to the set weight, the source price after exception processing is weighted and averaged.

Index price = SUM(source price * weight)

No available index source

When no index price is available, take the latest index price as the last one. At the same time, try to reconnect, and automatically restart the service if fail to reconnect several times.

Index price = last index price

Last updated