A Bitmex perpetual swap contract is an inverse futures contract which has no settlement date and never expires. Each contract is worth 1 USD and traders can hold open positions for as long as they want.
If you’re not familiar with futures and more so with inverse futures, please check out these articles first:
There is a small problem though with these futures contracts which never expire. In a regular futures market, the price tends to converge to the index price when the settlement/delivery date is nearing, since there’s less and less uncertainty about where the price will be in the future. Delivery keeps price tethered to the index since traders know their positions will be closed against the index anyways on expiry/settlement.
How does one tie a futures contract to an index if there’s no settlement/expiry? Bitmex.com does this through the mechanism which they call “funding”. It is intended to replicate the interest payments mechanics between longs and shorts in a regular spot market with lending and borrowing for margin trading, like at bitfinex.com for instance.
When you hold USD at a spot margin exchange, you essentially short on BTC/USD pair, if the price goes down you can buy more BTC with your fiat money. While being short on BTC/USD, you can lend your USD and receive an interest (if the trading platform supports borrowing and lending).
Those who borrow USD, use it to open long positions, and if there’s a bull market the demand to borrow is high, which makes lending rates rise. In such case, those who go long pay interest to those who are short (by holding fiat). At some point, if the interest rates rise high enough, long traders will start to close their positions. Some will do it to begin lending at favourable rates themselves, and some will do it because keeping a long position on margin becomes more and more expensive (bitfinex.com, for example, automatically reborrows funds for you to keep your margin position open at the best available rate).
The same thing happens when there’s a high demand to go short. If the rates to borrow BTC to sell it short become high enough, some portion of short sellers will begin to close their short positions because keeping it open becomes more and more expensive. And some will even want to close their shorts and buy BTC to lend it at excellent rates.
This market dynamic is what bitmex.com funding supposed to resemble. Bitmex.com calculates a premium/discount of the futures price against the index (can be seen here https://www.bitmex.com/app/index/.XBTUSDPI). At some point, if there are enough open long positions, there will be upwards futures price deviation against the underlying index price. In such case, those who are long will have to pay interest (funding fee) to those who are short. If the funding fee is big enough, it will make some portion of positions to close and some to open in the opposite direction to receive a funding fee, this will make the price converge to the index price.
Funding happens every 8 hours, and you only pay if you have an open position in the perpetual contract. Negative funding rate indicates that shorts will pay longs, and if a fee is positive longs will pay shorts. To avoid paying a fee, traders can close their positions. Those who want to receive a funding fee can open a position just for this purpose.
The amount of funding you will pay or receive is calculated like this:
Funding = Position Value * Funding Rate
Whole notional value of your open position is used. For example, if the total worth of your position is 1 BTC, but your margin is only 0.1 BTC of that (using x10 leverage), you will pay funding on the whole amount, and not on 0.1 BTC only.