// ═══════════ FTDT Quant Lab — Type Definitions ═══════════

export interface Strategy {
  allocation: number;
  instrument: string;
  pnl: number;
  pnl_pct: number;
  position: number;
  trades_today: number;
  wins: number;
  win_rate: number;
  status: "running" | "idle";
  size: number;
  fee_paid: number;
  fee_model: "maker" | "taker";
  type: string;
  description: string;
  signals: { signal: string; ts: number }[];
  max_position?: number;
  stop_loss?: number;
  entry_price?: number;
}

export interface Trade {
  time: string;
  strategy: string;
  side: string;
  size: number;
  price: number;
  pnl: number;
  fee: number;
  reason?: string;
  pnl_net?: number;
  pnl_gross?: number;
}

export interface Position {
  strategy: string;
  size: number;
  entry_px: number;
  pnl?: number;
}

export interface Order {
  coin: string;
  side: "B" | "A";
  sz: number;
  limitPx?: string;
  cloid?: string;
}

export interface LiveMetrics {
  timestamp: number;
  wallet: string;
  total_equity: number;
  base_equity: number;
  total_pnl: number;
  total_pnl_pct: number;
  reserve: number;
  equity_history: { t: number; v: number }[];
  strategy_equity: Record<string, { t: number; v: number }[]>;
  strategies: Record<string, Strategy>;
  trades: Trade[];
  status: string;
  testnet_up: boolean;
  open_positions: Position[];
  open_orders: Order[];
}

export interface PaperMetrics {
  timestamp: number;
  total_equity: number;
  base_equity: number;
  total_pnl: number;
  total_pnl_pct: number;
  regime: string;
  equity_history: { t: number; v: number }[];
  strategy_equity: Record<string, { t: number; v: number }[]>;
  strategies: Record<string, Strategy>;
  per_strategy_trades: Record<string, Trade[]>;
  open_positions: Position[];
  open_orders: Order[];
}

export interface BacktestSummary {
  name: string;
  strategy: string;
  start: string;
  end: string;
  sharpe: number;
  sortino: number;
  pnl_pct: number;
  max_dd: number;
  win_rate: number;
  total_trades: number;
  coin: string;
}

export interface BacktestFull {
  name?: string;
  strategy: string;
  pnl_net?: number;
  pnl_gross?: number;
  pnl_pct?: number;
  pnl_net_pct?: number;
  pnl_gross_pct?: number;
  pnl: number;
  sharpe: number;
  sortino: number;
  max_dd: number;
  win_rate: number;
  total_trades: number;
  fees_total: number;
  num_periods: number;
  fee_model: string;
  equity_curve: { t: number | string; v: number }[];
  trades: Trade[];
}
