Menu

The math behind a liquidation price calculator, in TypeScript
📰

The math behind a liquidation price calculator, in TypeScript

DEV Community: javascript·diogenicious·2 days ago
#7lEaSoef
#devtojavascript#devto#dev#leverage#entry
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.