Files
siloqy/prod/clickhouse/violet/08_trade_events.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

70 lines
2.7 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_events
(
`ts` DateTime64(6, 'UTC'),
`trade_id` String DEFAULT '',
`date` Date,
`strategy` LowCardinality(String),
`asset` LowCardinality(String),
`side` LowCardinality(String),
`entry_price` Float64,
`exit_price` Float64 DEFAULT 0,
`quantity` Float64,
`pnl` Float64 DEFAULT 0,
`pnl_pct` Float32 DEFAULT 0,
`exit_reason` LowCardinality(String) DEFAULT '',
`vel_div_entry` Float32,
`boost_at_entry` Float32,
`beta_at_entry` Float32,
`posture` LowCardinality(String),
`leverage` Float32,
`conviction_multiplier` Float32 DEFAULT 0,
`exchange_leverage` UInt8 DEFAULT 0,
`exchange_leverage_mode` LowCardinality(String) DEFAULT '',
`leverage_mapping_rule` LowCardinality(String) DEFAULT '',
`account_capital` Float64 DEFAULT 0,
`portfolio_capital` Float64 DEFAULT 0,
`current_open_notional` Float64 DEFAULT 0,
`remaining_notional_capacity` Float64 DEFAULT 0,
`max_account_leverage` Float32 DEFAULT 0,
`margin_required` Float64 DEFAULT 0,
`ledger_authority` LowCardinality(String) DEFAULT '',
`regime_signal` Int8 DEFAULT 0,
`capital_before` Float64 DEFAULT 0,
`capital_after` Float64 DEFAULT 0,
`peak_capital` Float64 DEFAULT 0,
`drawdown_at_entry` Float32 DEFAULT 0,
`open_positions_count` UInt8 DEFAULT 0,
`scan_uuid` String DEFAULT '',
`bars_held` UInt16 DEFAULT 0,
`entry_payload_json` String DEFAULT '',
`exit_payload_json` String DEFAULT '',
`execution_payload_json` String DEFAULT '',
`friction_payload_json` String DEFAULT '',
`event_payload_json` String DEFAULT '',
`runtime_namespace` LowCardinality(String) DEFAULT '',
`strategy_namespace` LowCardinality(String) DEFAULT '',
`event_namespace` LowCardinality(String) DEFAULT '',
`actor_name` LowCardinality(String) DEFAULT '',
`exec_venue` LowCardinality(String) DEFAULT '',
`data_venue` LowCardinality(String) DEFAULT '',
`market_state_bundle_json` String DEFAULT '',
`tp_base_pct` Float32 DEFAULT 0,
`tp_effective_pct` Float32 DEFAULT 0,
`our_leverage` Float32 DEFAULT 0,
`fee` Float64 DEFAULT 0,
`fee_source` LowCardinality(String) DEFAULT '',
`is_maker` UInt8 DEFAULT 0,
`slippage_bps` Float32 DEFAULT 0,
`mark_at_submit` Float64 DEFAULT 0,
`exchange_ts` Int64 DEFAULT 0,
`pnl_source` LowCardinality(String) DEFAULT ''
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(ts)
ORDER BY (ts, asset)
SETTINGS index_granularity = 8192;