clickhouse: commit exit-leg/reconstruction/maras DDLs + UV/violet DDLs (M1 vendor reconcile, upstream-first)
This commit is contained in:
1
prod/clickhouse/pink/00_create_database.sql
Normal file
1
prod/clickhouse/pink/00_create_database.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE DATABASE IF NOT EXISTS dolphin_pink;
|
||||
51
prod/clickhouse/pink/01_create_policy_events.sql
Normal file
51
prod/clickhouse/pink/01_create_policy_events.sql
Normal file
@@ -0,0 +1,51 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.policy_events
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`strategy` LowCardinality(String),
|
||||
`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 '',
|
||||
`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
|
||||
18
prod/clickhouse/pink/02_create_trade_reconstruction.sql
Normal file
18
prod/clickhouse/pink/02_create_trade_reconstruction.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.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,
|
||||
`market_state_bundle_json` String DEFAULT '',
|
||||
`tp_base_pct` Float32 DEFAULT 0,
|
||||
`tp_effective_pct` Float32 DEFAULT 0,
|
||||
`our_leverage` Float32 DEFAULT 0
|
||||
)
|
||||
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/pink/03_create_trade_exit_legs.sql
Normal file
36
prod/clickhouse/pink/03_create_trade_exit_legs.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.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
|
||||
26
prod/clickhouse/pink/04_create_position_state.sql
Normal file
26
prod/clickhouse/pink/04_create_position_state.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.position_state
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`trade_id` String,
|
||||
`asset` LowCardinality(String),
|
||||
`direction` Int8,
|
||||
`entry_price` Float64,
|
||||
`quantity` Float64,
|
||||
`notional` Float64,
|
||||
`leverage` Float32,
|
||||
`bucket_id` Int32 DEFAULT -1,
|
||||
`entry_bar` Int32 DEFAULT 0,
|
||||
`status` LowCardinality(String),
|
||||
`exit_reason` LowCardinality(String) DEFAULT '',
|
||||
`pnl` Float64 DEFAULT 0,
|
||||
`bars_held` UInt16 DEFAULT 0,
|
||||
`market_state_bundle_json` String DEFAULT '',
|
||||
`tp_base_pct` Float32 DEFAULT 0,
|
||||
`tp_effective_pct` Float32 DEFAULT 0,
|
||||
`our_leverage` Float32 DEFAULT 0
|
||||
)
|
||||
ENGINE = ReplacingMergeTree(ts)
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (trade_id, ts)
|
||||
TTL toDateTime(ts) + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
5
prod/clickhouse/pink/05_alter_trade_events_maras_tp.sql
Normal file
5
prod/clickhouse/pink/05_alter_trade_events_maras_tp.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE dolphin_pink.trade_events
|
||||
ADD COLUMN IF NOT EXISTS market_state_bundle_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS tp_base_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS tp_effective_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS our_leverage Float32 DEFAULT 0;
|
||||
18
prod/clickhouse/pink/05_create_anomaly_events.sql
Normal file
18
prod/clickhouse/pink/05_create_anomaly_events.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.anomaly_events
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`decision_id` String,
|
||||
`trade_id` String,
|
||||
`symbol` LowCardinality(String),
|
||||
`anomaly` LowCardinality(String),
|
||||
`origin` LowCardinality(String),
|
||||
`sensor` LowCardinality(String) DEFAULT '',
|
||||
`detail` String DEFAULT '',
|
||||
`rm_meta` Float32 DEFAULT 0
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts_day, trade_id, anomaly, ts)
|
||||
TTL ts_day + toIntervalDay(180)
|
||||
SETTINGS index_granularity = 8192
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE dolphin_pink.position_state
|
||||
ADD COLUMN IF NOT EXISTS market_state_bundle_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS tp_base_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS tp_effective_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS our_leverage Float32 DEFAULT 0;
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE dolphin_pink.trade_reconstruction
|
||||
ADD COLUMN IF NOT EXISTS market_state_bundle_json String DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS tp_base_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS tp_effective_pct Float32 DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS our_leverage Float32 DEFAULT 0;
|
||||
30
prod/clickhouse/pink/account_events.sql
Normal file
30
prod/clickhouse/pink/account_events.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE TABLE dolphin_pink.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 '',
|
||||
`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 '',
|
||||
`notes` String DEFAULT ''
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY (ts, event_type)
|
||||
SETTINGS index_granularity = 8192
|
||||
29
prod/clickhouse/pink/adaptive_exit_shadow.sql
Normal file
29
prod/clickhouse/pink/adaptive_exit_shadow.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
CREATE TABLE dolphin_pink.adaptive_exit_shadow
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`trade_id` String,
|
||||
`asset` LowCardinality(String),
|
||||
`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 '',
|
||||
`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/pink/status_snapshots.sql
Normal file
31
prod/clickhouse/pink/status_snapshots.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
CREATE TABLE dolphin_pink.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
|
||||
58
prod/clickhouse/pink/trade_events.sql
Normal file
58
prod/clickhouse/pink/trade_events.sql
Normal file
@@ -0,0 +1,58 @@
|
||||
CREATE TABLE dolphin_pink.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 '',
|
||||
`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 '',
|
||||
`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 '',
|
||||
`market_state_bundle_json` String DEFAULT '',
|
||||
`tp_base_pct` Float32 DEFAULT 0,
|
||||
`tp_effective_pct` Float32 DEFAULT 0,
|
||||
`our_leverage` Float32 DEFAULT 0
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (ts, asset)
|
||||
SETTINGS index_granularity = 8192
|
||||
51
prod/clickhouse/pink/v7_decision_events.sql
Normal file
51
prod/clickhouse/pink/v7_decision_events.sql
Normal file
@@ -0,0 +1,51 @@
|
||||
CREATE TABLE IF NOT EXISTS dolphin_pink.v7_decision_events
|
||||
(
|
||||
`ts` DateTime64(6, 'UTC'),
|
||||
`ts_day` Date MATERIALIZED toDate(ts),
|
||||
`strategy` LowCardinality(String),
|
||||
`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 '',
|
||||
`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