The margin math, line by line
How an order becomes the venue's integers, the formulas of the pre-trade preview, and where the model stops. The preview's integer arithmetic runs in your browser and in NomaroMarginMath on chain.
From the ticket to a signed order
BaseAmount = size × 10^size_decimals rounded down (never more than typed) Price = price × 10^price_decimals limit: buy rounds down, sell rounds up market = worst price mark × (1 ± slippage), IOC, rounded inside the slippage max leverage = 10000 / min_initial_margin_fraction leverage L -> initial margin fraction ceil(10000 / L), never below the market minimum
size_decimals, price_decimals, minimum size and minimum order value come from the venue's orderBookDetails for each market. The cockpit shows the exact integers before you confirm. The transaction is signed in your browser by the venue's official signer (lighter-go v1.0.13 WebAssembly, hash-pinned) and posted to the venue.
Liquidation by the venue's rule
Account value = collateral + Σ (mark_i − entry_i) × position_i Maintenance = Σ |position_i| × mark_i × maintenance_fraction_i liquidation price of position i, others held at their marks: P = (entry_i × pos_i − K) / (pos_i − |pos_i| × m_i) K = collateral + Σ_other (mark − entry) × pos − Σ_other |pos| × mark × m
This is the venue's published rule (partial liquidation starts when account value falls below the maintenance requirement). On 1 Dec 2026 it reproduced the venue's own liquidation_price within 1 % on live multi-position accounts (unit test with that snapshot). With an open position, the venue's number is shown and is the one that counts.
Preview inputs
Side (long or short), entry price P0 (your limit price, or the mark for a market order), position size N in USD at entry (size × P0), initial margin M = N / leverage, the venue's taker fee f per side and maintenance fraction m for the market. Funding F is 0 in the preview; the venue charges it hourly.
At a price P
PnL = side × N × (P − P0) / P0 side = +1 long, −1 short exit value = N × P / P0 fees = N × f + exit value × f funding = N × F margin left = M + PnL − fees − funding of margin = PnL / M maintenance = exit value × m liquidated = margin left ≤ maintenance
The order's example: long, N = $1,000, M = $100, P = P0 × 0.97 gives PnL = 1,000 × (−0.03) = −$30, which is −30 % of the margin, $70 left before fees and funding.
Single-position estimate (preview curve)
long: P_liq = P0 × (N − M + N×f + N×F) / (N × (1 − f − m)) short: P_liq = P0 × (N + M − N×f − N×F) / (N × (1 + f + m))
Used for the curve and the ladder: where margin left meets maintenance for this position alone, counting the exit fee. The readout above the gauge uses the venue's rule with your real account instead.
Units and rounding
Prices carry 8 decimals, USD amounts 6 decimals, rates are parts per million. Every division truncates toward zero, in the browser (BigInt) and on chain (Solidity), so both give the same integers. The cockpit's "Check against contract" tab compares all eleven output fields for nine prices in one call.
What the model leaves out
- The path of the price: the preview checks one price at a time, not whether a wick touched liquidation on the way.
- Funding accrual, fills against the book (slippage beyond the worst price is refused by the venue), pending orders and partial liquidations.
- Anything the venue changes: its parameters are read live, and its own numbers win.
Optional: seal a trade plan (NomaroSketchSeal)
commitment = keccak256(abi.encode(TAG, chainId, contract, sealer, sketch, salt)) seal(commitment, feed, checkAt) checkAt between now + 1 hour and now + 365 days reveal(id, sketch, salt, roundId) from checkAt until checkAt + 30 days roundId must be the FIRST round of the sealed feed with updatedAt >= checkAt (its round has updatedAt >= checkAt, the round before it has updatedAt < checkAt)
The contract recomputes the outcome at that round's price and stores it with the event. A seal that is not revealed in time lapses and stays counted against its sealer. No funds, no owner, no admin, no upgrade.
Reference feeds
- ETH / USD · 0x78f3556b67e17df817d51ef5a990cdaf09e8d3a9
- RHNVDA / USD · 0x379ec4f7c378f34a1b47e4f3cbebcbac3e8e9f15
- RHTSLA / USD · 0x4a1166a659a55625345e9515b32adecea5547c38
- Robinhood AAPL / USD · 0x6b22a786baa607d76728168703a39ea9c99f2cd0
- RHSPY / USD · 0x319724394d3a0e3669269846abe664cd621f9f6a
- Robinhood QQQ / USD · 0x80901d846d5d7b030f26b480776ee3b29374c2ae
Previews are not future results. Perpetual futures can lose your whole margin. Not financial advice. Open the cockpit.