Sprint 2 (accounting + observability parity, PINK scope):
- Verified pink_clickhouse.py writes the 8 BLUE-legacy row families at
matching schema and that capital authority in pink_direct.step() is
solely kernel.account (no balance-poll overwrite in the hot loop).
- Report: prod/clean_arch/dita_v2/SPRINT2_ACCOUNTING_PARITY.md.
Sprint 3 offline groundwork (no exchange contact):
- Add _write_trade_exit_leg to pink_clickhouse.py: one BLUE-schema-faithful
trade_exit_legs row per exit leg, with isolated (non-cumulative) per-leg
deltas tracked via _leg_state (reset on ENTER). Closes the docstring gap.
- New offline suite test_pink_multi_exit_groundwork.py (3 passed):
* Flaw 4 — two-leg exit closes once, realized accrues per leg, closed
slot rejects further EXIT (no double-close).
* Overshoot invariant — a final EXIT requesting more than the remaining
size CLAMPS (size to 0, no oversell), retiring the Sprint 0 cumulative-
ratio risk empirically.
* trade_exit_legs delta + full BLUE column-set assertions.
- Persistence regression after edits: 10 passed.
BLUE untouched: no changes to dolphin.* / DOLPHIN_*_BLUE / nautilus_event_trader.py.
Live VST multi-leg run remains deferred pending explicit authorization.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
21 KiB
PINK Re-Architecture Specification (Implementation Blueprint)
Status: Approved-for-coding spec (no code in this document)
Date: 2026-05-19
Owner: Runtime/Infra
Target: Add isolated PINK testnet execution system with identical trading algorithm behavior to BLUE, while keeping BLUE undisturbed.
1. Executive Decision
1.1 Decision
Build PINK as an isolated sidecar system with dedicated namespaces and control surfaces, then optionally migrate that sidecar’s infra onto Podman+Quadlet+systemd.
1.2 Why this decision
- BLUE must remain undisturbed.
- Current codebase hard-routes many
prod*paths into PRODGREEN sinks; a naive clone collides. - BingX account journaling currently dominates data volume and must be controlled explicitly.
1.3 Non-negotiable invariant
The trading algorithm logic must remain identical to BLUE (signal math, thresholds, decision state machine semantics).
2. Hard Constraints (Must Hold)
- No behavior change in core trading logic vs BLUE.
- No write contamination across BLUE/GREEN/PINK CH databases.
- No write contamination across BLUE/GREEN/PINK Hazelcast maps.
- BLUE process manager and lifecycle remain unchanged during PINK buildout.
- PINK must run BingX in VST/testnet mode only until explicit go-live gate.
- Any infra re-architecture must be introduced to PINK first, never by replacing BLUE in-place.
3. Current-State Evidence (Reference Anchors)
3.1 Supervisord-first doctrine
prod/docs/SYSTEM_BIBLE_v7.mdstates all dolphin services are supervisord-managed and warns against dual-management races.- See:
/mnt/dolphinng5_predict/prod/docs/SYSTEM_BIBLE_v7.md:11/mnt/dolphinng5_predict/prod/docs/SYSTEM_BIBLE_v7.md:1339/mnt/dolphinng5_predict/prod/docs/SYSTEM_BIBLE_v7.md:3377
3.2 Namespace split already in doctrine
- BLUE:
dolphin,DOLPHIN_STATE_BLUE,DOLPHIN_PNL_BLUE - PRODGREEN:
dolphin_prodgreen,DOLPHIN_STATE_PRODGREEN,DOLPHIN_PNL_PRODGREEN - See:
/mnt/dolphinng5_predict/prod/docs/SYSTEM_BIBLE_v7.md:11/mnt/dolphinng5_predict/prod/docs/SYSTEM_BIBLE_v7.md:14
3.3 Hardcoded routing that collides with new strategy names
- BLUE trader hardcoded map keys:
/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1740/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1741/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1850/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:2806
DolphinActorroutesstrategy.startswith("prod")to PRODGREEN sink:/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:179/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:180
- BingX execution hardcodes PRODGREEN strategy/db:
/mnt/dolphinng5_predict/prod/bingx/execution.py:263/mnt/dolphinng5_predict/prod/bingx/execution.py:532
- BingX journal maps
prod*->dolphin_prodgreen:/mnt/dolphinng5_predict/prod/bingx/journal.py:90/mnt/dolphinng5_predict/prod/bingx/journal.py:91
3.4 Current BingX poll cadence (main source of account-event volume)
- Poll loops:
- open orders loop
- positions loop
- account loop
- See:
/mnt/dolphinng5_predict/prod/bingx/execution.py:707/mnt/dolphinng5_predict/prod/bingx/execution.py:723/mnt/dolphinng5_predict/prod/bingx/execution.py:732/mnt/dolphinng5_predict/prod/bingx/execution.py:741
- Default intervals:
/mnt/dolphinng5_predict/prod/bingx/config.py:58/mnt/dolphinng5_predict/prod/bingx/config.py:59/mnt/dolphinng5_predict/prod/bingx/config.py:60
3.5 Data volumes measured (14 complete days; 2026-05-05 to 2026-05-18)
- BLUE-like CH outgoing payload estimate: ~4.17 MB/day avg, ~12.01 MB/day p95-day.
- BLUE-like HZ outgoing payload estimate: ~100.03 MB/day avg, ~301.53 MB/day p95-day.
- PRODGREEN-style BingX
account_eventsstream estimate: ~7.41 GB/day avg, ~18.57 GB/day p95-day.
4. Scope
4.1 In scope
- Introduce first-class
PINKnamespace contract across CH/HZ/control-plane. - Preserve algorithm semantics exactly.
- Isolate PINK execution in BingX VST.
- Add explicit friction/cost characterization outputs.
- Add infra spec for Podman+Quadlet+systemd deployment of PINK stack.
4.2 Out of scope
- Any change to signal formula/thresholds/risk decision logic.
- Any BLUE teardown or manager migration in this phase.
- Any LIVE mainnet enablement for PINK.
5. Naming and Namespace Contract
5.1 Strategy naming
- Strategy name for new instance:
pink(lowercase). - Disallowed for this phase: names with
prodprefix (e.g.,prodpink) because current routing treatsprod*specially.
5.2 ClickHouse namespace
- New DB:
dolphin_pink. - Required tables (minimum):
trade_eventstrade_reconstructiontrade_exit_legsv7_decision_eventsadaptive_exit_shadowaccount_eventsstatus_snapshots
- Optional parity tables if needed by downstream tooling:
sc_threshold_advisor_shadowsc_bucket_gauge_shadowinverse_ars_bounce_shadow
5.3 Hazelcast namespace
- Maps:
DOLPHIN_STATE_PINKDOLPHIN_PNL_PINK
- Control-plane runtime command queue key:
pink_runtime_commands
- Capital mirror key:
pink_capital_update_latest
5.4 Trader identity
- Trader ID default:
DOLPHIN-PINK-001
6. Required File-Level Changes (Coding Agent Worklist)
Important: This section is prescriptive. Implement all items unless explicitly marked optional.
6.1 Sink/routing abstraction
6.1.1 prod/ch_writer.py
Current state exposes only _writer, _writer_green, _writer_prodgreen and corresponding functions.
- Source anchor:
/mnt/dolphinng5_predict/prod/ch_writer.py:302
Required:
- Add
_writer_pink = _CHWriter(db="dolphin_pink"). - Add
ch_put_pink(table: str, row: dict) -> None. - Do not modify behavior of existing sink functions.
Acceptance:
- Unit test asserts writes called via
ch_put_pinktargetdolphin_pinkonly.
6.1.2 prod/bingx/journal.py
Current _db_for_strategy routes prod* to dolphin_prodgreen.
- Anchor:
/mnt/dolphinng5_predict/prod/bingx/journal.py:88
Required:
- Replace ad-hoc prefix routing with explicit strategy->db map.
- Add explicit
pink -> dolphin_pinkmapping. - Keep existing
blue,green,prodgreencompatibility. - Update sink selection to include
ch_put_pink.
Acceptance:
- For
strategy='pink', both journal snapshot writes and lookup reads use onlydolphin_pink.
6.1.3 prod/bingx/execution.py
Current code hardcodes:
self._journal_strategy = "prodgreen"- account-events insert URL database
dolphin_prodgreen - Anchors:
/mnt/dolphinng5_predict/prod/bingx/execution.py:263/mnt/dolphinng5_predict/prod/bingx/execution.py:532
Required:
- Add config-driven
journal_strategyandjournal_dbfields. - Default for existing prodgreen path remains unchanged.
- PINK launcher passes
journal_strategy='pink',journal_db='dolphin_pink'. - Remove any remaining hardcoded
dolphin_prodgreenin account-event path.
Acceptance:
- No writes from PINK execution appear in
dolphin_prodgreen.account_events.
6.2 Actor and launcher namespace configurability
6.2.1 prod/launch_dolphin_live.py
Current defaults are prodgreen-centric:
- state/pnl maps and strategy name.
- Anchors:
/mnt/dolphinng5_predict/prod/launch_dolphin_live.py:78/mnt/dolphinng5_predict/prod/launch_dolphin_live.py:79/mnt/dolphinng5_predict/prod/launch_dolphin_live.py:132
Required:
- Introduce generic env-driven namespace fields:
DOLPHIN_STRATEGY_NAMEDOLPHIN_STATE_MAPDOLPHIN_PNL_MAPDOLPHIN_ADAPTIVE_EXIT_DBDOLPHIN_V7_JOURNAL_DB
- Keep prodgreen defaults backward-compatible.
- Add dedicated PINK launcher module or mode wrapper with PINK defaults.
Acceptance:
- Running PINK launcher without overrides lands in PINK namespaces only.
6.2.2 nautilus_dolphin/nautilus/.../dolphin_actor.py
Current default + routing:
strategy_name='prodgreen'startswith("prod")sink logic- state/pnl defaults map to PRODGREEN
- Anchors:
/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:179/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:180/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:181/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:185/mnt/dolphinng5_predict/nautilus_dolphin/nautilus_dolphin/nautilus/dolphin_actor.py:189
Required:
- Replace prefix-based sink selection with explicit strategy mapping.
- Add first-class
pinkmapping for CH sink + default shadow db. - Keep old strategy names functional.
- Ensure aliases do not include BLUE keys in PINK mode.
Acceptance:
- Actor in
pinkmode never writes toDOLPHIN_STATE_PRODGREEN,DOLPHIN_PNL_PRODGREEN, ordolphin_prodgreen.
6.3 Control-plane keys and capital surfaces
6.3.1 prod/nautilus_event_trader.py (if PINK reuses this path)
Current BLUE hardcoding includes:
DOLPHIN_STATE_BLUE,DOLPHIN_PNL_BLUE,blue_runtime_commands- Anchors:
/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1740/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1741/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:1850/mnt/dolphinng5_predict/prod/nautilus_event_trader.py:2806
Required (only if this file is used for PINK runtime):
- Parameterize map names and runtime queue key.
- Preserve BLUE defaults exactly.
- Add PINK equivalents via env/config.
Acceptance:
SET_CAPITAL/CAPITAL_UPDATEfor PINK only affects PINK state surfaces.
Note: Preferred approach is to keep BLUE runtime on this file untouched and run PINK through launcher/actor path first.
6.4 Ops scripts and tooling
6.4.1 prod/ops/prodgreen_ctl.py
Current script is hardcoded to PRODGREEN namespaces.
- Anchors:
/mnt/dolphinng5_predict/prod/ops/prodgreen_ctl.py:23/mnt/dolphinng5_predict/prod/ops/prodgreen_ctl.py:24/mnt/dolphinng5_predict/prod/ops/prodgreen_ctl.py:42
Required:
- Create
pink_ctl.pyOR generalize into namespace-aware ctl tool. - Required commands: status, healthcheck, start, stop, restart, mode-verify.
- Must not invoke BLUE program names by default.
Acceptance:
pink_ctl statusreports PINK CH/HZ surfaces only.
7. ClickHouse Schema Plan for dolphin_pink
7.1 Strategy
Clone prodgreen schema set as baseline for PINK to preserve execution-profile columns.
Reference DDLs:
/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/00_create_database.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/account_events.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/status_snapshots.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/trade_events.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/v7_decision_events.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/adaptive_exit_shadow.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/02_create_trade_reconstruction.sql/mnt/dolphinng5_predict/prod/clickhouse/prodgreen/03_create_trade_exit_legs.sql
7.2 Required migration artifacts
Create new folder:
prod/clickhouse/pink/
Include:
00_create_database.sql->CREATE DATABASE IF NOT EXISTS dolphin_pink;- Full table DDL scripts mirroring prodgreen table structures.
- Apply script with idempotent checks.
7.3 Guardrails
- No schema mutation to existing
dolphinordolphin_prodgreenin this phase. - No historical retagging/movement required for initial PINK bring-up.
8. Hazelcast Map and Key Contract
8.1 Required map names
DOLPHIN_STATE_PINKDOLPHIN_PNL_PINK
8.2 Required keys in DOLPHIN_STATE_PINK
engine_snapshotcapital_checkpointlatest_nautilus- optional replay/control keys mirrored from blue contract if PINK runtime supports same capital workflows
8.3 Control-plane keys
- Runtime command queue:
pink_runtime_commands - Latest capital update mirror:
pink_capital_update_latest
8.4 Isolation validation rule
A PINK process must never read/write keys under DOLPHIN_STATE_BLUE or DOLPHIN_PNL_BLUE except explicitly allowed read-only analytics queries.
9. BingX VST Behavior Contract
9.1 Environment
DOLPHIN_BINGX_ENV=VSTDOLPHIN_BINGX_ALLOW_MAINNET=0
9.2 Expected data venue / exec venue
- Initial recommended mode:
- data venue: BINANCE (same sensing stream as BLUE)
- exec venue: BINGX VST
9.3 Leverage/sizing mode
- Use existing sizing-mode mechanisms.
- No strategy-logic change permitted.
10. Data Resource Budget and Controls
10.1 Baseline estimates (from measured data)
CH + HZ for BLUE-like write path
- CH: ~4.17 MB/day avg, ~12.01 MB/day p95-day
- HZ: ~100.03 MB/day avg, ~301.53 MB/day p95-day
BingX journal risk stream
account_events: ~7.41 GB/day avg, ~18.57 GB/day p95-day if current high-rate snapshots remain.
10.2 Mandatory control for account_events
Implement at least one, preferably multiple:
- Snapshot delta suppression beyond fingerprint-only (field-level sampling and minimum emission interval).
ACCOUNT_REFRESHwrite interval floor (e.g., min 2s, then tune).- Separate high-granularity debug table optional; production
account_eventsshould be rate-limited. - Configurable hard cap alert on rows/minute.
10.3 Acceptance thresholds
- PINK
account_eventssustained rate must stay below agreed cap (set initial policy: <= 5 rows/sec average over 15 min unless debug mode explicitly enabled). - Alert if exceeds cap for > 3 consecutive windows.
11. Observability and ROI/Friction Outputs
11.1 Required KPI outputs
- Realized ROI (closed trades).
- Open-equity ROI (mark-to-market).
- Cost-adjusted ROI.
- Latency decomposition:
- decision->submit
- submit->ack
- ack->first_fill
- first_fill->done
- Slippage decomposition (bps against decision/arrival references).
- Fee/funding components.
11.2 Storage location
- PINK metrics rows in
dolphin_pink.trade_eventspayload columns and/or dedicated execution quality table.
11.3 TUI policy
Current TUI is BLUE-hardcoded in places (DOLPHIN_STATE_BLUE, dolphin.trade_events, blue_runtime_commands).
- Anchors:
/mnt/dolphinng5_predict/Observability/dolphin_status.py:513/mnt/dolphinng5_predict/Observability/dolphin_status.py:558/mnt/dolphinng5_predict/Observability/dolphin_status.py:1164/mnt/dolphinng5_predict/Observability/dolphin_status.py:212
Required:
- Do not break BLUE TUI.
- Add either:
- separate
dolphin_status_pink.py, or - namespace-parameterized TUI mode.
- separate
12. Podman + Quadlet + systemd Adoption Plan
12.1 Strategy
Apply only to PINK stack first.
12.2 Preflight checks (must pass before coding)
- Podman availability on host (
podman --version). - systemd user/service model chosen (rootless preferred unless operationally blocked).
- Persistent volume paths and permissions validated.
- ClickHouse config/users mounts parity with current docker-compose pattern.
Current host note: Podman not currently installed (which podman returned no result).
12.3 Unit boundaries
- BLUE stays under supervisord + current docker compose infra.
- PINK gets independent unit set.
- Do not dual-manage same runtime process with supervisord and systemd.
12.4 Quadlet file set for PINK
Create under dedicated path (example):
datastack-pink.podhazelcast-pink.container(or reuse cluster only if explicitly designed shared)clickhouse-pink.container(or shared CH with separate DB if accepted)prefect-pink.container(if needed)pink-worker.container
12.5 Shared vs dedicated infra policy
Decision required before implementation:
- Option A (preferred first): shared HZ+CH infra, isolated logical namespaces.
- Option B: dedicated PINK HZ/CH containers.
Given HZ volatility risk and operational complexity, start with Option A unless a strict physical isolation requirement is imposed.
13. Algorithm Identity Assurance (Critical)
13.1 Required parity harness
Implement deterministic parity checks between BLUE decision path and PINK decision path on identical input replay.
13.2 Comparison granularity
At each scan/bar compare tuple hash of:
- signal fired boolean
- selected asset
- side
- leverage intent
- entry/exit action
- reason code
- bars_held progression
No tolerance except for fields explicitly dependent on execution venue acknowledgements.
13.3 Fail criteria
Any divergence in pure strategy decisions is a release blocker.
14. Test Plan (Implementation Exit Criteria)
14.1 Unit tests
- Routing tests for strategy->DB and strategy->HZ map.
- Sink tests (
ch_put_pinkpath). - Control key tests (
pink_runtime_commands). - Account-event rate-limit logic tests.
14.2 Integration tests
- Start PINK in VST and verify:
- CH writes only into
dolphin_pink.* - HZ writes only into
DOLPHIN_STATE_PINK/DOLPHIN_PNL_PINK
- CH writes only into
- Verify no new rows in
dolphin_prodgreen.account_eventsduring PINK-only test run. - Verify BLUE process and metrics unaffected.
14.3 Soak tests
- 24h soak with PINK live in VST.
- Monitor:
- row rates
- CH insert error rates
- HZ heartbeat age
- control-plane responsiveness
14.4 Regression tests
Run existing relevant suites for:
- bingx journaling/accounting
- actor routing
- launch paths
- MHS basic health checks for BLUE unaffectedness
15. Deployment Sequence (Phased)
Phase 0: Namespace groundwork
- Add sink and routing abstractions.
- Add PINK CH schema migration artifacts.
- Add PINK launcher and env contract.
Gate 0:
- Compile/tests pass.
- Static grep verifies no hardcoded fallback from
pinktoprodgreen.
Phase 1: PINK logical bring-up (same infra)
- Start PINK process under current management (or controlled runner) with VST.
- Verify strict namespace isolation.
- Run parity harness with replay feed.
Gate 1:
- No contamination.
- Parity pass.
Phase 2: Data-volume control tuning
- Tune account-event emission controls.
- Verify row-rate caps and KPI completeness.
Gate 2:
- Resource budgets stable.
Phase 3: Optional Podman+Quadlet packaging for PINK
- Build PINK quadlet units.
- Validate independent lifecycle.
- Keep BLUE unchanged.
Gate 3:
- PINK can be fully operated without impacting BLUE.
16. Rollback Plan
16.1 Soft rollback
- Stop PINK process/unit only.
- Leave BLUE untouched.
- Preserve PINK CH/HZ artifacts for postmortem.
16.2 Hard rollback
- Revert routing patches that introduced PINK mapping.
- Keep PINK DB as historical archive or drop only after approval.
16.3 Explicit no-rollback targets
Do not alter BLUE capital/state surfaces during PINK rollback.
17. Security and Safety
- PINK VST keys isolated from BLUE credentials.
- No mainnet enable unless separate approval gate flips
DOLPHIN_BINGX_ALLOW_MAINNET=1. - Validate no accidental propagation of PINK credentials into shared logs.
18. Deliverables Checklist (Coding Agent Must Produce)
- Code changes implementing explicit strategy/namespace routing for PINK.
dolphin_pinkCH schema files inprod/clickhouse/pink/.- PINK launcher/config entrypoint.
- PINK ops control script or generalized namespace-aware ctl tool.
- Unit + integration tests for routing/isolation.
- Parity harness and parity report artifact.
- Data-rate monitor/report for
account_eventsand major tables. - Optional: Quadlet unit files for PINK stack (if Phase 3 in scope).
19. Coding Prohibitions (Strict)
- Do not alter algorithm constants or decision logic behavior.
- Do not remove or repurpose BLUE maps/tables.
- Do not bind PINK to names beginning with
prodin this phase. - Do not change BLUE process manager/runtime flow as part of PINK implementation.
20. Open Decisions Requiring Explicit Operator Choice
- PINK infra physical model:
- shared CH/HZ vs dedicated CH/HZ.
- PINK manager in early phases:
- supervised process first vs direct Quadlet rollout.
- Account-event rate cap values:
- initial thresholds and alert policy.
If decisions are not provided, default choices are:
- shared CH/HZ with strict logical isolation,
- supervised PINK process before Quadlet migration,
- account-events cap <= 5 rows/sec sustained (debug off).
21. Minimal Go/No-Go Matrix
Go only if all true:
- Strategy parity = exact pass.
- Namespace contamination tests = zero leaks.
- Data-rate caps respected during soak.
- BLUE observability and trade loop unchanged.
No-Go if any true:
pinkrows appear indolphin_prodgreenordolphinunexpectedly.- BLUE map/table writes change baseline rates materially.
- Decision parity drifts.
- VST safety flags not enforced.
22. Final Operator Notes
- This spec intentionally separates architecture modernization from algorithm behavior.
- PINK is the safe proving ground for infra re-architecture.
- BLUE remains production reference and must not be structurally disturbed until PINK completes parity + soak + resource gates.