Commit 2ffdc3a
feat(broker): add Alpaca paper order submit sandbox (#311)
Add a backend-only, multi-gated, PAPER-ONLY order submission sandbox. Blocked by
default; it submits a single paper order to Alpaca Paper ONLY when every explicit
gate is satisfied. Not live trading, not frontend UX, not autotrade.
Gates (all required): ALPACA_ENV=paper, ALPACA_PAPER_ORDER_SUBMIT_ENABLED=true,
ALPACA_PAPER_ORDER_SUBMIT_SANDBOX_ACK=I_UNDERSTAND_THIS_SUBMITS_A_PAPER_ORDER,
paper credentials present, request confirm_paper_order=true and
source="manual_sandbox", draft risk validation, and conservative size caps
(qty<=100, notional<=5000; market/limit only). Any failure -> no Alpaca call,
safe blocked response (HTTP 200), safety flags preserved.
- app/schemas/alpaca_paper_order_submit_sandbox.py — request/response
(extra="forbid"); response locks paper_only=true, live_trading=false,
live_orders_blocked=true, dry_run=true, read_only_posture_preserved=true,
execution_enabled=false, requires_human_review=true; only redacted ids.
- app/services/alpaca_paper_order_submit_sandbox_service.py — gated service with
an isolated paper-only client wrapper. Lazy SDK import only after gates;
TradingClient(paper=True) only; single non-retried submit; raw order id
redacted. Legacy live adapter (brokers/alpaca_adapter.py) NOT imported.
Injected fake client supported for tests.
- app/api/routes/alpaca_paper.py — POST /api/alpaca-paper/order-submit-sandbox.
- tests/app/test_alpaca_paper_order_submit_sandbox.py — 36 tests (default
blocked; every gate; validation reuse + caps; gated fake-client submit called
once; redaction/no leak; dry-run-preview; raising client; no network; route
POST-only/405; OpenAPI; allowlists do not exempt live paths).
- tests/app/test_safety_invariants.py & test_paper_sandbox_guardrails.py —
narrow, path-specific allowlist registration with justification (additive).
- docs/tasks/alpaca_paper_order_submit_sandbox_001.md (incl. manual-smoke policy).
No live endpoint, no live credentials, no frontend trading controls, no secrets.
No manual real-paper smoke performed (requires separate explicit approval).
Global safety posture unchanged: autotrade=false, dry_run=true, read_only
preserved, live_orders_blocked=true, max risk <= 1%.
Co-authored-by: Melly <Melly-999@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 60b0a34 commit 2ffdc3a
7 files changed
Lines changed: 1042 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
172 | 182 | | |
173 | 183 | | |
174 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
175 | 224 | | |
176 | 225 | | |
177 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
0 commit comments