The API Surface
Before strategy, mechanics. This chapter is the reference material - the equivalent of reading the API docs before writing against a service. Skimming it is how people lose money to things that had nothing to do with their strategy.
Instruments: what you're actually holding
Spot equities. You own a piece of a company. Settlement is typically T+1 or T+2. Dividends and corporate actions affect your position and - critically - affect your historical data (Chapter 6). In some jurisdictions there's a transaction tax; Irish stamp duty on equity purchases is 1%, which is enormous for anything short-term. Know your local rules before you model costs.
Futures. A standardised contract to transact at a future date. Leveraged by construction via margin. Each contract has a specification you must read: tick size, tick value, contract size, expiry, roll conventions. Continuous futures charts are constructed by stitching contracts together, and different stitching methods produce different histories - your backtest depends on a choice your data vendor made.
CFDs. A bet with your broker on a price difference. You own nothing. Your counterparty is the broker, whose interests are not aligned with yours. High leverage, financing charges on held positions, and the loss statistics from Chapter 1 come predominantly from here. Treat with substantial caution.
Options. Non-linear payoff, multi-dimensional risk (direction, volatility, time, rates). Genuinely interesting for engineers because the maths is tractable and the modelling is fun. Also a place where you can construct positions whose risk you do not understand until they express themselves. Not a beginner instrument, regardless of how approachable the pricing model looks.
Crypto spot. You own the asset. Fragmented liquidity across venues, 24/7 operation, custody risk, and venue risk that has repeatedly materialised.
Crypto perpetuals. Futures without expiry, anchored to spot by a funding rate paid periodically between longs and shorts. Funding is a real and often dominant cost or income stream - a strategy holding perps for days has a P&L component that has nothing to do with price direction. Model it explicitly or your backtest is fiction.
Orders as a state machine
You'll recognise this. The types:
| Type | Semantics | Guarantee |
|---|---|---|
| Market | Execute now at whatever's available | Fills; price unknown |
| Limit | Execute at this price or better | Price known; may not fill |
| Stop (stop-market) | Becomes a market order when price is touched | Fills; price unknown, often bad |
| Stop-limit | Becomes a limit order when touched | Price known; may not fill at all |
That last row is where people get hurt. A stop-limit protects you from slippage by not filling - which means in a fast move against you, your protective stop simply doesn't execute and your position keeps losing. A stop-market fills, at a possibly terrible price. Choose deliberately; the failure modes are different and both are real.
Time in force - GTC (rests until cancelled), IOC (fill what you can now, cancel the rest), FOK (all or nothing, immediately), DAY (expires at session close).
Flags - post-only (reject if it would take liquidity, to guarantee maker fees), reduce-only (can only shrink an existing position - useful as a safety property).
The lifecycle:
SUBMITTED ──► ACCEPTED ──► PARTIALLY_FILLED ──► FILLED
│ │ │
▼ ▼ ▼
REJECTED CANCELLED CANCELLED (remainder)If you trade manually, this is background detail. If you automate, this state machine is your entire correctness problem, and it has all the properties you'd expect of a distributed system with an unreliable network:
- Every order needs a client-generated idempotency key. Networks partition. Retrying without one is how you accidentally open a double position.
- Acknowledgement is not execution. A 200 response means the exchange received your order, not that it filled.
- You must reconcile. Your view of your position is a cache. Reconcile it against the exchange's authoritative view on startup and periodically thereafter, and treat any divergence as a stop-trading condition rather than something to auto-correct.
- Design for restart mid-position. Your process will die while holding a position. That must not be a novel situation for your code.
Chapter 17 covers this properly. It's mentioned here because it's the part of trading that is genuinely your home turf, and where careful engineering pays direct dividends.
Costs, comprehensively
Every cost, on every trade. Most people model the first one and are surprised by their live results.
- Commission - explicit, known, easy.
- Spread - paid on entry and exit. Half a spread each way, effectively. On tight instruments, negligible; on wide ones, it can exceed your entire edge.
- Slippage - the gap between the price that triggered your order and your fill. Worst on stop-market orders in fast markets, which is precisely when your stops trigger. Systematically underestimated.
- Financing / funding - overnight rates on leveraged positions, funding on perps, borrow cost on shorts. Scales with holding time.
- Taxes - transaction taxes on entry, capital gains on profit, and jurisdiction-specific rules about how gains are computed and offset. Materially affects strategy selection: a strategy that's marginally profitable pre-tax can be firmly negative post-tax.
A discipline worth adopting: calculate your cost per round trip as a percentage, then compare it to your average winning trade. If costs are 20% of your average win, you need a substantially better edge than the raw signal suggests. If they're 50%, you're running a business that mostly serves your broker.
Leverage and liquidation
Leverage does not increase your edge. It multiplies your outcomes, both signs, and it introduces a failure mode that unleveraged trading doesn't have: the position can be closed for you.
If you're 10× leveraged, roughly a 10% adverse move wipes your margin and triggers liquidation - typically at a worse price than the theoretical level, often with a fee. And the mechanism is reflexive: cascading liquidations create the very moves that cause more liquidations, which is why crypto produces sudden violent wicks that stop out everyone leveraged and then reverse.
The engineering framing: leverage converts a drawdown into an outage. An unleveraged position that goes 40% against you is unpleasant and recoverable. A 10× position that goes 10% against you is gone, and being right afterwards doesn't help you. Survival is a precondition for edge, not a trade-off against it.