Order Types Deep Dive¶
Objective¶
Explore every order type beyond basic LIMIT and MARKET — STOP, STOP_LIMIT, FOK, IOC, ICEBERG, and TRAILING_STOP — through practical exercises.
Background reading
Prerequisites¶
- Chapters 01–04 completed.
TRADER01,TRADER02, the operator console and theMM_AAPL_01console connected to the current engine (Exercise 5 also usesMM_TSLA_01).- The MSFT market-maker quote from chapter 02 still resting (Exercise 4 trades
against its 300-share ask at 420.10). If
BOOK|SYM=MSFTshows otherwise, send it again fromMM_MSFT_01:QUOTE|SYM=MSFT|BID=419.90|ASK=420.10|BID_QTY=300|ASK_QTY=300|TIF=DAY|QUOTE_ID=MSFT-MM-005.
Deterministic Trigger Setup¶
Stop and stop-limit orders only trigger when the market actually trades through their trigger price — quotes alone never trigger them. To make the exercises below behave exactly as described, build the AAPL book yourself before each one, with the market maker's console placing ordinary limit orders:
-
Clear AAPL from the operator console (this cancels every order and quote on it), and stop any
pm-mm-botquoting AAPL: -
Give the book two bids, one above and one below the trigger level you will use (149.50):
-
Make a trade above the trigger, so the last traded price is 149.60 and a sell stop at 149.50 is not triggered the moment you place it:
Now only the 200-share bid at 149.30 is left in the book.
Exercise 1: Stop Order¶
A stop order becomes a market order when the trigger price is reached.
After the setup above, place a stop-sell — the order a trader holding AAPL would use to limit the loss if the price falls:
The order is acknowledged and then lies dormant: it is not in the visible
book. Now let the market fall through 149.50 — TRADER02 sells into the
149.30 bid:
That trade at 149.30 is at or below the stop, so the stop triggers and becomes a market sell, which fills against the remaining 100 bid at 149.30:
Interpretation: 149.50 was the trigger, not the execution price. A stop guarantees that you get out, not at what price — in a falling market the fill can be well below the stop.
Checkpoint: the stop triggered on a trade below 149.50 and filled at 149.30.
Exercise 2: Stop-Limit Order¶
Like a stop, but becomes a limit order (not a market order) when triggered. Repeat the setup, but with the lower bid at 149.00 instead of 149.30, so that the market will gap through your limit:
[GW_ADMIN|ADMIN]> CANCEL_SYM|SYM=AAPL
[MM_AAPL_01]> NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=149.60|TIF=DAY
[MM_AAPL_01]> NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=200|PRICE=149.00|TIF=DAY
[TRADER02]> NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=100|PRICE=149.60|TIF=DAY
Place the stop-limit:
STOP=149.50 controls when the order is activated; PRICE=149.40 is the
worst price you will accept once it is. Now trade through both levels:
The trade at 149.00 triggers the stop, and a limit sell at 149.40 is placed —
but the only bid left is at 149.00, below your limit, so nothing fills. The
order now rests on the ask side at 149.40 (check with BOOK|SYM=AAPL and
ORDERS). A plain stop would have sold at 149.00; the stop-limit protected
the price and gave up the certainty of getting out.
Checkpoint: the stop-limit triggered and rests as a limit sell at 149.40.
Before the next exercise, cancel the resting stop-limit and let the market maker quote AAPL again:
[TRADER01]> CANCEL|ID=<stop-limit order id>
[MM_AAPL_01]> QUOTE|SYM=AAPL|BID=149.95|ASK=150.05|BID_QTY=500|ASK_QTY=500|TIF=DAY|QUOTE_ID=AAPL-MM-005
Exercise 3: Fill-or-Kill (FOK)¶
FOK demands the entire quantity in a single all-or-nothing execution (which may sweep several resting orders) or cancels:
The market maker offers only 500, so the ask side doesn't have 1000 shares at
or below 150.10, and the order is rejected at once with
code=INSUFFICIENT_LIQUIDITY — nothing trades.
Try with a smaller qty that the MM can fill:
Checkpoint: large FOK rejected; small FOK filled.
Exercise 4: Immediate-or-Cancel (IOC)¶
IOC fills as much as possible immediately, then cancels the rest:
If only 300 are available at the ask, you get 300 filled and 700 cancelled.
Checkpoint: partial fill + cancellation of remainder.
Exercise 5: Iceberg Order¶
An iceberg shows only a visible "peak" quantity while hiding the reserve. First give TSLA a known book: chapter 04 left orders of its own on it, and its market-maker quote was cleared there. Clear TSLA and have the market maker quote it again:
[GW_ADMIN|ADMIN]> CANCEL_SYM|SYM=TSLA
[MM_TSLA_01]> QUOTE|SYM=TSLA|BID=249.75|ASK=250.25|BID_QTY=200|ASK_QTY=200|TIF=DAY|QUOTE_ID=TSLA-MM-005
Then place the iceberg:
The book shows only 100 visible. When those 100 fill, another 100 automatically appears until the full 1000 is done.
Check the book:
You should see the market maker's 200-share bid at 249.75 and, below it, a
100-share bid at 249.70 — not 1000 — next to the market maker's 200 ask at
250.25. (The iceberg's price is one tick below the market maker's bid on
purpose: BOOK adds up all orders at one price, so at 249.75 you would see
the market maker's 200 plus your 100.)
Checkpoint: only peak quantity visible in the book.
Exercise 6: Trailing Stop¶
A trailing stop follows the market by a fixed offset. To watch it work you control every trade, as in the setup above. Clear AAPL again and create a last traded price of 150.00:
[GW_ADMIN|ADMIN]> CANCEL_SYM|SYM=AAPL
[MM_AAPL_01]> NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=100|PRICE=150.00|TIF=DAY
[TRADER02]> NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=150.00|TIF=DAY
Now place the trailing stop. No STOP= is given, so the engine derives the
initial trigger from the last traded price minus TRAIL: 150.00 − 0.20 =
149.80.
Without a trade, no automatic trigger
If AAPL has no trade history, a TRAILING_STOP without an explicit
STOP= is rejected — pass STOP=<price> to set the initial trigger
yourself, e.g. STOP=149.80.
Put a bid in the book for the stop to sell into once it fires (it becomes a market sell), well below the trigger so it does not interfere:
Let the price rise. A trade at 150.50 drags the stop up to 150.30 (150.50 − 0.20); nothing happens visibly:
[MM_AAPL_01]> NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=100|PRICE=150.50|TIF=DAY
[TRADER02]> NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=150.50|TIF=DAY
Let it reverse. A trade at 150.30 reaches the (raised) stop. Had the stop stayed at 149.80 this trade would not have touched it:
[MM_AAPL_01]> NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=150.30|TIF=DAY
[TRADER02]> NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=100|PRICE=150.30|TIF=DAY
TRADER01's console now reports the stop's market sell, filled against the
149.70 bid:
The stop only moves up (for a sell) or down (for a buy) — never against you — and, like a plain stop, it guarantees the exit, not the price: it was triggered at 150.30 and sold at 149.70.
Checkpoint: the trailing stop sat unfilled while the price rose, then sold at 149.70 after the reversal to 150.30.
Order Type Summary¶
| Type | Execution | Rests? | Key Parameter |
|---|---|---|---|
| MARKET | Immediate, best price | No | — |
| LIMIT | At price or better | Yes | PRICE |
| STOP | Dormant → market on trigger | Until triggered | STOP |
| STOP_LIMIT | Dormant → limit on trigger | Until triggered, then yes | STOP, PRICE |
| FOK | All-or-nothing, immediate | No | QTY, PRICE |
| IOC | Fill what you can, cancel rest | No | QTY, PRICE |
| ICEBERG | Hidden reserve, visible peak | Yes | VISIBLE |
| TRAILING_STOP | Dynamic stop follows market | Until triggered | TRAIL |
Reflection¶
Why does STOP_LIMIT exist at all, given that a plain STOP order guarantees execution once triggered? What real trading scenario would make a trader prefer a STOP_LIMIT's "might not fill" risk over a STOP's "might fill at a bad price" risk?