Page cover image

Trade lifecycle

This page contains a description of the life cycle of transactions, the main stages of trading on the platform and the calculation formulas used to determine the value of transactions, profit and loss, as well as commissions and spreads.

The page also provides examples of PnL (profit and loss) calculations, and an explanation of the terms used on the platform.

Lifecycle of a long trade

Let's start by setting pool and position parameters for traders:

Depth=400ETHDepth = 400\,\,ETH

Openfee=0.03%Open\,fee = 0.03\%

Basespread=0.05%Base\,spread = 0.05\%

Fundingbaserate=1%Funding\,base\,rate = 1\%

Suppose a trader has decided to open a long position for the ETH/USD pair, using 1000 USDT as their collateral and setting the leverage at x2. After the smart contract receives 1000 USDT, it will calculate and charge an open fee, which depends on the size of the open position and the leverage. For this trade, the commission can be calculated using the following formula:

Openfee=CollateralLeverageOpenfeerate=100020.03%=0.6USDTOpen\,fee = Collateral*Leverage*Open \,fee\,rate = 1000 * 2 * 0.03\% = 0.6\, \,USDT

Where:

  • Collateral - the amount a trader uses to open a position without taking leverage into account

  • Leverage - a multiplier indicating how much a trader's position is increased relative to their collateral

  • Open fee rate - the percentage rate charged by the exchange for opening a position. It may vary depending on the type of traded asset

Then the calculation of the amount of the trader's position takes place:

Openposition=(CollateralOpenFee)Leverage=(10000.6)2=1998.8Open\,position = (Collateral - Open\,Fee)*Leverage = (1000-0.6)*2= 1998.8

The next step is to determine the opening price of the position.

Let's calculate the dynamic spread:

Dynamicspreadforlong=max(0;(Long+0.5LongnewShort)Depth0.1%)=max(0;(100+0.51.33253390)4000.1%)=0.002666566625%Dynamic\,spread\,for\,long = max(0; \cfrac{(Long + 0.5*Long_{new} - Short)}{Depth} * 0.1\%) = max(0; \cfrac{(100 + 0.5*1.332533 - 90)}{400} * 0.1\%) = 0.002666566625\%

Where:

  • Long/Short - the number of short/long positions

  • LongnewLong_{new} - the new long position size

  • Depth - the depth parameter of this asset

The final opening price of the position:

Openlongprice=Currentprice(1+Basespread+Dymamicspread)=1500(1+0.05%+0.002666566625%)=1500.789998Open\,long\,price = Current\,price*(1+Base\,spread+Dymamic\,spread) = 1500 * (1 + 0.05\% + 0.002666566625\%) = 1500.789998

Where:

  • Current price - the current price of the underlying asset in the market

  • Base spread - the fixed base spread

Funding calculations require the value of an open position in ETH:

Long,ETH=OpenpositionOpenlongprice=1998.81500.789998=1.331831904ETHLong, ETH = \cfrac {Open\,position}{Open\,long\,price} = \cfrac {1998.8}{1500.789998} = 1.331831904\,ETH

Where:

  • Long, ETH - the amount of Ethereum that was bought when opening a position

  • Open position - the size of a trader's open position

  • Open long price - the purchase price of Ethereum when opening a position

Fees while holding a position

A borrow fee will be continuously debited from the trader’s account: Borrowrate,perhour=BaserateLeverage=0.001%2=0.002%Borrow\,rate, per\,hour= Base\,rate * Leverage = 0.001\%*2 = 0.002\%

Where:

  • Borrow rate - the interest rate that the trader pays for using borrowed funds

  • Base rate - the base interest rate for borrowing, which depends on the type of asset used when opening a position

Borrowfee,perhour=Borrowrate(CollateralOpenfee)=0.002%(10000.6)=0.19988USDTBorrow\,fee, per\,hour= Borrow\,rate * (Collateral -Open\,fee) = 0.002\% * (1000-0.6) = 0.19988\,USDT

Where:

  • Borrow fee - the commission that the trader pays for using borrowed funds

Since there are more long positions open than short positions, the funding rate will be debited from the trader’s account:

Fundingrate=FundingbaserateLongShortMarketdepth=1%100+1.33183190490400=0.02832957976%Funding\,rate = Funding\,base\,rate * \cfrac {|Long - Short|}{Market\,depth} = 1\% * \cfrac {|100+1.331831904-90|}{400} = 0.02832957976\%

Where:

  • Funding rate - the funding rate that a trader pays or receives depending on the direction of his open position

  • Funding base rate - the base funding rate set by Gravix

  • Market Depth - the depth of the market, which determines how large the open amount of assets must be in order to affect the cost of funding

Longfundingrate=fundingrate=0.02832957976%Long\,funding\,rate = funding\,rate = 0.02832957976\%

The trader will be charged the following hourly amount:

1.331831904ETHETHpriceLongfundingrate=1.331831904ETH1500ETH/USD0.0283313325%=0.56598858759USD1.331831904\,ETH * ETH\,\,price * Long\,funding\,rate = 1.331831904\,ETH * 1500 \,ETH/USD * 0.0283313325\% = 0.56598858759\,USD

Let's calculate the trader's liquidation price after one day:

LiquidationPriceDistance==OpenPrice(Collateral0.9BorrowratesFundingfees)CollateralLeverage==1500.789998(10000.90.19988240.5659885875924)10002=661.562604108Liquidation\,Price\,Distance = \\ = \cfrac {Open\,Price * (Collateral * 0.9 - Borrow\,rates - Funding\,fees)} {Collateral * Leverage} = \\ = \cfrac {1500.789998 * (1000 * 0.9 - 0.19988 * 24 - 0.56598858759 * 24)} {1000 * 2} = 661.562604108

Where:

  • Liquidation Price Distance - the distance between the current price and the liquidation price of the position. It is used to determine when the position will be liquidated

Liquidationprice=OpenpriceLiquidationPriceDistance1Closespread==1500.789998661.56260410810.05%=839.6472175ETH/USDLiquidation\,price = \cfrac {Open\,price - Liquidation\,Price\,Distance}{1-Close\,spread} = \\ = \cfrac {1500.789998 - 661.562604108}{1-0.05\%} = 839.6472175\,ETH/USD

Where:

  • Liquidation price - the price at which the position will be liquidated

Closing a position

We will assume that ETH has risen to 2,000 USD in 24 hours. Let’s calculate how much profit the trader will receive after closing their position:

Closeprice=2000(1Basespread)=2000(10.05%)=1999Close\,price = 2000*(1-Base\,spread) = 2000*(1-0.05\%) = 1999

Where:

  • Close price - the price at which the trader closes their position

The trader’s profit excluding fees is then calculated:

PnLLong=(ClosepriceOpenprice1)(CollateralOpenfee)Leverage==(19991500.7899981)(10000.6)2=663.531975PnL_{\,Long} = ( \cfrac {Close\,price} {Open\,price} - 1) * (Collateral - Open\,fee) * Leverage = \\ = (\cfrac{1999} {1500.789998} - 1) * (1000 - 0.6) * 2 = 663.531975

Where:

  • PnLLongPnL_{\,Long} - the profit or loss from an open position

We then calculate the close fee:

Сlosefee=((CollateralOpenfee)Leverage+PnLFundingfeeBorrowfee)Closefeerate=((10000.6)2+663.5319750.56598858759240.1998824)0.03%=0.793186Сlose\,fee = ((Collateral-Open\,fee) * Leverage + PnL - Funding\,fee - Borrow\,fee) * Close\,fee\,rate = ((1000-0.6) * 2 + 663.531975 - 0.56598858759 * 24 - 0.19988*24) * 0.03\% = 0.793186

Where:

  • Close fee - the commission charged for closing a position

  • Close fee rate - equals the Open fee rate for this type of asset

Finally, we calculate the trader’s profit after payment of all fees:

PnLLong=(ClosepriceOpenprice1)(CollateralOpenfee)LeverageFundingfeeBorrowfeeClosefee=(19991500.7899981)(10000.6)20.56598858759240.19988240.793186=644.3579433PnL_{\,Long} = ( \cfrac {Close\,price} {Open\,price} - 1) * (Collateral - Open\,fee) * Leverage - Funding fee - Borrow fee - Close\,fee = (\cfrac{1999} {1500.789998} - 1) * (1000 - 0.6) * 2 - 0.56598858759 * 24 - 0.19988*24 - 0.793186 = 644.3579433

Where:

  • PnLLongPnL_{\,Long} - profit or loss from an open position

Last updated

Was this helpful?