whatif_order
Simulate a hypothetical order's margin impact and commissions using IB's what-if engine, without sending any order to market.
Instructions
IB's own margin impact for a hypothetical structure. Nothing reaches the market.
Each order carries whatIf=True, which IB evaluates in its margin engine
and discards: it is never routed, never acknowledged as live, never appears
in the order book. The tool is still gated behind IBKR_ENABLE_WHATIF=true
because it is the only thing in this server that touches the order path at
all; with the gate closed it sends nothing and returns blocked: true.
Returns initMargin, maintMargin and equityWithLoan before/after/change, plus commission and any warningText, in two views:
perLeg— each leg evaluated on its own.cumulative— legs 1..k as a combo, for every k, so you can see where the offset appears.
Read the combined figure, not the sum of the legs. SPAN offsets the legs
against each other and against what the account already holds, so the two
differ — the difference is reported as offset.spanOffset. IB's what-if on
arbitrary multi-leg combos is unreliable and will sometimes return nothing;
that is reported per step and does not mean the structure is invalid.
If every call fails with no margin figures, check whether TWS has "Read-Only API" enabled — that setting blocks what-if orders too.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| legs | Yes | The structure to evaluate. Each leg is a conid, or symbol+secType+expiry+strike+right, with action BUY/SELL and a quantity. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||