Ladder Max Leg
workflow.run_ladder_max_legLargest equal leg, in whole contracts, for a scale-in ladder of D legs (linear perpetuals, cross margin). Edge cases: linear perpetuals and cross margin only; legs, step or steps, equity and leverage must describe a real ladder, and an unknown symbol or an unreachable exchange gives available false. Result is capped at 10,000,000 contracts. Not covered: isolated margin, inverse contracts, fees, funding, slippage between legs, and the exchange own liquidation engine; liq_buffer is our model of cross margin. Use when user asks "how many contracts per leg can I put on a ladder of 8 legs at 3x with this equity?". Legs chain from currentPrice: each is step further against the position (a short ladder climbs, a long ladder falls); an existing position (existingCt) is leg 1, the other legs-1 are new; oppositeCt is a hedge on the other side (adds to exposure, its PnL moves with price). equity is the account equity measured at currentPrice. mode "leverage" (default): after every leg, gross contracts x ctSize x price <= leverage x equity at that price (equity includes the loss of every position at that price); liquidation does not take part; fees are not in equity. mode "liq_buffer": the cross-margin liquidation price of the full ladder, from the exchange's live maintenance-margin tiers (exchange and symbol, same tables as workflow.run_liquidation_live), must stay beyond the last leg by at least bufferPct (0.3 for 30%); on OKX pass liqFeeRate (the taker fee rate). Mode liq_buffer does not apply the leverage cap (exposureOverEquityAtLastLeg shows the result) and respects the exchange's largest position (checked at each leg's own price after it fills, not at a later mark); it is our model of cross margin (the opposite side is a fixed oppositeMaintenanceMargin), not the exchange's engine, and the exchange may report no liquidation price for a hedged account. It looks for liquidation in the ladder's adverse direction only: when none exists (noLiquidationInLadderDirection true, for example a larger opposite hedge) the buffer is not a safety statement. Give step (one fraction for every gap) or steps (legs - 1 fractions). Returns: available (false + error when the symbol is unknown or the exchange cannot be reached), maxLegCt (0 when nothing fits, with reason), newLegs, legs [{leg, price, newCt, ladderCt, load}], bindingLeg (leverage), capped (true when the 10,000,000-contract ceiling of the tool was hit), liq_buffer: liqPrice, noLiquidationInLadderDirection, note, limitedBy (buffer, exchange_max_position or ceiling), actualBufferPct, requiredLiqLevel, exposureOverEquityAtLastLeg, tierTable.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"side": "<side>",
"currentPrice": "<currentPrice>",
"equity": "<equity>",
"legs": "<legs>",
"ctSize": "<ctSize>"
},
"name": "workflow.run_ladder_max_leg"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| legs | Yes | D: total legs, the existing position counts as leg 1 | |
| mode | No | Which definition of "the leg fits"; default leverage | |
| side | Yes | Ladder side | |
| step | No | One fraction for every gap between legs, 0.01 for 1% | |
| steps | No | One fraction per gap, legs - 1 values (instead of step) | |
| ctSize | Yes | Base units per contract, e.g. 0.01 for OKX BTC-USDT-SWAP | |
| equity | Yes | Account equity in the quote currency at currentPrice | |
| symbol | No | liq_buffer: symbol as the exchange writes it | |
| exchange | No | liq_buffer: exchange whose tiers are read | |
| leverage | No | Leverage cap on gross exposure / equity. Required for mode leverage; not used by mode liq_buffer | |
| bufferPct | No | liq_buffer: required distance of the liquidation price beyond the last leg, a fraction | |
| existingCt | No | Contracts already held on the ladder side, default 0 | |
| liqFeeRate | No | liq_buffer, OKX only: forced-liquidation fee rate, a fraction | |
| oppositeCt | No | Contracts held on the other side, default 0 | |
| currentPrice | Yes | Price of leg 1 (the existing position is valued from here) | |
| oppositeMaintenanceMargin | No | liq_buffer: maintenance margin of the other side, default 0 |