Create your own
Lesson illustration

Order Types, Order Books, and Time-in-Force Constraints

Hello. In the previous lesson, we established that the bid, ask, spread, and available depth determine an algorithm’s attainable price. The remaining question is operational: how does the algorithm express whether it values speed, price protection, or a chance to wait for a better fill?

This lesson examines the three foundational order instructions—market, limit, and stop orders—and the time-in-force constraints that determine how long an order may remain active. By the end, you should be able to look at a small order book and predict whether an order executes immediately, rests in the book, fills only partly, or is cancelled.


An order is a precise execution instruction

A trading signal such as “buy 600 shares” is incomplete. To make it executable, the system must specify at least:

  • side: buy or sell;
  • quantity: how much to trade;
  • order type: market, limit, stop, or stop-limit;
  • price fields: a limit price and, where applicable, a stop trigger;
  • time in force: how long the instruction remains eligible to execute;
  • venue and broker-specific settings: relevant especially for stop triggers and routing.

The core trade-off is simple:

PriorityOrder choice tends to favorCost
Execution certaintyMarket orderExecution price is uncertain
Price protectionLimit orderFill is uncertain
Conditional actionStop orderTrigger and final execution are distinct events
Immediate decisionIOC or FOK constraintThe unfilled portion, or all of it, may be cancelled
PatienceDay or GTC constraintMarket conditions can change while waiting

A useful mental model is that market orders consume existing liquidity, while resting limit orders offer liquidity to future traders. In market-microstructure terminology, the former take liquidity and the latter make liquidity.

Investor Bulletin: Understanding Order Types | Investor.gov

Read the SEC’s Investor.gov bulletin for its clear, broker-neutral definitions of the order types and timing restrictions used in this lesson. Its central distinction is exactly the one an execution algorithm must make: immediate execution is not the same as price certainty.

In the “MARKET, LIMIT and STOP ORDERS” section, begin with market-order execution, noting why the last traded price does not guarantee your fill. Then read the limit-order discussion through the price-versus-fill trade-off. Finish the stop-order discussion, beginning “A stop order, also referred to as a stop-loss order,” and focus on the trigger-versus-execution distinction. Then move to “TIMING RESTRICTIONS AND TRADING INSTRUCTIONS.” Read from the Day-order definition through the All-Or-None definition, using these common constraints to compare the meaning of Day, GTC, IOC, FOK, and AON. Treat “On Open” and “On Close” as useful special scheduling instructions, but not the main focus today.


Market orders: prioritize immediacy, not a known price

A market order says: execute now at the best prices available when the order reaches the venue. It does not state a maximum purchase price or minimum sale price.

Consider this simplified book immediately before your order arrives:

Ask priceShares offeredBid priceShares bid
100.021,00099.99800
100.0150099.98600
100.00200

A market buy for 600 shares consumes the ask side, beginning with the lowest ask:

  1. It buys 200 shares at 100.00.
  2. It buys the remaining 400 shares at 100.01.

Its volume-weighted average execution price is:

The order has walked one level into the book. A market sell would do the mirror image: consume the highest bid, then lower bids if necessary.

How orders affect the order book

Watch Udacity’s “How orders affect the order book” for a compact visual treatment of exactly this book interaction. It reinforces that order type, order size, and available depth jointly determine the fill.

Watch the market buy to see a small order remove quantity from the best ask. Then watch the limit buy, paying attention to why an executable limit can receive a better price than its stated cap. Finish with book walking, where a larger sell order consumes several bid levels and therefore receives a progressively worse average price.

A simplified limit order book: sell limit orders sit above the current market and buy limit orders below it. The blue market order removes resting sell liquidity at the best ask, while new and cancelled limit orders continuously reshape the visible book.

For a market order, the displayed book is only a snapshot. Before your order reaches the exchange, other participants may consume or cancel the displayed offers. Thus even the calculated 100.0067 is a book-based estimate, not a promise.

A market order is therefore sensible when:

  • the desired size is small relative to immediately available liquidity;
  • completing the trade is materially more valuable than controlling a few ticks of price;
  • the instrument is liquid and the spread is stable;
  • the strategy is not so cost-sensitive that a modest adverse fill destroys expected alpha.

For a large or fast-moving order, “market” should not be interpreted as “safe.” It provides a high likelihood of execution, but it can produce poor prices in a thin or rapidly changing book. A market order has no price at which it can rest; any unfilled remainder is normally cancelled or handled according to venue and broker rules.


Limit orders: a price boundary, not necessarily a passive order

A limit order sets an execution boundary:

  • A buy limit executes only at its limit price or lower.
  • A sell limit executes only at its limit price or higher.

The limit price is not necessarily the execution price. It is the worst acceptable price.

Return to the book above. A buy limit for 600 shares with a limit of 100.01 is immediately executable. It can buy 200 shares at 100.00 and 400 shares at 100.01, with the same average price as the market buy. Its difference from the market order is protection: it cannot pay 100.02 or more.

This is called a marketable limit order: its limit crosses the current spread and matches against resting liquidity immediately. It takes liquidity just as a market order does, but keeps an explicit price ceiling.

Now change the instruction to a buy limit for 600 shares at 100.00:

  • The 200 shares offered at 100.00 execute immediately.
  • The remaining 400 shares cannot buy at 100.01, because that would violate the limit.
  • Unless an immediate-cancellation condition applies, the remaining 400 shares become a resting bid at 100.00.

The order has had a partial fill. It has price protection, but not completion certainty.

Passive limits and queue position

A buy limit below the best ask, or a sell limit above the best bid, normally becomes a passive limit order. It waits for another participant to trade at its price.

If several orders are waiting at the same price, most electronic markets typically apply a form of price-time priority:

  1. Better-priced orders have priority.
  2. Among orders at the same price, earlier arriving orders usually have priority.

So a buy limit at the best bid is not simply “waiting for price to touch my level.” It may be behind substantial quantity already waiting at that price. Trades need to consume those earlier orders before your order fills. The exact priority model varies by venue and order type, but a basic backtest that assumes an instant fill whenever the bar touches a limit price is usually too optimistic.

The distinction is worth making explicit:

InstructionCan execute immediately?Can rest in the book?Price guaranteed?Full fill guaranteed?
Market buy or sellUsuallyNoNoUsually high probability, not absolute
Marketable limitYes, up to limitYes, for any remainder if permittedYesNo
Passive limitUsually noYesYesNo

For an algorithm, a limit order is not merely a mechanism for “buying lower” or “selling higher.” It is an execution decision: accept non-fill risk in exchange for price control and, potentially, liquidity-providing economics.


Stops: a trigger first, then a new order

A stop order is conditional. Before its trigger price is reached, it is dormant. Once triggered, it becomes an active order.

In the standard convention:

  • A sell stop is placed below the current market. It is often used to exit a long position if the market falls.
  • A buy stop is placed above the current market. It is often used to cover a short position or enter a long position only after an upward move.

Suppose you own a stock currently quoted near 50.00 and enter a sell stop at 49.50. If the relevant trigger condition occurs at or below 49.50, the stop is activated. A regular sell stop then becomes a market sell order.

The crucial implication is:

A stop price is a trigger price, not a guaranteed fill price.

If bad news causes the market to gap down, the stop can trigger at 49.50 but execute substantially lower because the activated market order sells into whatever bids remain. If many other sell stops trigger around the same level, they may collectively increase selling pressure and worsen available prices.

A stop order can be useful for systematic risk control, but it does not guarantee that a loss is capped at the chosen threshold. The guarantee is procedural: the system will attempt to exit once the trigger condition is met.

Stop-limit orders: price protection after activation

A stop-limit order has two prices:

  1. The stop price determines when the order becomes active.
  2. The limit price determines the worst permitted execution price afterward.

For example, a sell stop-limit with stop price 49.50 and limit price 49.20 becomes an active sell limit once triggered. It may execute at 49.20 or above, but not below 49.20.

This trades one risk for another:

Order after triggerMain benefitMain risk
Stop marketStronger chance of exitFill can be far worse than stop price
Stop limitMinimum acceptable sale priceIt may not exit at all during a fast decline

A stop-limit can therefore be dangerous if its purpose is emergency liquidation. It protects a price boundary but can leave the strategy holding exposure precisely while the market is moving rapidly against it.

One further operational detail matters: stop orders are often managed by a broker or venue rather than displayed as ordinary resting orders in the visible limit order book. Trigger rules vary. A broker might use the last traded price, a bid or ask quote, or another defined reference. Your execution system must know the broker’s exact trigger rule; a backtest must not assume a universal one.


Time in force: the life of the instruction

Order type answers how the algorithm is willing to trade. Time in force answers how long it is willing to wait and whether partial execution is acceptable.

The Interactive Brokers Trader Workstation order-entry panel displays a Time in Force menu, including DAY, GTC, IOC, and GTD. These settings alter the lifetime and cancellation behavior of an otherwise identical order.

The principal instructions are:

ConstraintMeaningPractical algorithmic interpretation
DayOrder expires at the end of that trading day if unfilledAccept passive fill risk during the session, but do not carry the order overnight
GTCGood-Til-Cancelled; remains active until filled, cancelled, or broker expiryMaintain a standing instruction, but monitor it as market conditions and strategy intent change
IOCImmediate-Or-Cancel; fill what can execute now, cancel the restSeek immediate liquidity but do not leave residual quantity exposed
FOKFill-Or-Kill; fill the entire quantity immediately or cancel all of itTrade only if the full intended size is presently obtainable under the price constraint
AONAll-Or-None; require a complete fill, but the order can remain activeAvoid partial positions while accepting delay; availability and implementation vary by venue

A concrete comparison

Use the earlier ask book, where 200 shares are offered at 100.00 and 500 at 100.01. Consider a buy limit for 600 shares at 100.00.

  • Day: buy 200 shares immediately at 100.00. The remaining 400 may rest at 100.00 until the end of the trading day.
  • GTC: buy 200 immediately. The remaining 400 may remain active beyond today, subject to the broker’s GTC policy.
  • IOC: buy 200 immediately, then cancel the remaining 400.
  • FOK: cancel the entire 600-share order, because all 600 cannot execute immediately at 100.00 or better.
  • AON: do not accept the initial 200-share partial fill. The full 600 must become available at an acceptable price before execution can occur.

A highly common execution instruction is a marketable limit IOC. For example, a buy limit IOC at 100.01 for 600 shares says:

  • execute immediately at 100.01 or lower;
  • accept partial execution if only part is available;
  • cancel any residual rather than allowing it to rest.

That instruction is often more controllable than a bare market order. It expresses urgency, while preventing the order from continuing into unexpectedly worse prices or remaining as an unintended passive bid.

By contrast, a passive limit commonly uses Day or GTC because its purpose is to wait for a desired trade. A GTC stop may be used for longer-lived protection, but it must be actively maintained: corporate actions, contract rolls, changing volatility, revised position sizes, and a strategy shutdown can make an old standing order hazardous.

A market order paired with GTC is generally not meaningful in the ordinary order-book sense. A market order has no price at which it can rest, so it executes against current liquidity or is cancelled. Always confirm the broker’s supported combinations rather than assuming every menu choice is valid for every instrument and order type.


Predicting the outcome from the book

When reasoning about an order, use this sequence:

  1. Identify the side. A buy interacts with asks; a sell interacts with bids.
  2. Classify the active order. Is it a market order, an immediately executable limit, or a passive limit?
  3. Apply the price boundary. For a buy, only offers at or below the limit qualify. For a sell, only bids at or above the limit qualify.
  4. Compare order size with qualifying depth. This determines whether the fill is full, partial, or impossible at the stated price.
  5. Apply the time-in-force rule. Decide whether the residual rests, is cancelled, or invalidates the whole attempted trade.
  6. For a stop, handle triggering separately. First decide whether the trigger occurred under the broker’s rule; only then evaluate the resulting market or limit order.

This is close to the logic an event-driven trading simulator must implement. A simulator that treats a limit order as a guaranteed fill once a candle’s high or low crosses the limit ignores queue position, competing orders, the distinction between trades and quotes, and the possibility that the market moved through the level too quickly to fill the strategy.

At the daily-frequency research stage, you may model these details coarsely. At intraday frequency, order type and time in force become part of the strategy itself. A signal that works only if every passive limit fills is not merely a signal; it is an untested claim about execution quality.


Key takeaways

  • A market order seeks immediate execution against available liquidity, but does not guarantee an execution price.
  • A limit order guarantees a worst acceptable price, but not a full fill or any fill. It can be passive or immediately executable.
  • A marketable limit order combines urgency with a price ceiling for buys or floor for sells; any unfilled quantity may rest or cancel depending on time in force.
  • A stop order has two stages: a trigger event followed by an active market order. Its stop price is not its guaranteed execution price.
  • A stop-limit adds price protection after triggering, but may fail to exit in a fast market.
  • Day and GTC govern how long an order can wait. IOC, FOK, and AON control the treatment of partial fills and immediacy.
  • For every order, assess side, active order type, qualifying book depth, and time-in-force rule. For stops, assess the trigger separately before assessing the fill.

Next, we will trace an algorithmic order through its full lifecycle: from signal generation and risk checks to broker submission, fills, clearing, settlement, and accounting.

Can't find a good explanation? Sign up and we'll make it for you

Sign up