Files
aitrade/pkg/db/migrations/004_positions.sql
T
kaedwen ea141eb012
Build and Push Docker Image / build-and-push (push) Failing after 1m41s
initial
2026-07-02 20:09:44 +02:00

19 lines
672 B
SQL

-- Positions table to track open positions
CREATE TABLE IF NOT EXISTS positions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
quantity INTEGER NOT NULL,
entry_price REAL NOT NULL,
entry_trade_id INTEGER NOT NULL,
current_price REAL,
unrealized_pnl REAL,
opened_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (entry_trade_id) REFERENCES trades(id),
UNIQUE(symbol) -- Only one open position per symbol
);
CREATE INDEX IF NOT EXISTS idx_positions_symbol ON positions(symbol);
CREATE INDEX IF NOT EXISTS idx_positions_entry_trade ON positions(entry_trade_id);