-- ============================================================================
-- Schema: trading
-- Table: symbols
-- Description: Catálogo de símbolos/instrumentos financieros operables
-- Dependencies: None
-- ============================================================================

CREATE TABLE trading.symbols (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),

  -- Identificación
  symbol VARCHAR(20) NOT NULL UNIQUE, -- BTC/USDT, EUR/USD
  name VARCHAR(100) NOT NULL,
  base_asset VARCHAR(10) NOT NULL,    -- BTC, EUR
  quote_asset VARCHAR(10) NOT NULL,   -- USDT, USD

  -- Tipo
  asset_class VARCHAR(50) NOT NULL,   -- crypto, forex, stocks
  exchange VARCHAR(50),               -- binance, coinbase

  -- Precisión
  price_precision INTEGER NOT NULL DEFAULT 8,
  quantity_precision INTEGER NOT NULL DEFAULT 8,

  -- Límites
  min_quantity DECIMAL(20,8),
  max_quantity DECIMAL(20,8),
  min_notional DECIMAL(20,8),

  -- Estado
  is_active BOOLEAN DEFAULT true,
  is_tradeable BOOLEAN DEFAULT true,

  -- Timestamps
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Índices
CREATE INDEX idx_symbols_symbol ON trading.symbols(symbol);
CREATE INDEX idx_symbols_active ON trading.symbols(is_active) WHERE is_active = true;
CREATE INDEX idx_symbols_asset_class ON trading.symbols(asset_class);
CREATE INDEX idx_symbols_exchange ON trading.symbols(exchange);

-- Comentarios
COMMENT ON TABLE trading.symbols IS 'Catálogo de símbolos/instrumentos financieros operables';
COMMENT ON COLUMN trading.symbols.symbol IS 'Símbolo del instrumento (e.g., BTC/USDT)';
COMMENT ON COLUMN trading.symbols.asset_class IS 'Clase de activo: crypto, forex, stocks, commodities';
COMMENT ON COLUMN trading.symbols.is_tradeable IS 'Indica si el símbolo está disponible para trading';
