Files
ai-exchange/migrations/016_create_trade_executions.sql
2026-04-24 13:39:01 +08:00

30 lines
984 B
SQL

create table if not exists trade_executions (
id bigserial primary key,
signal_id bigint not null references trade_signals(id),
venue_order_id text,
execution_mode text not null,
side text not null,
entry_price numeric(20,10),
stop_loss numeric(20,10),
take_profit_1 numeric(20,10),
take_profit_2 numeric(20,10),
size numeric(28,10),
risk_pct numeric(8,4),
status text not null,
opened_ts timestamptz,
closed_ts timestamptz,
pnl numeric(28,10),
meta jsonb not null default '{}'::jsonb,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_trade_executions_signal_id
on trade_executions (signal_id);
create index if not exists idx_trade_executions_status_created_desc
on trade_executions (status, created_at desc);
create index if not exists idx_trade_executions_mode_created_desc
on trade_executions (execution_mode, created_at desc);