Combos
Several option legs sent as one order: spreads, straddles and the rest.
legs = [
while25.leg(while25.option("SPY", "2026-11-20", "PUT", "ATM-4"), "BUY"),
while25.leg(while25.option("SPY", "2026-11-20", "PUT", "ATM-2"), "SELL"),
while25.leg(while25.option("SPY", "2026-11-20", "CALL", "ATM+2"), "SELL"),
while25.leg(while25.option("SPY", "2026-11-20", "CALL", "ATM+4"), "BUY"),
]
c = while25.combo(legs, lots=1, name="Iron condor")
c["combo_id"] # what cancel(), square_off() and my_position() name it bywhile25.combo() places two to ten option legs as ONE combo: a spread, a
straddle, an iron condor, placed the way Deploy in Options Execution places a
design, through the same placer. Legs sent as separate orders can fill one and
miss the next, leaving a position nobody chose; a combo goes to the broker as
one order where the broker takes one, and all or none where it does not
(below). while25.orders.combo() is the same call.
A leg is while25.leg(contract, side, ratio=1, price=None):
| Argument | Takes |
|---|---|
contract | an option's instrument key, or the dict while25.option() returned |
side | "BUY" or "SELL", in any capitals |
ratio | how many lots of this leg per lot of the combo: a whole number, 1 or more (1 and 2 for a 1x2 ratio spread) |
price | this leg's own limit, on an "LMT" combo only (below) |
leg() checks what it is given on the line that writes it, and returns a
plain dict. A dict you write yourself with the same four keys
(instrument_key, side, ratio, price) is a leg too; any other key in it
is refused, so a "qty" or a "lots" never quietly leaves a leg of ratio 1.
A combo is 2 to 10 legs, and names each contract once.
lots= is how many of the combo, a whole number, 1 or more. Each leg's
order is lots x its ratio x its contract's own lot size, as While25's
instrument list states it: one contract per lot on a US option, the
exchange's lot on an Indian one. You never write a leg's quantity, and a
contract whose lot size is not on file is refused (NO_LOT_SIZE) rather than
sized by a guess.
Market, or each leg's own limit — never a mix. order_type= is every
leg's:
"MKT"(the default): no leg states a price."LMT": every leg states its own limit, above 0, in the figures any price takes (aDecimal, anint, plain decimal text, or an exact float). Where the broker takes the combo as one order, its limit is the legs' limits netted by ratio: a bought leg adds and a sold leg subtracts, so a credit is negative, as IBKR writes it. Leg by leg, each leg works at its own limit.
legs = [while25.leg(put_far, "BUY", price="1.10"),
while25.leg(put_near, "SELL", price="2.05"),
while25.leg(call_near, "SELL", price="1.95"),
while25.leg(call_far, "BUY", price="1.00")]
while25.combo(legs, order_type="LMT") # as one order: 1.10 - 2.05 - 1.95 + 1.00 = -1.90, a 1.90 creditA limit combo with a leg stating no price, and a market combo with a leg
stating one, are refused (ValueError) before anything is sent: the one
order's limit is built from every leg's price, so a missing one would leave it
unset, and a stray one would put a limit on an order nobody priced.
product=, validity= and hours= apply to every leg and read as
place()'s do (hours="rth" is refused: leave it out for regular hours).
name= (at most 64 characters) is the combo's name on Options Execution, Open
orders and the Positions tab, and tag= (at most 20) rides on every leg's
orders and events. Left out, the name is the strategy's id, and the tag is
py: and that id, as on any order of the strategy placed with no tag. Every
call mints its own idempotency_key= unless you pass one, as place() does.
How it goes to the broker:
| Broker | |
|---|---|
| IBKR | one combo order of up to 6 legs; a combo of more legs goes leg by leg |
| Alpaca | one combo order of 2 to 4 legs; more go leg by leg. Options only, validity DAY only (left out, it is DAY; any other is refused), regular hours only (hours="eth" is refused), and a limit combo's net on Alpaca's 0.01 tick |
| Upstox, Zerodha | leg by leg, in the order the legs are listed |
Leg by leg it is all or none: a refused leg withdraws the legs not yet
filled, and a leg that already filled stays, for your script to deal with.
The answer's one_order says which way it went.
What it answers, once While25 has handed the combo on:
{"ok": True, "combo_id": ..., "order_ids": [...], "one_order": bool, "deployment_number": int}. order_ids is each leg's order, in the order the
legs were given; deployment_number is the combo's number on Options
Execution (#5; 0 when it has none). Every event of its legs carries
ev["combo_id"] and your tag=, so a handler tells the combo's fills from
everything else:
@on.fill(tag="condor")
def on_fill(self, ctx, ev):
if ev["combo_id"] == self.combo_id:
ctx.log(f"{ev['symbol']} {ev['side']} {ev['last_fill_quantity']} @ {ev['last_fill_price']}")A refusal raises While25Error with its code, as a refused place() does,
and nothing is placed. The SDK refuses what it can judge itself in words
(ValueError) before anything leaves your script; While25 judges again:
| code | meaning |
|---|---|
BAD_COMBO | not 2 to 10 legs, a contract twice, a side that is not BUY or SELL, a ratio or lots below 1 |
BAD_ORDER_TYPE | an order type that is not "MKT" or "LMT" |
BAD_PRICE | a limit leg with no price above 0, or a market leg with one |
BAD_PRODUCT, BAD_VALIDITY, BAD_HOURS | as for place(), "rth" included |
BAD_TAG, BAD_NAME | a tag over 20 characters, a name over 64 |
NOT_AN_OPTION | a leg that is not an option contract |
NO_LOT_SIZE | the instrument list states no lot size for a leg's contract |
INSTRUMENT_RESOLVING | a leg's contract is still being fetched from the venue: call combo() again in a moment |
INSTRUMENT_NOT_FOUND | the venue does not list a leg's contract |
KILL_SWITCH_ACTIVE | the kill switch is on |
DUPLICATE_ORDER | the idempotency_key= was used already: a resubmit needs a fresh key |
COMBO_REFUSED | the placer refused it; the message is its words |
NOT_LIVE, NOT_READY, BUSY, STORE_ERROR | the platform is not on the live account; While25's order path is not up yet; too many script orders are queued; the combo's record could not be written |
| the grant codes | NO_LIVE_GRANT, GRANT_STALE, MODULE_STOPPING and the rest every order hears |
What it holds is the combo's own. What its legs fill belongs to the combo,
held by your strategy, and never joins your strategy's part of each contract:
while25.portfolio.my_position(key)["quantity"] leaves it out, exactly as it
leaves a bracket out, and my_position(key)["combos"] lists it, one entry per
combo holding that contract:
| Key | |
|---|---|
combo_id, label | the combo, and its name as Options Execution shows it ("#5 Iron condor"; "Combo" when it has no deployment) |
quantity | what the combo holds of this contract, a signed Decimal |
product | its pocket, as on a part |
average_price, last_price | Decimal, or None when not known |
pnl | While25's unrealised P&L on it, a Money, or None when the price or the multiplier is not known |
deployment_number | its number on Options Execution; 0 when it has none |
A contract you hold only through a combo is listed too, with its own
quantity Decimal(0), and my_positions() lists every contract once. In
while25.orders.mine() a combo's legs still working appear under their own
order ids with role "COMBO_LEG": they are cancelled with the combo, never
alone.
Cancel it, or square it off — always whole.
while25.orders.cancel(c["combo_id"]) cancels every leg still working, as one
order where the broker holds one, and each leg hears CANCEL. A combo is
never cancelled or changed a leg at a time: a leg's own id is refused
COMBO_LEG by cancel() and modify() on every broker (where the legs
went one by one, a cancelled leg would leave its siblings working with no
unwind). To change a combo, cancel it by its id and place it again. The
cancel is refused NOT_ORDER_OWNER when the combo is not your module's, and
NOT_WORKING when nothing of it is working.
while25.orders.square_off(c["combo_id"]) does what Sq Off does on its row in
Options Execution: its legs still working are cancelled, then what it holds is
closed at market, as one combo order where the broker takes one. It answers
once While25 has taken it, with {"ok": True, "square_off_id": ..., "bracket_id": ...} (bracket_id is the combo's id here). Each close arrives
as NEW and FILL under its own id, with ev["combo_id"] set, and one
SQUARE_OFF event under the combo's id, with its tag=, says how it went:
ev["status"] | when |
|---|---|
SENT | the closes went out: ev["reason"] lists them and ev["close_order_id"] names the first |
DONE | it held nothing to close: its legs still working were cancelled |
REFUSED | it could not start; ev["reason"] says why, and nothing was closed |
STOPPED | nothing could go out; ev["reason"] says why |
Refused at once, with nothing sent: NO_BRACKET (the id names no open combo,
nor bracket, of your module), NOT_ORDER_OWNER, MARKET_CLOSED, NOT_LIVE,
NOT_READY and BUSY.
In the app. Options Execution's Running list shows the combo as
#N <name>, with no saved design behind it: its Sq Off and Cancel work as for
any deployment, and it has no Add. Open orders and the Positions tab show it
under the same #N.
Stopping the strategy. The Stop window lists each combo that holds something, with what each choice does to it: "Stop and cancel its orders" keeps it (and cancels a combo still working, whole), "Stop and square off" closes it whole, as one combo order where the broker takes one.
An iron condor, entered on the first bar and closed whole if SPY closes beyond either short strike:
import while25
from while25 import Strategy, on
class SpyCondor(Strategy):
id = "spy_condor"
combo_id = None
closing = False
@on.bar("EQ:US:SPY", "5m")
def on_bar(self, ctx, bar):
if self.combo_id is None:
picks = [(while25.option("SPY", "2026-11-20", right, strike), side)
for right, strike, side in (("PUT", "ATM-4", "BUY"),
("PUT", "ATM-2", "SELL"),
("CALL", "ATM+2", "SELL"),
("CALL", "ATM+4", "BUY"))]
c = while25.combo([while25.leg(p, side) for p, side in picks],
lots=1, name="Iron condor", tag="condor")
self.combo_id = c["combo_id"]
self.low, self.high = picks[1][0]["strike"], picks[2][0]["strike"]
elif not self.closing and not self.low < bar["close"] < self.high:
while25.orders.square_off(self.combo_id) # the whole condor, at market
self.closing = True
@on.order(tag="condor")
def on_order(self, ctx, ev):
if ev["event"] == "SQUARE_OFF" and ev["combo_id"] == self.combo_id:
ctx.log(f"square off {ev['status']}: {ev['reason']}")On NIFTY the same lines name NIFTY's contracts
(while25.option("NIFTY", "28th", "PE", "ATM-2")), lots=1 is one NIFTY lot
of each leg, and on Upstox or Zerodha the legs go one at a
time, all or none. combo() works in a running strategy or trading app; a
one-shot run is refused NOT_IN_RUN. While25 takes at most 1,000,000
lots, and a ratio of at most 10,000 on a leg.