feat(ts-sdk): return a liquidation price in trade previews - #300
Merged
Merged
Conversation
`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>
majesticwizardcat
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
previewOrdernow 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: solveequity(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
maintenanceMarginwhile perps in other markets contribute to it, since their margin rates cannot be derived from the singlemarketthe preview is given. Enriched snapshots always carry the field, so live callers get a number.