# Net Funding

Perpetual futures charge or pay a funding rate periodically. In a pair trade, you're paying funding on one side and receiving it on the other. The net funding rate tells you the combined funding cost (or income) of the entire basket.

#### How It Works

* **Long positions pay funding** when the rate is positive (and receive when negative).
* **Short positions receive funding** when the rate is positive (and pay when negative).

The net funding rate is the weighted sum across all assets, with signs flipped to reflect the actual cost to the trader:

* Longs: subtract the funding rate (you're paying it)
* Shorts: add the funding rate (you're receiving it)

A **negative** net funding rate means you're paying to hold the position. A **positive** net funding rate means you're earning by holding it.

#### Code

```typescript
type Token = { symbol: string; weight: number };
type TokenPriceMap = Map<string, { markPrice: number; funding: number }>;

function computeNetFundingRate(
  longTokens: Token[],
  shortTokens: Token[],
  prices: TokenPriceMap,
): number {
  let total = 0;
  for (const t of longTokens) {
    const funding = prices.get(t.symbol)?.funding;
    if (funding !== undefined && t.weight > 0) {
      total += -funding * t.weight;
    }
  }
  for (const t of shortTokens) {
    const funding = prices.get(t.symbol)?.funding;
    if (funding !== undefined && t.weight > 0) {
      total += funding * t.weight;
    }
  }
  return total;
}
```

#### Example

Given a basket: 50% long HYPE (funding: 0.01%), 25% short ASTER (funding: 0.03%), 25% short XPL (funding: -0.02%):

```
net = (-0.01% × 0.5) + (0.03% × 0.25) + (-0.02% × 0.25)
    = -0.005% + 0.0075% + (-0.005%)
    = -0.0025%
```

Slightly negative — you're paying a small amount to hold this basket.


---

# 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.pearprotocol.io/api-integration/important-terms/net-funding.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.
