Perpetual Mark Price Formula
Steps to calculate the Mark Price
1. Every 5 seconds, get the latest Best Ask, Best Bid, Last Trade and Spot Prices
2. Calculate the implied rates from Best Ask, Best Bid, Last Trade relative to the Spot Price
3. Calculate the EWMA (Exponentially Weighted Moving Average) of each of the three rates and take the Funding Rate as the median rate
4. Calculate the Mark Price by applying the Funding Rate to the Spot Price