Canonical TSAPI series DB schema v1.0.0

Single source of truth for the timeseries PostgreSQL schema shared by the
Python (TSAPI_SERIESDB_PG_PY) and C++ (TSAPI_POSTGRES_CPP) libraries. SQL
seeded byte-for-byte from TSAPI_SERIESDB_PG_PY/tsapi_pgdb/sql on 2026-09-02.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
peter 2026-09-02 17:27:26 +01:00
commit eed06559c0
17 changed files with 2080 additions and 0 deletions

View file

@ -0,0 +1,99 @@
-- Migration: Add Instrument Metadata Columns
-- Date: 2026-02-11
-- Description: Adds classification and trading specification columns to meta.exchanges and meta.instruments
-- ============================================================================
-- 1. Add columns to meta.exchanges
-- ============================================================================
-- Trading specifications
ALTER TABLE meta.exchanges ADD COLUMN IF NOT EXISTS default_tick_size DOUBLE PRECISION;
ALTER TABLE meta.exchanges ADD COLUMN IF NOT EXISTS default_tick_value DOUBLE PRECISION;
ALTER TABLE meta.exchanges ADD COLUMN IF NOT EXISTS default_extended_hours BOOLEAN DEFAULT false;
-- Geographic info
ALTER TABLE meta.exchanges ADD COLUMN IF NOT EXISTS country VARCHAR(3);
COMMENT ON COLUMN meta.exchanges.default_tick_size IS 'Default minimum price increment (e.g., 0.01 for stocks)';
COMMENT ON COLUMN meta.exchanges.default_tick_value IS 'Default value per tick in currency (0.01 for stocks = 1 cent per share)';
COMMENT ON COLUMN meta.exchanges.default_extended_hours IS 'Default for whether instruments support pre/post market trading';
COMMENT ON COLUMN meta.exchanges.country IS 'ISO 3166-1 alpha-3 country code (USA, GBR, JPN)';
-- ============================================================================
-- 2. Add columns to meta.instruments
-- ============================================================================
-- Basic info
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS description VARCHAR(255);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS country VARCHAR(3);
-- Trading specifications
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS extended_hours BOOLEAN;
-- Company/Fund classification
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS sector VARCHAR(50);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS industry VARCHAR(100);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS category VARCHAR(50);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS subcategory VARCHAR(50);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS asset_class VARCHAR(30);
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS geography VARCHAR(30);
-- ETF-specific
ALTER TABLE meta.instruments ADD COLUMN IF NOT EXISTS underlying VARCHAR(30);
COMMENT ON COLUMN meta.instruments.description IS 'Full name/description of the instrument';
COMMENT ON COLUMN meta.instruments.country IS 'ISO 3166-1 alpha-3 country code (overrides exchange default)';
COMMENT ON COLUMN meta.instruments.extended_hours IS 'Override exchange default for pre/post market trading';
COMMENT ON COLUMN meta.instruments.sector IS 'GICS sector (e.g., Technology, Financials)';
COMMENT ON COLUMN meta.instruments.industry IS 'GICS industry (e.g., Software-Application)';
COMMENT ON COLUMN meta.instruments.category IS 'Custom categorization (e.g., Sector ETF, Broad Market)';
COMMENT ON COLUMN meta.instruments.subcategory IS 'Custom sub-categorization (e.g., S&P 500, Technology)';
COMMENT ON COLUMN meta.instruments.asset_class IS 'Asset class (Equity, Fixed Income, Commodity, Currency)';
COMMENT ON COLUMN meta.instruments.geography IS 'Geographic focus (US, International, Emerging)';
COMMENT ON COLUMN meta.instruments.underlying IS 'Underlying symbol for ETFs/derivatives (e.g., SPX, NDX)';
-- ============================================================================
-- 3. Update existing exchange data
-- ============================================================================
-- Update NYSE if it exists
UPDATE meta.exchanges
SET
default_tick_size = 0.01,
default_tick_value = 0.01,
default_extended_hours = true,
country = 'USA'
WHERE id = 'NYSE';
-- Update CME if it exists
UPDATE meta.exchanges
SET
country = 'USA',
default_extended_hours = true
WHERE id = 'CME';
-- Add NASDAQ if it doesn't exist
INSERT INTO meta.exchanges (
id, name, timezone, currency, default_sec_type,
default_tick_size, default_tick_value, default_extended_hours, country
)
SELECT 'NASDAQ', 'NASDAQ Stock Market', 'America/New_York', 'USD', 'STK',
0.01, 0.01, true, 'USA'
WHERE NOT EXISTS (SELECT 1 FROM meta.exchanges WHERE id = 'NASDAQ');
-- ============================================================================
-- Migration Complete
-- ============================================================================
-- Verify the changes
SELECT 'meta.exchanges columns:' as info;
SELECT column_name, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'meta' AND table_name = 'exchanges'
ORDER BY ordinal_position;
SELECT 'meta.instruments columns:' as info;
SELECT column_name, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'meta' AND table_name = 'instruments'
ORDER BY ordinal_position;