# Fees

Trading fees are necessary to help sustain the protocol over the long term.  They are broken out into 3 areas; position fees, funding fees, and borrowing fees.

### Position Fees

Position fees are paid when opening, increasing or decreasing a position.  They are based on position size and a trading rate that is set per asset as follows:

$$
positionFee = posSize  \times positionRate\[asset]
$$

| Asset Class | Rate  |
| ----------- | ----- |
| Crypto      | 0.08% |
| Forex       | 0.08% |
| Metals      | 0.08% |

### Funding Fees

Funding fees are in place to keep open interest balanced. The rate is determined by the net difference between long and short open interest per asset and usdc in the vault. If positive, then longs pay shorts, and if negative, then shorts pay longs.

$$
fundingRate = fundingRateFactor \times \frac{longOI-shortOI}{usdcVault}
$$

The funding rate shown on the UI is per hour, even though fees are continuously accrued every block.  For example if the rate shown is 0.01%/hr then this means an APR of 87.6% (0.01% \* 24 \* 365).

A funding index (unique to each asset) is introduced which is updated each time a function is called.  It increases/decreases over time based on a positive/negative funding rate as follows:

$$
fundingIndex = fundingRate \times (currentTimestamp - lastTimestamp)
$$

$$
deltaFundingIndex = fundingIndex\[current] - fundingIndex\[posID]
$$

$$
fundingFee =\begin{cases} posSize \times deltaFundingIndex/1000000 &\text{if } LONG \ -posSize \times deltaFundingIndex/1000000 &\text{if } SHORT\end{cases}
$$

For example, lets say: the user opens a 100k BTC long position and the current funding index for BTC is 15010.

A simple flow for illustration:

1. User calls a function to open a new position which sets fundingIndex\[posID] = 15010.  &#x20;
2. User holds position for a few hours at which time they decide to close 80% of their position.  Now, due to dynamic conditions with other users opening and closing BTC positions as well as BTC funding rate changing, the funding index for BTC is now 15510.
3. User pays 80% \* 100k \* (15510 - 15010)/1000000 = $40&#x20;

### Borrow Fees

A borrow fee is implemented to help mitigate/offset the vault's risk of always taking the opposite side of each trade. The borrow fee will be based on the position size as well as the duration, in seconds, the position is held open.

$$
borrowFee=posSize\times borrowRate \times duration
$$

Borrow rate will be determined per asset by using each assets historical volatility. This is set manually, based on analysis, and will be periodically reviewed and updated to ensure the vault's risk is being managed appropriately.

### Asset Risk

We consider assets either Low, Medium, or High risk, and group them into one of these categories to illustrate their borrow rate classification. For example, BTC and ETH have relatively low historical volatility in the crypto market.


---

# 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.mummy.finance/trade/trading-v2/platform-mechanics/fees.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.
