Book · adamcoding.com
The Machine and the Market
Learning to Program in Go, One Trade at a Time
How to read this book
Every chapter follows the same rhythm:
- A problem from the market. Something you'd actually want a computer to do.
- The idea. Explained in plain language, no assumed background.
- The mechanism. What's actually happening underneath - the part most books skip.
- Build it. Working code you type out yourself.
- Exercises. Four or five, getting harder. Solutions at the end of each chapter.
Type the code. Don't copy-paste it. You will make typos, the compiler will complain, and you will learn more from three minutes of confusion than from thirty seconds of working code you didn't write. This is the whole method. It's slower and it works.
You need Go installed (go.dev/dl) and a text editor. That's it. No frameworks, no libraries, nothing to configure. That's part of why we're using Go.
Book Architecture
Part I - The Machine and the Language (written in full below)
- Hello, Price
- Numbers That Lie
- Making Decisions
- Doing It Again
- Naming Things
- When It Goes Wrong
Part II - Structures That Hold Data
- Lists in a Row - slices, capacity, why
appendis usually free - The Sliding Window - ring buffers, and turning O(n²) into O(n)
- Lookup by Name - maps, hashing, and building your own hash table
- Shapes of Your Own - structs and methods
- Pointers, Gently - copies, references, and why
*Tradediffers fromTrade - Sorting and Searching - binary search on a million timestamps
- The Order Book - heaps, priority queues, and the data structure the market runs on
Part III - Organising a Program
- Interfaces - the
Strategycontract, and Go's unusual take on them - Packages - splitting a program up without losing track of it
- Reading the World - files, CSV, JSON, and parsing real market data
- Testing - table-driven tests, and testing things that involve money
- Time - timestamps, timezones, and the bugs that eat intraday strategies
Part IV - Doing More Than One Thing
- Goroutines and Channels - concurrency as conversation
- Fan-Out - running a thousand backtests at once
- Races - how concurrent programs lie to you, and the race detector
Part V - The Capstone
- Building the Backtester - assembling everything
- Making It Honest - costs, slippage, and a handover to Trading Systems for Software Engineers
Contents
- ·Preface & Dedication
- Part IThe Machine and the Language
- 01Hello, Price
- 02Numbers That Lie
- 03Making Decisions
- 04Doing It Again
- 05Naming Things
- 06When It Goes Wrong
- ·Getting Real Data, and Two Tools
- Part IIStructures That Hold Data
- 07Lists in a Row
- 08The Sliding Window
- 09Lookup by Name
- 10Shapes of Your Own
- 11Pointers, Gently
- 12Sorting and Searching
- 13The Order Book
- Part IIIOrganising a Program
- 14Interfaces
- 15Packages
- 16Reading the World
- 17Testing
- 18Time
- Part IVDoing More Than One Thing
- 19Goroutines and Channels
- 20Fan-Out
- 21Races
- Part VThe Capstone
- 22Building the Backtester
- 23Making It Honest