> For the complete documentation index, see [llms.txt](https://sodex.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sodex.com/documentation/trading-mechanics/funding-legacy.md).

# Funding (Legacy)

Funding Rates are periodic fees exchanged between long and short positions in perpetual futures contracts to align contract prices with the underlying asset's spot price.

## Payment Calculation

The funding payment is calculated as: Funding Amount = Nominal Value of Positions × Funding Rate

* Nominal Value of Positions = Mark Price \* Size of a Contract

## Payment Settlement Rules

* Position Timing:
  * Traders only pay/receive funding if they hold open positions at the exact funding time (e.g., 08:00:00 UTC).
  * Closing a position before settlement exempts traders from funding payments, regardless of direction.
* Settlement Latency:
  * System processing may take up to 1 minute to complete all settlements.
  * New orders placed during settlement may experience high latency (e.g., opening a position at 08:00:59 UTC could still incur funding fees).

## Funding Rate Calculation

The funding rate (`F`) combines two elements:

* Premium Index (`P`): Measures the deviation between the futures price and spot price.
* Interest Rate (`I`): A fixed component set by exchanges. In SoDEX, the interest rate is 0.01%.
* Funding Rate (`F`) = Average Premium Index (P) + clamp(Interest Rate (I) - P, -0.05%, 0.05%)

## **Calculation Steps**

### **Step 1: Compute Impact Bid/Ask Prices**

* Impact Margin Notional (IMN): The notional value tradable with a fixed collateral (e.g., 25,000 USDT for BTC-USDT at 125x leverage).
* Impact Bid Price: Derived from the order book depth required to reach IMN.
* Impact Bid Price = IMN / \[(IMN - ∑px-1\*qx-1)/px + ∑qx-1]

### **Step 2: Calculate Premium Index Series**

* Updated every 5 seconds (5,760 times per 8-hour interval).
* Premium Index (P) = \[Max(0, Impact Bid Price - Index Price) - Max(0, Index Price - Impact Ask Price)] / Index Price

### **Step 3: Compute Time-Weighted Average Premium Index**

* Average Premium Index = (1\*P1 + 2\*P2 + ... + n\*Pn) / (1 + 2 + ... + n)

### **Step 4: Apply Funding Rate Formula**

Funding Rate (F) = Premium Index (P) + clamp(interest rate - Premium Index (P), -0.05%, 0.05%)

### **Step 5: Capped Funding Rate**

Enforce caps/floors to limit extreme rates: Capped Funding Rate = clamp(Funding Rate, Floor, Cap)

* The function clamp (x, min, max) means that if (x < min), then x = min; if (x > max), then x = max; if max ≥ a ≥ min, then return x.
* Floor = 0.75 \* Maintenance Margin Ratio
* Cap = 0.75 \* Maintenance Margin Ratio
