Files
siloqy/prod/clickhouse/violet/03_trade_exit_legs.sql
Codex 99e529c32a VIOLET V1a: dolphin_violet DDL set + statement-wise applier (applied + verified)
14 tables consolidated from the LIVE post-ALTER dolphin_pink schema
(maras_tp + provenance folded into base CREATEs — a fresh DB never replays
ALTER chains) + violet_feed_divergence (scan-vs-venue divergence metric,
session_id + plane seqs + mono_ns). apply_violet_ddl.py posts ONE statement
per HTTP request (multi-statement posts fail — proven on pink 08), is
idempotent (all IF NOT EXISTS, double-apply tested live), and verifies the
expected table set. Applied to live CH: verify all 14 present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 15:40:05 +02:00

46 lines
1.5 KiB
SQL

-- dolphin_violet DDL — consolidated from the LIVE dolphin_pink schema
-- (post-ALTER: includes maras_tp + provenance columns). Generated 2026-06-12.
-- Apply via apply_violet_ddl.py (one statement per HTTP POST).
CREATE TABLE IF NOT EXISTS dolphin_violet.trade_exit_legs
(
`ts` DateTime64(6, 'UTC'),
`ts_day` Date MATERIALIZED toDate(ts),
`date` Date,
`strategy` LowCardinality(String),
`trade_id` String,
`chain_root_trade_id` String DEFAULT '',
`chain_head_leg_id` String DEFAULT '',
`chain_prev_leg_id` String DEFAULT '',
`chain_seq` UInt32 DEFAULT 0,
`chain_token` String DEFAULT '',
`chain_mode` LowCardinality(String) DEFAULT '',
`exit_leg_id` String,
`exit_seq` UInt32,
`command_id` String DEFAULT '',
`source` LowCardinality(String),
`reason` LowCardinality(String),
`asset` LowCardinality(String),
`side` LowCardinality(String),
`entry_price` Float64,
`exit_price` Float64,
`fraction` Float32,
`exit_notional` Float64,
`remaining_notional` Float64,
`remaining_qty` Float64,
`pnl_pct_leg` Float32,
`pnl_leg` Float64,
`pnl_realized_total` Float64,
`bars_held` UInt16,
`fee_leg` Float64 DEFAULT 0,
`fee_source` LowCardinality(String) DEFAULT '',
`is_maker` UInt8 DEFAULT 0,
`slippage_bps` Float32 DEFAULT 0,
`pnl_source` LowCardinality(String) DEFAULT ''
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(ts)
ORDER BY (ts_day, trade_id, exit_seq, ts)
TTL ts_day + toIntervalDay(180)
SETTINGS index_granularity = 8192;