> For the complete documentation index, see [llms.txt](https://docs.nekodex.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nekodex.org/nekodex-playground/docs-for-devs/contracts/funding-fee.md).

# Funding Fee

The `fundingFee` contract provides logic for calculating and settling funding fees, as well as querying the funding rate and pending (pre-settlement) funding fees.

## basePool

Funding rates are calculated using `basePool`. If for a given market the `basePool` is not set (ie. set to `0x000...`), funding fees will not be applied in this market.&#x20;

The `basePool` address can be queried using [Config](/nekodex-playground/docs-for-devs/contracts/config.md).

## Contract

<pre class="language-solidity" data-overflow="wrap"><code class="lang-solidity"><strong>/// #notice Check the settlement event to see amount of funding paid/received. This information may also be available from The Graph.
</strong>event FundingFeeSettled(uint256 marketId, address trader, int256 fundingFee);

function getCurrentFundingRate(uint256 marketId) public view returns (int256)

/// @notice Amount of pending fees from the trader's perspective.
/// @return When settled, margin will decrease if fee is positive, increase if fee is negative.
function getPendingFee(
    uint256 marketId,
    address trader
) 

returns (
    int256 pendingFee
)

/// @notice Query latest funding rate. Historical funding rates should be queried from The Graph or similiar provider.
function getCurrentFundingRate(
    uint256 marketId
)

returns (
    int256 fundingRate
)
</code></pre>


---

# 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://docs.nekodex.org/nekodex-playground/docs-for-devs/contracts/funding-fee.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.
