-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
48 lines (40 loc) · 1.29 KB
/
init.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- Drop existing tables
DROP TABLE IF EXISTS trades CASCADE;
-- Create trades table
CREATE TABLE trades (
id SERIAL PRIMARY KEY,
trade_id VARCHAR(50) UNIQUE NOT NULL,
order_id VARCHAR(50),
position_id VARCHAR(50),
mt5_ticket VARCHAR(50),
-- Trade details
instrument VARCHAR(20) NOT NULL,
side VARCHAR(10) NOT NULL,
quantity DECIMAL NOT NULL,
type VARCHAR(20) NOT NULL,
-- Prices
ask_price DECIMAL,
bid_price DECIMAL,
execution_price DECIMAL,
-- Status
status VARCHAR(20) NOT NULL DEFAULT 'new',
error_message TEXT,
is_closed BOOLEAN DEFAULT FALSE,
-- JSON data
tv_request JSONB,
tv_response JSONB,
execution_data JSONB,
mt5_response JSONB,
-- Timestamps
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
executed_at TIMESTAMP WITH TIME ZONE,
-- Indexes
CONSTRAINT trades_trade_id_key UNIQUE (trade_id)
);
-- Create indexes
CREATE INDEX idx_trades_order_id ON trades(order_id);
CREATE INDEX idx_trades_position_id ON trades(position_id);
CREATE INDEX idx_trades_status ON trades(status);
CREATE INDEX idx_trades_instrument ON trades(instrument);
CREATE INDEX idx_trades_created_at ON trades(created_at);