B-PNL Calc Demo
Keep in mind that this is still a simplified version and may not fully replicate Binance's exact calculations but I try my best!
This is the amount of money you initially invest in the trade.
Convert the leverage ratio to a multiplier: 1 + (leverage / 100).
Divide the initial investment by the entry price and multiply by the leverage multiplier: (initialInvestment / entryPrice) * leverageMultiplier.
Multiply the contract quantity by the entry and exit prices to get the total value at entry and exit: entryValue = contractQuantity * entryPrice, exitValue = contractQuantity * exitPrice.
The profit or loss is the difference between the exit value and entry value: profitLoss = exitValue - entryValue.
Funding costs are commonly associated with perpetual contracts and are calculated based on the funding rate and the duration the position is held: fundingCost = (entryValue + exitValue) * (fundingRate / 100) * (daysHeld / 365).
Trading fees are calculated as a percentage of the total value of the trade: totalTradingFee = (entryValue + exitValue) * (tradingFee / 100).
Sum up all the costs, including trading fees and funding costs: totalCosts = totalTradingFee + fundingCost.
If you like my repo and want to support me then here is my USDT address on Tron (TRC20) Chain: TLL3LgZeCAn7QsJ8RZuADpn5mawbELwmgx