Skip to content

feat(ts-sdk): return a liquidation price in trade previews - #300

Merged
0zzy-o merged 3 commits into
mainfrom
feat/preview-liquidation-price
Sep 28, 2026
Merged

0zzy-o merged 3 commits into
mainfrom
feat/preview-liquidation-price

Conversation

@0zzy-o

@0zzy-o 0zzy-o commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

previewOrder now reports the mark at which the account would be liquidated once the order fills. Margin is cross, so it is an account-level number expressed in one market's mark: solve equity(X) = Σ maintenance margin(X) with every other mark held still. Both sides are linear in X, so there is a single root.

It is undefined when no such mark exists — spot, a position that ends flat, or a root at or below zero (a long the rest of the account fully covers) — and when the snapshot carries no maintenanceMargin while perps in other markets contribute to it, since their margin rates cannot be derived from the single market the preview is given. Enriched snapshots always carry the field, so live callers get a number.

`previewOrder` now reports the mark at which the account would be
liquidated once the order fills. Margin is cross, so it is an
account-level number expressed in one market's mark: solve
`equity(X) = Σ maintenance margin(X)` with every other mark held still.
Both sides are linear in X, so there is a single root.

It is undefined when no such mark exists — spot, a position that ends
flat, or a root at or below zero (a long the rest of the account fully
covers) — and when the snapshot carries no `maintenanceMargin` while
perps in other markets contribute to it, since their margin rates cannot
be derived from the single `market` the preview is given. Enriched
snapshots always carry the field, so live callers get a number.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@0zzy-o
0zzy-o merged commit ae15689 into main Sep 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants