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

# Funding

Funding payments keep the perpetual contract price anchored to spot in the absence of an expiry. At each funding interval, longs and shorts exchange a small payment proportional to position size and to the **funding rate**. The exchange is peer-to-peer; AgentDex doesn't take a cut of funding (it's not a fee — see [Fees](/agentdex-docs/trading/fees.md)).

### Direction of payment

| Funding rate | Who pays | Who receives |
| ------------ | -------- | ------------ |
| Positive     | Longs    | Shorts       |
| Negative     | Shorts   | Longs        |

If the contract is trading **above** the index, the rate trends positive: longs subsidise shorts, nudging the price back down. The reverse applies below the index.

### How the rate is computed

The funding rate is derived from a **premium index** that measures how far the order book sits above or below index price, sampled continuously through the interval and aggregated. Two terms feed it:

* **Bid component** — `impact_bid − mark_price`
* **Ask component** — `mark_price − impact_ask`

Both use **impact prices** (the volume-weighted price to sweep a configured depth of the book), not raw best bid/ask. The premium is `(bid − ask) / spot_price`. A smoothing window (SMA) is applied before the rate is published, and the result is clamped to a per-instrument cap so a transient dislocation can't produce a runaway payment.

The interest-rate component (typical of TradFi swaps) is set to zero on most instruments at launch and may be re-enabled per instrument later.

### Funding interval and settlement

Funding is sampled and accrued continuously; the actual cash-flow is settled at fixed intervals. The interval per instrument is part of the contract spec (returned by `get_instrument`) — typically 1 hour or 8 hours, matching industry convention.

At each interval:

1. The engine computes the period rate from the premium index time-series.
2. Each open position pays or receives `position_value × rate` against the **funding partner pool**.
3. The settlement debits `available` (or, if depleted, eats into position margin) for the losing side and credits the winning side.

You can read the live rate via `get_ticker` (`funding_rate` field in extended responses) and the next settlement time via the instrument config. Historical rates are published through the public market-data WebSocket topics in [Websocket API](/agentdex-docs/developers/websocket-api.md).

### Worked example

Long $10 000 BTC. Funding rate +0.01 % for the upcoming interval, payable to shorts.

* Settlement: $10 000 × 0.0001 = $1.00 deducted from your available balance.
* If you flip the position to short before the cutoff, you receive the same $1.00 instead.

Funding accrues continuously, so a position closed mid-interval pays the prorated portion since the last settlement.

### Practical considerations

* **Mean reversion**: in a sustained trend, funding can become the dominant cost of holding a position. A 0.1 % hourly rate compounds to \~10 % a month if it persists — large by any measure.
* **Holding through funding**: opening seconds before settlement and closing seconds after collects (or pays) the full period. Some traders chase this; the engine settles position holders at the snapshot, not those who happen to be on the book.
* **Funding vs. mark price**: funding accrues against the engine's mark price; large divergence between mark and last-trade can produce surprising settlements during volatile periods (see [Mark price](/agentdex-docs/trading/mark-price.md)).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://agentdex.gitbook.io/agentdex-docs/trading/funding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
