Skip to content

v1.0.0-rc.1: All 10 hardening layers + production safety - #1

Merged
dmuhoro merged 35 commits into
mainfrom
sprint-2-paper-trading
Jul 27, 2026
Merged

v1.0.0-rc.1: All 10 hardening layers + production safety#1
dmuhoro merged 35 commits into
mainfrom
sprint-2-paper-trading

Conversation

@dmuhoro

@dmuhoro dmuhoro commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Merges sprint-2-paper-trading (35 commits ahead) into main for v1.0.0-rc.1 release.

Layers 1-6: Architecture Hardening

  • Port protocols, dependency inversion, no global mutable state
  • Kill switch & circuit breaker in RiskService
  • API authentication middleware
  • Secrets management (env-only, startup validation)
  • Observability persistence to SQLite

Layers 7-9: Trading + Testing

  • Order lifecycle, position management, realized PnL
  • Orchestrator decomposition (CycleExecutor, DaemonController)
  • Alpaca mock tests, API integration tests, CLI tests — 85%+ coverage

Layer 10: Production Hardening

  • Retry with exponential backoff + jitter
  • Data archival (90-day retention)
  • Strategy registry persistence to SQLite
  • Improved config validation

Phases 0-3: Release Polish

  • Replaced 4 production asserts with RuntimeError
  • Unified version to 0.8.0
  • Added MIT LICENSE
  • Comprehensive .env.example
  • Rewrote README, added CONTRIBUTING.md
  • Deleted 200+ lines of dead code
  • Added CI security scanning + Docker push to GHCR

Verification

  • 587 tests passing
  • 88% code coverage (threshold: 70%)
  • Lint: 0 ruff errors
  • Typecheck: 0 pyright errors

dmuhoro added 30 commits June 10, 2026 07:23
WP-001: Makefile & Developer Tooling Setup
WP-003: Linting & Code Quality Enforcement (39 ruff errors fixed)
WP-004: Pyright Type Checking (47 strict-mode errors fixed)
WP-005: Docker Containerization (Dockerfile, compose, .dockerignore)
WP-006: GitHub Actions CI Pipeline (lint/typecheck/test/docker)
WP-007: Database Migration Framework + ADR-005

Full CI pipeline passes: ruff, black, isort, pyright (0 errors), pytest (7/7)
New src/traderos/ layered architecture:
  domain/     — analysis, liquidity, risk, strategies, backtesting, research
  infrastructure/ — config, database, data
  application/    — orchestrator
  interfaces/     — cli, visualization

Dual directory strategy: old flat modules become re-export shims.
All configs updated: Makefile (PYTHONPATH), pyproject.toml (pyright, coverage),
Dockerfile, CI workflow.

Full CI pipeline passes: ruff, black, isort, pyright (0), pytest (7/7).
…y stubs, config v2, error handling, logging, event bus, architecture tests, MarketDataRepository

- WP-009: 17 domain entity dataclasses (Market, Candle, OHLCV, Signal, Strategy, etc.)
- WP-010: Repository[T] ABC + 16 domain repository interfaces
- WP-011: InMemory implementations for all 16 repositories
- WP-013: Config v2 — frozen dataclass with YAML/env loader, backward-compatible .get()
- WP-014: Exception hierarchy (TraderOSError → Domain/Infra/Application/InterfaceError)
- WP-015: StructuredLogger producing JSON logs
- WP-016: EventBus + InMemoryEventBus with frozen Event dataclass
- WP-017: 9 architecture enforcement tests (layer separation, import validation)
- WP-018: MarketDataRepository combining Market + Candle repos
- 163 tests passing, 0 lint errors, 0 typecheck errors, 82% coverage
…a services)

- WP-012: SQLiteRepository base + 16 SQLite repo implementations
- WP-019: DataCollector ABC + CollectorRegistry in domain layer
- WP-020: BinanceCollector (reads from Binance REST API)
- WP-021: YFinanceCollector (stub for later yfinance wrapper)
- WP-022: MockDataCollector (deterministic synthetic OHLCV)
- WP-023: DataNormalizer + DataValidator services
- 280 tests passing, 0 lint, 0 typecheck, 83% coverage
…tation (Sharpe/Sortino/Calmar), BacktestStep tracking, 5 tests
…rAdapter, DeviationAnalysisService, 26 tests
…ill_price fix

Gap 1: Wire market data feed into orchestrator
- DataIngestionService.get_latest_close() resolves close price by market_id
- Factory builds CollectorRegistry + parses settings.yaml symbols
- run_forever() reads prices via data_ingestion instead of hardcoded 100.0

Gap 2: Wire Alpaca broker for LIVE mode
- Factory branches broker selection on TradingMode.LIVE
- Uses AlpacaBrokerAdapter when alpaca_api_key/secret are configured
- Falls back gracefully to PaperBrokerAdapter if alpaca-py absent
- Config gains typed alpaca fields + env var mappings

Gap 3: Fix fill_price multiplier bug
- BrokerAdapter.place_market_order accepts close_price for absolute pricing
- PaperBrokerAdapter returns ref_price * slippage (not just slippage)
- process_candle double-multiply workaround removed
- All call sites updated (orchestrator, tests, Alpaca adapter)

Hardening: Config typed fields, daemon panic recovery in run_forever
- 33 ruff errors fixed: DTZ001/DTZ005 tzinfo=UTC, FURB157 Decimal, E741 rename l, E501 line length, B011 raise AssertionError, RUF059 prefix unused var, F401 unused import, RUF100 unused noqa
- 42 pyright errors fixed: FastAPI optional deps TYPE_CHECKING guard, public ensure_fastapi, running @Property, BaseModel type:ignore, TradeSide enum, total_equity, StrategyBase instantiation, isinstance removal
- 514 tests pass, lint clean, typecheck clean
Batch 1 (Config alignment):
- GAP-14: Config.load() maps settings.yaml nested keys
- GAP-15: Docker MODE=paper env var removed
- GAP-25: PaperBrokerAdapter reads DEFAULT_CASH env var

Batch 2 (API hardening):
- GAP-11: /papertrade/session accepts market_ids body
- GAP-17: CORSMiddleware added
- GAP-27: /metrics returns warning when orchestrator not running

Batch 3 (Stub replacements):
- GAP-7: strategy_lab.py stripped to list-only
- GAP-9: notifications: file persistence + webhook POST
- GAP-21: Alpaca limit order implemented
- GAP-22: EventBus exception isolation

Batch 4 (Infrastructure hardening):
- GAP-16: HEALTHCHECK in Dockerfile
- GAP-20: backtest timeout after max_duration_seconds
- GAP-23: shutdown timeout daemon force-exit

Batch 5 (Remaining):
- GAP-12: all cash reads DEFAULT_CASH env var (verified)
- GAP-19: CLI --json flag for key subcommands

509 tests pass, 78% coverage, 0 lint/typecheck errors
- Add KillSwitch dataclass with circuit breaker (max consecutive failures),
  daily loss limit, and trade-blocking can_trade() method
- Add can_trade() to RiskService that checks kill switch + max position count
- Wire kill switch into orchestrator: check can_trade() before placing orders,
  record_success() on filled trades, record_failure() on unfilled
- Add EventBus backward-compat alias in events.py (isort-safe)
- 509 tests pass, 0 lint/typecheck errors
- Add X-API-Key authentication via FastAPI middleware
- API key read from TRADEROS_API_KEY env var (optional)
- When key is set, all endpoints require X-API-Key header
- When not set, all endpoints remain open (dev mode)
- Middleware applies globally to all routes
- 509 tests pass, 0 lint/typecheck errors
dmuhoro added 5 commits July 27, 2026 23:08
…ersistence, config validation

- retry_with_backoff() with exponential backoff, jitter, max 3 attempts
- purge_old_entries() with 90-day retention on 5 SQLite tables
- v003_strategies migration: strategy_registry table + 3 seed strategies
- Config validation: db_path dir check, MAX_DRAWDOWN 0-100 range, forex_symbols type check
- Factory calls purge_old_entries() on startup after migrations
- Retry wrapped around Alpaca broker submit() and notification webhook
- 585 tests pass, 85.04% coverage, lint/typecheck clean
…CENSE, .env.example

- Replace 4 production asserts with proper RuntimeError checks
- Unify version to 0.8.0 across pyproject.toml, VERSION, CHANGELOG
- Add MIT LICENSE file
- Update .env.example with all documented env vars
- Rewrite README to reflect current architecture, CLI/API usage, config ref
- Add CONTRIBUTING.md with setup, standards, commit convention, architecture rules
- Delete unused CLI modules: dashboard.py, research.py, strategy_lab.py
- Delete unused visualization modules: charts.py, liquidity_charts.py
- Delete empty interfaces/visualization/ package
- Add smoke test for api/main build_app()
- 587 tests pass, 87.83% coverage
- Add security job: pip-audit (dependency vulns) + bandit (SAST)
- Replace raw docker build with build-push-action pushing to ghcr.io
- Tag with commit SHA, branch name, and 'latest' on main branch
- Docker job now depends on security job
@dmuhoro
dmuhoro merged commit c4a60ef into main Jul 27, 2026
2 of 8 checks passed
@dmuhoro
dmuhoro deleted the sprint-2-paper-trading branch July 27, 2026 20:27
@dmuhoro
dmuhoro restored the sprint-2-paper-trading branch July 31, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant