Intelligence, Advanced Charting & Trading Platform
docs(paper): detail stage-two local workspace, quote boundary and production exclusions
davoodmehraban89 committed
Oct 14, 2026 at 23:54 UTC
945b1c8b67e6d7f020c02352d59a3e65c16cec8a
1 file changed
+36
docs/trading/paper-trading-stage2.md
new
+36
@@ -0,0 +1,36 @@
1
+# VELYQOR Paper Trading — Stage 2: Multi-position workspace and quote preflight
2
+
3
+**Date:** 2026-10-14. **Review branch:** `feature/paper-trading-risk-controls-2026-10-14` / [PR #27](https://github.com/davoodmehraban89/VELYQOR/pull/27). **NOT deployed; NO live orders.**
4
+
5
+## Product acceptance
6
+
7
+A user can create up to **10 concurrent paper positions** (maximum **50 stored positions**, including closed ones), switch between positions on the selected market symbol, manually enter successive hypothetical prices, view the current fixed/trailing stop and take-profit levels, close a hypothetical position once, and export a CSV of all events. Positions are restored from local browser storage after refresh. The initial MVP risk panel is also documented in [stage 1](./paper-trading-stage1.md).
8
+
9
+- `packages/market-domain/src/paper-position.mjs`: deterministic Long/Short simulation, percent SL/TP and trailing-stop; fees, adverse hypothetical exit slippage and event timeline.
10
+- `packages/market-domain/src/paper-workspace.mjs`: immutable multi-position workspace, maximum active count, replay-checked restore, per-position summaries and CSV export.
11
+- `apps/market-terminal/src/PaperTradingPanel.jsx`: React panel; uses browser `localStorage` key `velyqor.paper-workspace.v1`; no network calls to write money or trades.
12
+- `packages/market-domain/src/paper-quote-guard.mjs`: separately testable **future integration boundary only**, for authenticated/backend-verified bid/ask snapshots. Checks exact source allowlist, explicitly reviewed simulation-display entitlement metadata, GOOD quality, open-market flag, strict order sequences, source and receive UTC times, configurable age, unit, bid/ask spread and correct adverse exit side. There is **no importer, publisher, brokerage connector or live-feed auto-trigger connected**.
13
+
14
+## Security and accuracy constraints
15
+
16
+1. **NO LIVE ORDERS:** no broker key, exchange order API, wallet or settlement. No AI command can cause real trade execution.
17
+2. **MANUAL SCENARIOS:** each paper mark is a user-entered hypothetical price, not a verified executable quote or current market price. A simulated trigger only closes a local paper position.
18
+3. **LOCAL ONLY:** browser storage is not encrypted, tamper-proof, server-side, cross-device, backed up or attached to an authenticated account. Do not store real assets, personal financial account details or API secrets here. If restore validation fails, automatic overwriting is blocked; user explicitly decides whether to reset.
19
+4. **NO MIXED-CURRENCY SUM:** `EUR_USD_ECB` paper quote-unit results are not summed with `GOLD18_IRT` or `XAU_USD` results. Each row reports its own quote-unit P&L, and currency conversion is not inferred.
20
+5. **MARKET DATA INTEGRITY:** ECB daily reference observations are not tradable bid/ask. Gold spot reference point, CoinGecko price points, or source OHLC bars cannot be silently promoted to live executable bid/ask. No quote is connected until source rights, bid/ask meaning, freshness, market/session status, latency, quote unit and real-world licensing are established.
21
+6. **QUOTE-GUARD IS NOT AN ENTITLEMENT AUTHORITY:** supplied strings like `reviewed_simulation_display` cannot prove legal permission or authenticity. A future secure server gateway must authenticate the provider, verify signed policy/permission and ensure clients cannot forge price source or turn simulated orders into real ones.
22
+7. **NO PROMISE OF SL FILL:** SL/TP and trailing stops are based on observed hypothetical prices; a gap can close below/above the threshold. This simulator does not model full limit-order book depth, spread evolution, liquidity, market impact, financing, taxes, leverage, liquidations, partial fills or brokerage execution.
23
+8. **TRANSPARENCY:** show `PAPER ONLY`, `MANUAL SCENARIO`, separate real-data chart source badges and quote quality. The API itself MUST NOT claim the user has real trading capital, actual positions or realized financial returns.
24
+
25
+## Quality gates
26
+
27
+- `node --test packages/market-domain/test/paper-*.test.mjs`
28
+- `node --test packages/market-domain/test/*.test.mjs packages/market-feed/test/*.test.mjs` (full domain/feed suite where available)
29
+- `cd apps/market-terminal && npm ci && npm run build`
30
+- `./.github/workflows/paper-trading-ci.yml` runs simulation tests, network/broker import checks and Vite build; main CI validates generic domain + PostgreSQL invariants.
31
+- Client-local restore tests rebuild all financial fields from manual events; this detects inconsistent data and accidental corruption, **not sophisticated attacker-forged coherent local events**.
32
+- Stage 2 code is stacked onto PR #24. Do not merge or publicly deploy until its underlying PR #23/#24 acceptance and licensing/Neon/WS tests are satisfied; the GitHub `main` stream already contains independent PR #25/#26 safety changes, and must be reconciled in a reviewed integration.
33
+
34
+## Next gate: genuinely updating paper prices
35
+
36
+A future **server-owned simulation worker** can accept only authenticated, explicitly entitled, fresh, sequenced real bid/ask from a vetted provider; validate via the quote guard; maintain durable server-side paper positions with a tamper-resistant event log, idempotent state transitions, gap/outage reconciliation, clock/skew handling, open-market sessions and role-based access. Client controls remain **paper only**. Instrument-specific spread, price precision, stop behavior and session rules must be configured. Actual buying/selling requires a **separate explicit product and security authorization** and is out of scope.