clickhouse: commit exit-leg/reconstruction/maras DDLs + UV/violet DDLs (M1 vendor reconcile, upstream-first)
This commit is contained in:
1
prod/clickhouse/prodgreen/00_create_database.sql
Normal file
1
prod/clickhouse/prodgreen/00_create_database.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE DATABASE IF NOT EXISTS dolphin_prodgreen;
|
||||
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE dolphin_prodgreen.account_events
|
||||
ADD COLUMN IF NOT EXISTS current_open_notional Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS current_account_leverage Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage UInt8 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage_mode LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS leverage_mapping_rule LowCardinality(String) DEFAULT '';
|
||||
@@ -0,0 +1,12 @@
|
||||
ALTER TABLE dolphin_prodgreen.status_snapshots
|
||||
ADD COLUMN IF NOT EXISTS conviction_multiplier Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage UInt8 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage_mode LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS leverage_mapping_rule LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS account_capital Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS portfolio_capital Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS current_open_notional Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS current_account_leverage Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS remaining_notional_capacity Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS max_account_leverage Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS ledger_authority LowCardinality(String) DEFAULT '';
|
||||
@@ -0,0 +1,18 @@
|
||||
ALTER TABLE dolphin_prodgreen.trade_events
|
||||
ADD COLUMN IF NOT EXISTS trade_id String DEFAULT '' AFTER ts,
|
||||
ADD COLUMN IF NOT EXISTS conviction_multiplier Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage UInt8 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS exchange_leverage_mode LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS leverage_mapping_rule LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS account_capital Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS portfolio_capital Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS current_open_notional Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS remaining_notional_capacity Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS max_account_leverage Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS margin_required Float64 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS ledger_authority LowCardinality(String) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS entry_payload_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS exit_payload_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS execution_payload_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS friction_payload_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS event_payload_json String DEFAULT '';
|
||||
14
prod/clickhouse/prodgreen/02_create_trade_reconstruction.sql
Normal file
14
prod/clickhouse/prodgreen/02_create_trade_reconstruction.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_prodgreen.trade_reconstruction
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`trade_id` String,
|
||||
`event_type` LowCardinality(String),
|
||||
`event_id` String,
|
||||
`payload_json` String
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts_day, trade_id, event_type, event_id)
|
||||
TTL ts_day + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
36
prod/clickhouse/prodgreen/03_create_trade_exit_legs.sql
Normal file
36
prod/clickhouse/prodgreen/03_create_trade_exit_legs.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_prodgreen.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
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts_day, trade_id, exit_seq, ts)
|
||||
TTL ts_day + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
24
prod/clickhouse/prodgreen/account_events.sql
Normal file
24
prod/clickhouse/prodgreen/account_events.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE dolphin_prodgreen.account_events
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`event_type` LowCardinality(String),
|
||||
`strategy` LowCardinality(String),
|
||||
`posture` LowCardinality(String),
|
||||
`capital` Float64,
|
||||
`peak_capital` Float64,
|
||||
`drawdown_pct` Float32,
|
||||
`pnl_today` Float64 DEFAULT 0,
|
||||
`trades_today` UInt16 DEFAULT 0,
|
||||
`open_positions` UInt8 DEFAULT 0,
|
||||
`boost` Float32 DEFAULT 1.,
|
||||
`beta` Float32 DEFAULT 0.,
|
||||
`current_open_notional` Float64 DEFAULT 0,
|
||||
`current_account_leverage` Float32 DEFAULT 0,
|
||||
`exchange_leverage` UInt8 DEFAULT 0,
|
||||
`exchange_leverage_mode` LowCardinality(String) DEFAULT '',
|
||||
`leverage_mapping_rule` LowCardinality(String) DEFAULT '',
|
||||
`notes` String DEFAULT ''
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY (ts, event_type)
|
||||
SETTINGS index_granularity = 8192
|
||||
23
prod/clickhouse/prodgreen/adaptive_exit_shadow.sql
Normal file
23
prod/clickhouse/prodgreen/adaptive_exit_shadow.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE dolphin_prodgreen.adaptive_exit_shadow
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`trade_id` String,
|
||||
`asset` LowCardinality(String),
|
||||
`bucket_id` UInt8,
|
||||
`bars_held` UInt16,
|
||||
`mae_norm` Float32,
|
||||
`mfe_norm` Float32,
|
||||
`tau_norm` Float32,
|
||||
`p_cont` Float32,
|
||||
`vel_div_entry` Float32,
|
||||
`vel_div_now` Float32,
|
||||
`action` LowCardinality(String),
|
||||
`exit_reason` LowCardinality(String),
|
||||
`actual_exit` LowCardinality(String),
|
||||
`pnl_pct` Float32
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY (ts_day, asset, ts)
|
||||
TTL ts_day + toIntervalDay(90)
|
||||
SETTINGS index_granularity = 8192
|
||||
31
prod/clickhouse/prodgreen/status_snapshots.sql
Normal file
31
prod/clickhouse/prodgreen/status_snapshots.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
CREATE TABLE dolphin_prodgreen.status_snapshots
|
||||
(
|
||||
`ts` DateTime64(3, 'UTC'),
|
||||
`capital` Float64,
|
||||
`roi_pct` Float32,
|
||||
`dd_pct` Float32,
|
||||
`trades_executed` UInt16,
|
||||
`posture` LowCardinality(String),
|
||||
`rm` Float32,
|
||||
`vel_div` Float32,
|
||||
`vol_ok` UInt8,
|
||||
`phase` LowCardinality(String),
|
||||
`mhs_status` LowCardinality(String),
|
||||
`boost` Float32,
|
||||
`cat5` 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,
|
||||
`current_account_leverage` Float32 DEFAULT 0,
|
||||
`remaining_notional_capacity` Float64 DEFAULT 0,
|
||||
`max_account_leverage` Float32 DEFAULT 0,
|
||||
`ledger_authority` LowCardinality(String) DEFAULT ''
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY ts
|
||||
TTL toDateTime(ts) + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
48
prod/clickhouse/prodgreen/trade_events.sql
Normal file
48
prod/clickhouse/prodgreen/trade_events.sql
Normal file
@@ -0,0 +1,48 @@
|
||||
CREATE TABLE dolphin_prodgreen.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 ''
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts, asset)
|
||||
SETTINGS index_granularity = 8192
|
||||
45
prod/clickhouse/prodgreen/v7_decision_events.sql
Normal file
45
prod/clickhouse/prodgreen/v7_decision_events.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
CREATE TABLE dolphin_prodgreen.v7_decision_events
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`strategy` LowCardinality(String),
|
||||
`source` LowCardinality(String),
|
||||
`trade_id` String,
|
||||
`asset` LowCardinality(String),
|
||||
`side` LowCardinality(String),
|
||||
`entry_price` Float64,
|
||||
`current_price` Float64,
|
||||
`quantity` Float64,
|
||||
`notional` Float64,
|
||||
`leverage` Float32,
|
||||
`bar_idx` UInt32,
|
||||
`decision_seq` UInt32,
|
||||
`bars_held` UInt16,
|
||||
`action` LowCardinality(String),
|
||||
`reason` LowCardinality(String),
|
||||
`pnl_pct` Float32,
|
||||
`mfe` Float32,
|
||||
`mae` Float32,
|
||||
`mfe_risk` Float32,
|
||||
`mae_risk` Float32,
|
||||
`exit_pressure` Float32,
|
||||
`rv_comp` Float32,
|
||||
`mae_thresh1` Float32,
|
||||
`bounce_score` Float32,
|
||||
`bounce_risk` Float32,
|
||||
`ob_imbalance` Float32,
|
||||
`vel_div_entry` Float32,
|
||||
`vel_div_now` Float32,
|
||||
`v50_vel` Float32,
|
||||
`v750_vel` Float32,
|
||||
`exf_funding` Float32,
|
||||
`exf_dvol` Float32,
|
||||
`exf_fear_greed` Float32,
|
||||
`exf_taker` Float32,
|
||||
`posture` LowCardinality(String)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts_day, trade_id, decision_seq, ts)
|
||||
TTL ts_day + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
Reference in New Issue
Block a user