-- Stores per-position results from backtest runs.
-- Kept separate from paper_runs.result_summary to avoid hitting the 256 MB jsonb limit.
CREATE TABLE paper_run_positions (
    id          BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    run_id      UUID NOT NULL REFERENCES paper_runs(id) ON DELETE CASCADE,
    seq         INTEGER NOT NULL,           -- chronological order within the run
    side        TEXT NOT NULL,              -- 'Buy' or 'Sell' (entry direction)
    price_entry NUMERIC NOT NULL,
    price_exit  NUMERIC NOT NULL,
    quantity    NUMERIC NOT NULL,
    pnl         NUMERIC NOT NULL,
    fees_enter  NUMERIC NOT NULL,
    fees_exit   NUMERIC NOT NULL,
    time_enter  TIMESTAMPTZ NOT NULL,
    time_exit   TIMESTAMPTZ NOT NULL
);

CREATE INDEX idx_paper_run_positions_run_id ON paper_run_positions(run_id, seq);
