Minor fixes and feats on the SDK needed for the UI - #246
Open
shresthagrawal wants to merge 7 commits into
Open
Conversation
shresthagrawal
force-pushed
the
ts-sdk-realized-pnl-mm
branch
from
July 20, 2026 20:15
ad56323 to
00fd32a
Compare
The orders API reports realized_pnl on PnL-realizing perp fills; decode it from REST history and the WS fill push. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Surface the maintenance-margin total already computed internally on enriched snapshots, plus liquidationBuffer in accountMetrics. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
shresthagrawal
force-pushed
the
ts-sdk-realized-pnl-mm
branch
from
July 20, 2026 20:19
00fd32a to
1d5f591
Compare
Pre-trade cross-margin liquidation estimate matching the venue's reported liquidationPrice. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
What an order does to the existing position: zone, blended entry, margin, realized PnL on the closed slice, post-change liquidation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
shresthagrawal
force-pushed
the
ts-sdk-realized-pnl-mm
branch
from
July 21, 2026 05:56
1d5f591 to
55cdc2d
Compare
Review feedback: one preview module, not two — the liquidation/pro-forma functions move into order-preview.ts unchanged, sharing the position lookup and abs helpers. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Against an opposite-side position the liq-vs-notional curve has a reduce branch and a discontinuity at the exact close; bisecting across it could return meaningless dust sizes. Solve from the exact-close notional for flips (from zero for opens/adds), and report unreachable targets as undefined. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Five self-contained read-side additions, one per commit so they can be cherry-picked independently. Everything is additive — no changes to
transports, signing, or existing behavior.
Order.realizedPnl from REST order history and the WS fill push.
maintenanceMargin / liquidationBuffer (= perps equity − maintenance margin) on accountMetrics.
cash delta). Passed an existing position unchanged it reproduces the venue-reported PerpPosition.liquidationPrice; powers a pre-trade "Est.
liquidation" readout.
same-side adds, margin after, realized PnL on the closed slice, fee, and the post-change liquidation price.
a target) and notionalForLiquidation (order notional whose post-fill liquidation lands on a target).
Verification: estimateLiquidationPrice matches the venue-reported liquidationPrice exactly on all 122 open perp positions across 40 staging
leaderboard accounts; realized-slice PnL and both solver round-trips validated against live staging data; build + typecheck clean at every commit
boundary.