{adamcoding}
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:

  1. A problem from the market. Something you'd actually want a computer to do.
  2. The idea. Explained in plain language, no assumed background.
  3. The mechanism. What's actually happening underneath - the part most books skip.
  4. Build it. Working code you type out yourself.
  5. 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)

  1. Hello, Price
  2. Numbers That Lie
  3. Making Decisions
  4. Doing It Again
  5. Naming Things
  6. When It Goes Wrong

Part II - Structures That Hold Data

  1. Lists in a Row - slices, capacity, why append is usually free
  2. The Sliding Window - ring buffers, and turning O(n²) into O(n)
  3. Lookup by Name - maps, hashing, and building your own hash table
  4. Shapes of Your Own - structs and methods
  5. Pointers, Gently - copies, references, and why *Trade differs from Trade
  6. Sorting and Searching - binary search on a million timestamps
  7. The Order Book - heaps, priority queues, and the data structure the market runs on

Part III - Organising a Program

  1. Interfaces - the Strategy contract, and Go's unusual take on them
  2. Packages - splitting a program up without losing track of it
  3. Reading the World - files, CSV, JSON, and parsing real market data
  4. Testing - table-driven tests, and testing things that involve money
  5. Time - timestamps, timezones, and the bugs that eat intraday strategies

Part IV - Doing More Than One Thing

  1. Goroutines and Channels - concurrency as conversation
  2. Fan-Out - running a thousand backtests at once
  3. Races - how concurrent programs lie to you, and the race detector

Part V - The Capstone

  1. Building the Backtester - assembling everything
  2. Making It Honest - costs, slippage, and a handover to Trading Systems for Software Engineers
Contents
  1. ·Preface & Dedication
  2. Part I
    The Machine and the Language
  3. 01Hello, Price
  4. 02Numbers That Lie
  5. 03Making Decisions
  6. 04Doing It Again
  7. 05Naming Things
  8. 06When It Goes Wrong
  9. ·Getting Real Data, and Two Tools
  10. Part II
    Structures That Hold Data
  11. 07Lists in a Row
  12. 08The Sliding Window
  13. 09Lookup by Name
  14. 10Shapes of Your Own
  15. 11Pointers, Gently
  16. 12Sorting and Searching
  17. 13The Order Book
  18. Part III
    Organising a Program
  19. 14Interfaces
  20. 15Packages
  21. 16Reading the World
  22. 17Testing
  23. 18Time
  24. Part IV
    Doing More Than One Thing
  25. 19Goroutines and Channels
  26. 20Fan-Out
  27. 21Races
  28. Part V
    The Capstone
  29. 22Building the Backtester
  30. 23Making It Honest