19 lines
672 B
SQL
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);
|