feat(bot): add control-plane schema and hasura tracking
This commit is contained in:
@@ -111,6 +111,50 @@ ALTER TABLE api_tokens ADD COLUMN IF NOT EXISTS scopes TEXT[] NOT NULL DEFAULT A
|
||||
CREATE INDEX IF NOT EXISTS api_tokens_revoked_at_idx
|
||||
ON api_tokens (revoked_at);
|
||||
|
||||
-- Bot control-plane (desired state) + executor telemetry (state/events).
|
||||
--
|
||||
-- MVP intent:
|
||||
-- - `bot_config`: desired state (mode/market/limits/kill switch)
|
||||
-- - `bot_state`: heartbeat + last error/action
|
||||
-- - `bot_events`: append-only audit log
|
||||
CREATE TABLE IF NOT EXISTS public.bot_config (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
market_name TEXT NOT NULL,
|
||||
market_type TEXT NOT NULL DEFAULT 'perp',
|
||||
mode TEXT NOT NULL DEFAULT 'off',
|
||||
kill_switch BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
params JSONB,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS bot_config_updated_at_desc_idx
|
||||
ON public.bot_config (updated_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.bot_state (
|
||||
bot_id UUID PRIMARY KEY REFERENCES public.bot_config(id) ON DELETE CASCADE,
|
||||
last_heartbeat_at TIMESTAMPTZ,
|
||||
last_action_at TIMESTAMPTZ,
|
||||
last_error TEXT,
|
||||
state JSONB,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS bot_state_updated_at_desc_idx
|
||||
ON public.bot_state (updated_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.bot_events (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
bot_id UUID NOT NULL REFERENCES public.bot_config(id) ON DELETE CASCADE,
|
||||
ts TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
type TEXT NOT NULL,
|
||||
payload JSONB
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS bot_events_bot_ts_desc_idx
|
||||
ON public.bot_events (bot_id, ts DESC);
|
||||
|
||||
-- Compute OHLC candles from `drift_ticks` for a symbol and bucket size.
|
||||
-- Exposed via Hasura (track function) and used by trade-api to compute indicators server-side.
|
||||
-- Hasura tracks functions only if they return SETOF a table/view type.
|
||||
|
||||
Reference in New Issue
Block a user