-- OHLCV bar data for prediction generation
-- Used by trading_service prediction_generation_loop to query recent market data
CREATE TABLE IF NOT EXISTS ohlcv_bars (
    id         BIGSERIAL PRIMARY KEY,
    symbol     VARCHAR(32)      NOT NULL,
    timestamp  TIMESTAMPTZ      NOT NULL,
    open       DOUBLE PRECISION NOT NULL,
    high       DOUBLE PRECISION NOT NULL,
    low        DOUBLE PRECISION NOT NULL,
    close      DOUBLE PRECISION NOT NULL,
    volume     DOUBLE PRECISION NOT NULL DEFAULT 0,
    UNIQUE (symbol, timestamp)
);

CREATE INDEX IF NOT EXISTS idx_ohlcv_bars_symbol_ts
    ON ohlcv_bars (symbol, timestamp DESC);
