Most leverage calculators hide one small piece of algebra. Here it is, derived step by step, with a TypeScript function you can paste into a project.
Disclosure: I am the founder of copy.top. We publish a free leverage and liquidation calculator , and this post explains the math behind that kind of tool. The code below is a minimal version written for this article.
The setup
You post some margin , choose a leverage , and open a position at an entry price.
Position size in quote currency: notional = margin * leverage
Position size in coins: quantity = notional / entry
The exchange closes the position when your equity falls to the maintenance requirement.…