Project 10: Paper Trading Bot
Build a paper trading bot that places simulated orders and tracks P&L.
Project Overview
| Attribute | Value |
|---|---|
| Difficulty | Level 3: Advanced |
| Time Estimate | 2-3 weeks |
| Main Language | Python |
| Alternative Languages | JavaScript, Go |
| Knowledge Area | Execution and monitoring |
| Tools | Broker API (paper) |
| Main Book | “Algorithmic Trading” by Ernest Chan |
What you’ll build: A bot that connects to a paper trading API, submits orders, and logs fills and P&L.
Why it teaches quant: It closes the loop between signals and execution without real money risk.
Core challenges you’ll face:
- Managing API authentication and rate limits
- Handling order statuses and partial fills
- Tracking positions and cash accurately
Real World Outcome
You will run the bot on a demo account and see live order logs and position updates.
Example Output:
$ python bot.py --strategy sma
Orders submitted: 5
Open positions: 2
Unrealized P&L: +1.4%
Verification steps:
- Confirm orders match strategy signals
- Verify P&L matches broker calculations
The Core Question You’re Answering
“How do I connect strategy logic to real-world execution safely?”
Paper trading is the bridge from backtest to reality.
Concepts You Must Understand First
Stop and research these before coding:
- Order lifecycle
- What states can an order go through?
- Book Reference: “Trading and Exchanges” by Larry Harris, Ch. 6
- Position accounting
- How do you track realized vs unrealized P&L?
- Book Reference: “Algorithmic Trading” by Ernest Chan, Ch. 5
- Risk controls
- Why do you need max position size and stop limits?
- Book Reference: “Quantitative Trading” by Ernest Chan, Ch. 8
Questions to Guide Your Design
- Execution model
- Will you use market orders or limit orders?
- How will you handle partial fills?
- Monitoring
- How will you log trades and errors?
- Will you build alerts for failures?
Thinking Exercise
P&L Check
If you buy 100 shares at 50 and the price moves to 52, what is unrealized P&L?
Questions while working:
- How does position size scale risk?
- What happens after you sell?
The Interview Questions They’ll Ask
Prepare to answer these:
- “What is the difference between paper trading and backtesting?”
- “How do you track P&L accurately?”
- “What is an order lifecycle?”
- “Why do you need risk limits?”
- “How do you handle API failures?”
Hints in Layers
Hint 1: Starting Point Start with manual order placement before automation.
Hint 2: Next Level Add a simple strategy loop with logging.
Hint 3: Technical Details Persist order and fill data to avoid losing state.
Hint 4: Tools/Debugging Simulate network failures to test resilience.
Books That Will Help
| Topic | Book | Chapter |
|---|---|---|
| Order lifecycle | “Trading and Exchanges” by Larry Harris | Ch. 6 |
| P&L tracking | “Algorithmic Trading” by Ernest Chan | Ch. 5 |
| Risk controls | “Quantitative Trading” by Ernest Chan | Ch. 8 |
Implementation Hints
- Store positions and cash in a persistent store.
- Keep a clear separation between strategy and execution layers.
- Add sanity checks for account balances.
Learning Milestones
- First milestone: You can place and track paper orders.
- Second milestone: You can compute accurate P&L.
- Final milestone: You can run a strategy end-to-end safely.