Module 02 · Python Bot Architecture — Ek Professional Bot Ka Skeleton

Project Structure — Folders Aur Files Ka Blueprint

25 minfocused lesson0copyable prompts5completion checks3source links
Open lesson + course map

On this lesson

Course outline

A professional research bot is easier to audit when each folder has one responsibility. Network retrieval, normalization, research features, paper fills, storage, reporting, and tests must not blur together. The strongest safety control is structural: the repository contains no module capable of authenticating to a venue or transmitting an order.

Use this blueprint:

// prompt — copy me14 lines
paper_bot/
  pyproject.toml
  README.md
  SAFETY.md
  config/default.yaml
  data/raw/  data/normalized/  data/fixtures/
  src/paperbot/config.py
  src/paperbot/data/fetch.py
  src/paperbot/data/normalize.py
  src/paperbot/research/features.py
  src/paperbot/paper/fills.py
  src/paperbot/storage/events.py
  src/paperbot/reporting/dashboard.py
  tests/unit/  tests/integration/  tests/fixtures/

Dependencies should point inward. Reporting may read stored events; storage must not import reporting. Paper fills may consume validated research records; the data adapter must know nothing about fills. This prevents a “convenient” function from quietly reaching across boundaries.

Define narrow typed objects at layer edges. RawSnapshot carries bytes, capture time, host, status, and hash. NormalizedMarket carries validated fields plus provenance. PaperDecision carries hypothesis version, evidence IDs, abstention reason, and synthetic point limit. No object contains a token, private key, account balance, or destination address.

Keep configuration separate from code, but do not make every behavior configurable. Safety invariants are constants: EXECUTION_MODE = "PAPER_ONLY", permitted schemes are HTTPS, and permitted operations are GET. A YAML edit must never activate a live path. If a requested setting conflicts with an invariant, startup exits with a clear error.

Definition of done per layer

Each package needs a public interface, input validation, structured errors, unit tests, and a short README. Tests should run on fixtures with the network disabled. Integration tests may start a local fake server to exercise timeouts and malformed responses. The main command composes layers; it does not implement their details.

// pakistan_angle

Pakistan Angle

Many learners work on shared family machines or budget laptops. A plain Python package, SQLite file, and static report keep the architecture portable. Store only public records and fictional paper events. Do not put CNICs, phone numbers, personal messages, or client data in fixtures, screenshots, or Git history.

// hands_on

Hands-On Exercise

Create the skeleton and an import-boundary test. Add placeholder protocols for MarketDataReader, PaperFillEngine, and EventStore. Run a repository search for private_key, seed, wallet, place_order, and cancel_order; the result must be empty except the safety test that lists forbidden terms.

// completion_rubric

Completion Rubric

5 checks — tick as you verify

0/5

// sources

Sources