File size: 1,180 Bytes
77fd2f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
-- schema.sql
-- Run this script to initialize the TimescaleDB schema

-- First, ensure the TimescaleDB extension is enabled (requires superuser)
-- CREATE EXTENSION IF NOT EXISTS timescaledb;

CREATE TABLE IF NOT EXISTS tick_data (
    timestamp TIMESTAMPTZ NOT NULL,
    market_id VARCHAR(100),
    platform VARCHAR(20),  -- 'polymarket' or 'kalshi'
    event_name TEXT,
    outcome VARCHAR(50),   -- 'YES', 'NO', or other specific outcomes
    bid_price DECIMAL(10,8),
    bid_size DECIMAL(15,2),
    ask_price DECIMAL(10,8),
    ask_size DECIMAL(15,2),
    mid_price DECIMAL(10,8),
    volume_24h DECIMAL(15,2),
    CONSTRAINT pk_tick PRIMARY KEY (timestamp, market_id, platform, outcome)
);

-- Convert tick_data to a hypertable if TimescaleDB is installed
-- SELECT create_hypertable('tick_data', 'timestamp', if_not_exists => TRUE);

CREATE TABLE IF NOT EXISTS trades (
    trade_id SERIAL PRIMARY KEY,
    timestamp TIMESTAMPTZ NOT NULL,
    strategy VARCHAR(50),
    market_id VARCHAR(100),
    platform VARCHAR(20),
    side VARCHAR(10),
    price DECIMAL(10,8),
    size DECIMAL(15,2),
    fees DECIMAL(15,2),
    pnl DECIMAL(15,2),
    execution_latency_ms INTEGER
);