diff options
Diffstat (limited to 'frontend/src/lib/types.ts')
| -rw-r--r-- | frontend/src/lib/types.ts | 244 |
1 files changed, 244 insertions, 0 deletions
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts new file mode 100644 index 0000000..db065e4 --- /dev/null +++ b/frontend/src/lib/types.ts @@ -0,0 +1,244 @@ +import type { CoverageEntry } from './coverage'; + +export type { CoverageEntry }; + +export interface User { + id: string; + email: string; + name: string; + role: 'admin' | 'member'; + active: boolean; + daily_run_limit?: number | null; + ai_enabled?: boolean; + created_at?: string; +} + +export interface Project { + id: string; + name: string; + description: string | null; + draft_code: string; + draft_generation: number; + draft_code_preview?: string; + created_at: string; + updated_at: string; +} + +export interface Version { + id: string; + project_id: string; + message: string; + hash: string; + source: 'manual' | 'run' | 'ai' | 'restore'; + created_at: string; + code?: string; +} + +export interface Instrument { + symbol: string; + market: string; + asset_type: 'stock' | 'etf' | 'index'; + name: string | null; + currency: string | null; + source?: string | null; +} + +export interface InstrumentSearchItem extends Instrument { + symbol_requested?: string; +} + +export interface InstrumentSearchResponse { + items: Instrument[]; + source: 'provider_suggest' | 'operator_entry' | 'none'; + status: string; +} + +export interface DatasetManifestObject { + instrument: string; + market?: string; + asset_type?: string; + provider: string; + endpoint?: string; + params?: Record<string, unknown>; + akshare_version?: string; + fetched_at?: string; + requested_start: string; + requested_end: string; + actual_start: string | null; + actual_end: string | null; + row_count: number; + columns: string[]; + adjustment: string; + frequency?: string; + warnings?: string[]; +} + +export interface DatasetRequest { + name?: string; + instruments: Instrument[]; + start_date: string; + end_date: string; + frequency: 'daily'; + adjustment: 'none' | 'qfq' | 'hfq'; + fields: string[]; +} + +export interface Dataset { + id: string; + name: string | null; + request: DatasetRequest; + status: 'pending' | 'running' | 'ready' | 'failed'; + manifest?: DatasetManifest | null; + manifest_hash?: string | null; + error?: string | null; + cache_hit?: boolean; + created_at: string; +} + +export interface DatasetManifest { + version?: string; + hash?: string; + objects: DatasetManifestObject[]; + columns?: string[]; +} + +export interface DatasetPreview { + columns: string[]; + rows: Record<string, unknown>[]; + coverage: CoverageEntry[]; + warnings: string[]; + truncated?: boolean; +} + +export interface RunConfig { + capital: number; + commission: number; + slippage: number; + benchmark_symbol?: string | null; + parameters?: Record<string, unknown>; +} + +export interface Run { + id: string; + project_id: string; + version_id: string; + dataset_id: string; + status: 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled'; + config: RunConfig; + created_at: string; + started_at?: string | null; + finished_at?: string | null; + error?: string | null; + result?: BacktestResult | null; +} + +export interface Trade { + date: string; + symbol: string; + side: string; + quantity: number; + price: number; + commission: number; + value: number; +} + +export interface OrderRecord { + date?: string; + symbol?: string; + side?: string; + quantity?: number; + price?: number | null; + state?: string; + value?: number | null; + commission?: number | null; +} + +export interface BacktestMetrics { + total_return?: number | null; + annual_return?: number | null; + max_drawdown?: number | null; + sharpe?: number | null; + /** closed ROUND-TRIP count (open fully closed = 1), NOT fill count */ + trade_count?: number | null; + final_equity?: number | null; +} + +export interface BacktestResult { + equity: { date: string; equity: number; cash: number; benchmark?: number | null }[]; + orders?: OrderRecord[]; + trades: Trade[]; + metrics: BacktestMetrics; + logs: string[]; + engine: { name: string; version: string }; + warnings: string[]; + elapsed_ms?: number | null; + peak_rss_kb?: number | null; + data_manifest_hash?: string; +} + +export interface RunListItem extends Run { + project_name?: string; +} + +export interface AIUsageItem { + id: string; + project_id?: string; + model: string; + input_tokens?: number; + output_tokens?: number; + status?: string; + created_at: string; +} + +export interface AIUsage { + items: AIUsageItem[]; + totals?: { input_tokens?: number; output_tokens?: number; requests?: number }; + internal_poc?: boolean; +} + +export interface AIAssist { + id: string; + model: string; + explanation: string; + proposed_code: string; + diff: string | null; + base_generation: number; + usage?: { input_tokens?: number; output_tokens?: number } | null; + status?: string; +} + +export interface Invitation { + id: string; + email?: string | null; + role?: string; + token?: string | null; + expires_at?: string; + used_at?: string | null; + revoked?: boolean; + created_by?: string; + created_at?: string; +} + +export interface AdminUserUpdate extends Partial<Omit<User, 'id' | 'email' | 'created_at'>> {} + +export interface Capabilities { + frequencies: string[]; + asset_types: string[]; + adjustments: { code: string; label: string }[]; + fields: { code: string; label: string; raw?: boolean }[]; + limits: { + max_symbols: number; + max_years: number; + max_code_length: number; + }; + internal_only: boolean; +} + +export interface SessionInfo { + id: string; + created_at?: string; + last_seen_at?: string | null; + user_agent?: string | null; + expires_at?: string | null; + current?: boolean; +} |
