Lifecycle of a Trade

To better illustrate the working mechanisms of the trading engine and various fees and spreads applied, the following example will walk through a complete lifecycle of the trading process and the fees users incur.

1. Opening a position

Opening fee

A trader uses 500 USDT collateral at 5x leverage to open a long position on BTC/USD, where the total position size is 500 x 5 = 2500 USDT

The open trade fee of 0.08% is applied to the position size, which is 2500 * 0.08% = 2 USDT fee

498 USDT is the total collateral value of their newly opened trade, and therefore total position size is 2,490 USDT

Spread and price impact

When opening the trade, the Pyth oracle returned a price of 16500 for BTC/USD.

A base spread of 0.025% is first applied to the price before taking into consideration of price impact:

16500+ (16500 * 0.025%) = 16504.25

Recalling the price impact function above = (Open interest {long/short} + New trade position size / 2) / 1% depth {above/below}.

If we assume 1% depth above is $20M, and there is currently 300,000 USDT long open interest, we can calculate:

Price impact (%): 300,000 + 2490/2 20,000,000 = 0.015%

The value is then added to the base spread, where we get:

Execution price = 16504.25+16504.25*(0.015%) = 16506.73

2. While a position is open

While the trade is still open, rollover and funding fees are applied (see above for in-depth calculation). The front end displays aggregate current holding fees, where green values mean you will be earning money from the position, and red values will cost money and be deducted from your position.

Using the screenshot example above, a trader with a 5x long BTC position will earn 0.0089% per hour from funding rates and pay (0.0136%/5) 0.00272% on your position size (net positive).

It’s important to note that aggregate funding and rollover fees paid/received will also affect your liquidation threshold. If your position earns money from fees, your liquidation price will go further away, whereas if your position is paying fees, your liquidation price may get closer.

Liquidation Price Distance = Open Price * (Collateral * 0.9 - Rollover Fees - Funding Fees) / Collateral / Leverage.

When the position is first opened, the liquidation price is

16500 - 16500 * (498*0.9)/498/5 = 13530

Using the rates above, after 1 hour, the trader would have accrued:

Funding fee: 2490*0.0089% = 0.222

Rollover fee: 498*0.0136% = -0.0677

Hence the liquidation price would be 16500 - 16500 * (498*0.9 - 0.0677 + 0.222)/498/5 = 13,528.98

3. Closing a position

BTC went up 2% after 1 hour, and the trader closed the position at 16836.86. Gross profits before fees would be price change * leverage * position size, or 2%*5*2490 = 249 BUSD.

Closing a trade would require a closing fee, which, similar to opening fees, is charged on the initial position size (without PnL)

2490*0.08% = 1.992

Recall that during the 1 hour, the trade was opened, 0.222 was earned as funding fees, and 0.0677 was paid as rollover fees, which means the net profit is calculated as:

249 - 1.992 + 0.222 - 0.0677 = 247.16

Last updated