FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
db migrations
tilakpatel229e070d5285fc
diff --git a/fincept-terminal-desktop/src-tauri/src/setup.rs b/fincept-terminal-desktop/src-tauri/src/setup.rsindex dd50fb617..df8561860 100644--- a/fincept-terminal-desktop/src-tauri/src/setup.rs+++ b/fincept-terminal-desktop/src-tauri/src/setup.rs@@ -35,16 +35,22 @@ const BUN_VERSION: &str = "1.1.0";// Optimized builds (require AVX2 - modern CPUs from ~2013+)const BUN_WINDOWS_X64_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-windows-x64.zip";+#[cfg(target_os = "macos")]const BUN_MACOS_X64_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-darwin-x64.zip";+#[cfg(target_os = "linux")]const BUN_LINUX_X64_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64.zip";// Baseline builds (work on all CPUs, slightly slower)const BUN_WINDOWS_X64_BASELINE_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-windows-x64-baseline.zip";-const BUN_DARWIN_X64_BASELINE_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-darwin-x64-baseline.zip";+#[cfg(target_os = "macos")]+const BUN_MACOS_X64_BASELINE_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-darwin-x64-baseline.zip";+#[cfg(target_os = "linux")]const BUN_LINUX_X64_BASELINE_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64-baseline.zip";// ARM builds (always optimized for their architecture)-const BUN_DARWIN_ARM_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-darwin-aarch64.zip";+#[cfg(target_os = "macos")]+const BUN_MACOS_ARM_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-darwin-aarch64.zip";+#[cfg(target_os = "linux")]const BUN_LINUX_ARM_URL: &str = "https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-aarch64.zip";/// Detect if CPU supports AVX2 (required for optimized Bun builds)@@ -932,7 +938,7 @@ async fn install_bun(app: &AppHandle) -> Result<(), String> {if cfg!(target_arch = "aarch64") {// ARM Macs always use optimized buildemit_progress(app, "bun", 5, "Downloading Bun for Apple Silicon...", false);- BUN_DARWIN_ARM_URL+ BUN_MACOS_ARM_URL} else {// Intel Macs - check for AVX2if cpu_supports_avx2() {@@ -940,7 +946,7 @@ async fn install_bun(app: &AppHandle) -> Result<(), String> {BUN_MACOS_X64_URL} else {emit_progress(app, "bun", 5, "Downloading baseline Bun for compatibility...", false);- BUN_DARWIN_X64_BASELINE_URL+ BUN_MACOS_X64_BASELINE_URL}}} else {diff --git a/fincept-terminal-desktop/src/components/dashboard/DashboardScreen.tsx b/fincept-terminal-desktop/src/components/dashboard/DashboardScreen.tsxindex 0ebce6a28..1cde91e7c 100644--- a/fincept-terminal-desktop/src/components/dashboard/DashboardScreen.tsx+++ b/fincept-terminal-desktop/src/components/dashboard/DashboardScreen.tsx@@ -42,6 +42,7 @@ import ReportBuilderTab from '@/components/tabs/ReportBuilderTab';import BacktestingTab from '@/components/tabs/BacktestingTabNew';import RecordedContextsManager from '@/components/common/RecordedContextsManager';import AgentConfigTab from '@/components/tabs/AgentConfigTab';+import ExcelTab from '@/components/tabs/ExcelTab';import { useTranslation } from 'react-i18next';// Dropdown Menu Component@@ -526,6 +527,7 @@ function FinxeptTerminalContent() {{ label: 'AI Assistant', shortcut: 'F10', action: () => setActiveTab('chat') },{ label: 'Agent Config', action: () => setActiveTab('agents') },{ label: 'MCP Servers', action: () => setActiveTab('mcp'), separator: true },+ { label: 'Excel Workbook', action: () => setActiveTab('excel') },{ label: 'Node Editor', action: () => setActiveTab('nodes') },{ label: 'Code Editor', action: () => setActiveTab('code') },{ label: 'Data Sources', action: () => setActiveTab('datasources'), separator: true },@@ -1041,6 +1043,9 @@ function FinxeptTerminalContent() {<TabsContent value="agents" className="h-full m-0 p-0"><AgentConfigTab /></TabsContent>+ <TabsContent value="excel" className="h-full m-0 p-0">+ <ExcelTab />+ </TabsContent></Tabs>)}</div>diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/services/MappingDatabase.ts b/fincept-terminal-desktop/src/components/tabs/data-mapping/services/MappingDatabase.tsindex 7416ab6a7..786993e52 100644--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/services/MappingDatabase.ts+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/services/MappingDatabase.ts@@ -1,51 +1,68 @@-// Mapping Database - LocalStorage-based storage for mappings and cache-// Migrated from SQLite to LocalStorage for simplicity+// Mapping Database - SQLite storage for mappings and cacheimport { DataMappingConfig } from '../types';import { encryptionService } from './EncryptionService';--const STORAGE_KEYS = {- MAPPINGS: 'fincept_data_mappings',- CACHE: 'fincept_mapping_cache',- PREFERENCES: 'fincept_mapping_preferences',-};--interface CacheEntry {- cache_key: string;- mapping_id: string;- params_hash: string;- response_json: string;- cached_at: string;- expires_at: string;-}+import { sqliteService } from '@/services/sqliteService';/*** Database service for storing mappings and API response cache- * Uses localStorage for persistence*/export class MappingDatabase {private initialized = false;/**- * Initialize database (localStorage setup)+ * Initialize database tables*/async initialize(): Promise<void> {if (this.initialized) return;try {- // Ensure storage keys exist- if (!localStorage.getItem(STORAGE_KEYS.MAPPINGS)) {- localStorage.setItem(STORAGE_KEYS.MAPPINGS, JSON.stringify({}));- }- if (!localStorage.getItem(STORAGE_KEYS.CACHE)) {- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify({}));- }- if (!localStorage.getItem(STORAGE_KEYS.PREFERENCES)) {- localStorage.setItem(STORAGE_KEYS.PREFERENCES, JSON.stringify({}));+ // Ensure main SQLite service is initialized+ if (!sqliteService.isReady()) {+ await sqliteService.initialize();}+ // Create mappings table+ await sqliteService.execute(`+ CREATE TABLE IF NOT EXISTS data_mappings (+ id TEXT PRIMARY KEY,+ name TEXT NOT NULL,+ description TEXT,+ config_json TEXT NOT NULL,+ created_at TEXT NOT NULL,+ updated_at TEXT NOT NULL+ )+ `);++ // Create cache table+ await sqliteService.execute(`+ CREATE TABLE IF NOT EXISTS mapping_cache (+ cache_key TEXT PRIMARY KEY,+ mapping_id TEXT NOT NULL,+ params_hash TEXT NOT NULL,+ response_json TEXT NOT NULL,+ cached_at TEXT NOT NULL,+ expires_at TEXT NOT NULL,+ FOREIGN KEY(mapping_id) REFERENCES data_mappings(id) ON DELETE CASCADE+ )+ `);++ // Create index for cache lookups+ await sqliteService.execute(`+ CREATE INDEX IF NOT EXISTS idx_mapping_cache_lookup+ ON mapping_cache(mapping_id, params_hash)+ `);++ // Create user preferences table+ await sqliteService.execute(`+ CREATE TABLE IF NOT EXISTS mapping_preferences (+ key TEXT PRIMARY KEY,+ value TEXT NOT NULL+ )+ `);+this.initialized = true;- console.log('MappingDatabase initialized successfully (localStorage)');+ console.log('MappingDatabase initialized successfully');} catch (error) {console.error('Failed to initialize MappingDatabase:', error);throw error;@@ -111,10 +128,22 @@ export class MappingDatabase {};}- // Save to localStorage- const mappings = this.getMappingsFromStorage();- mappings[config.id] = configToStore;- localStorage.setItem(STORAGE_KEYS.MAPPINGS, JSON.stringify(mappings));+ // Serialize config+ const configJson = JSON.stringify(configToStore);++ // Upsert mapping+ await sqliteService.execute(+ `INSERT OR REPLACE INTO data_mappings (id, name, description, config_json, created_at, updated_at)+ VALUES (?, ?, ?, ?, ?, ?)`,+ [+ config.id,+ config.name,+ config.description,+ configJson,+ config.metadata.createdAt,+ config.metadata.updatedAt,+ ]+ );console.log(`Mapping '${config.name}' saved successfully`);} catch (error) {@@ -130,13 +159,17 @@ export class MappingDatabase {await this.ensureInitialized();try {- const mappings = this.getMappingsFromStorage();- const config = mappings[id];+ const result = await sqliteService.select<{ config_json: string }>(+ 'SELECT config_json FROM data_mappings WHERE id = ?',+ [id]+ );- if (!config) {+ if (!result || result.length === 0) {return null;}+ const config = JSON.parse(result[0].config_json) as DataMappingConfig;+// Decrypt sensitive data if neededconst encryptionEnabled = await encryptionService.isEncryptionEnabled();if (encryptionEnabled && config.source.type === 'api' && config.source.apiConfig) {@@ -197,13 +230,24 @@ export class MappingDatabase {await this.ensureInitialized();try {- const mappings = this.getMappingsFromStorage();- const mappingArray = Object.values(mappings);+ const results = await sqliteService.select<{ config_json: string }>(+ 'SELECT config_json FROM data_mappings ORDER BY updated_at DESC'+ );- // Sort by updated_at DESC- return mappingArray.sort((a, b) =>- new Date(b.metadata.updatedAt).getTime() - new Date(a.metadata.updatedAt).getTime()+ if (!results || results.length === 0) {+ return [];+ }++ // Parse and decrypt all mappings+ const mappings = await Promise.all(+ results.map(async (row: { config_json: string }) => {+ const config = JSON.parse(row.config_json) as DataMappingConfig;+ // Note: We don't decrypt here for performance - decrypt on demand in getMapping()+ return config;+ }));++ return mappings;} catch (error) {console.error('Failed to get all mappings:', error);return [];@@ -217,13 +261,7 @@ export class MappingDatabase {await this.ensureInitialized();try {- const mappings = this.getMappingsFromStorage();- delete mappings[id];- localStorage.setItem(STORAGE_KEYS.MAPPINGS, JSON.stringify(mappings));-- // Also clear related cache- await this.clearCache(id);-+ await sqliteService.execute('DELETE FROM data_mappings WHERE id = ?', [id]);console.log(`Mapping ${id} deleted`);} catch (error) {console.error('Failed to delete mapping:', error);@@ -240,22 +278,19 @@ export class MappingDatabase {try {const paramsHash = this.hashParams(params);const cacheKey = `${mappingId}_${paramsHash}`;- const cache = this.getCacheFromStorage();- const entry = cache[cacheKey];- if (!entry) {- return null;- }+ const result = await sqliteService.select<{ response_json: string; expires_at: string }>(+ `SELECT response_json, expires_at FROM mapping_cache+ WHERE cache_key = ? AND expires_at > datetime('now')`,+ [cacheKey]+ );- // Check expiration- if (new Date(entry.expires_at) <= new Date()) {- delete cache[cacheKey];- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify(cache));+ if (!result || result.length === 0) {return null;}console.log(`Cache hit for mapping ${mappingId}`);- return JSON.parse(entry.response_json);+ return JSON.parse(result[0].response_json);} catch (error) {console.error('Failed to get cached response:', error);return null;@@ -280,17 +315,12 @@ export class MappingDatabase {const expiresAt = new Date(Date.now() + ttlSeconds * 1000).toISOString();const responseJson = JSON.stringify(response);- const cache = this.getCacheFromStorage();- cache[cacheKey] = {- cache_key: cacheKey,- mapping_id: mappingId,- params_hash: paramsHash,- response_json: responseJson,- cached_at: now,- expires_at: expiresAt,- };-- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify(cache));+ await sqliteService.execute(+ `INSERT OR REPLACE INTO mapping_cache (cache_key, mapping_id, params_hash, response_json, cached_at, expires_at)+ VALUES (?, ?, ?, ?, ?, ?)`,+ [cacheKey, mappingId, paramsHash, responseJson, now, expiresAt]+ );+console.log(`Response cached for mapping ${mappingId}`);} catch (error) {console.error('Failed to cache response:', error);@@ -305,18 +335,11 @@ export class MappingDatabase {await this.ensureInitialized();try {- const cache = this.getCacheFromStorage();-if (mappingId) {- // Clear cache for specific mapping- const filtered = Object.fromEntries(- Object.entries(cache).filter(([_, entry]) => entry.mapping_id !== mappingId)- );- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify(filtered));+ await sqliteService.execute('DELETE FROM mapping_cache WHERE mapping_id = ?', [mappingId]);console.log(`Cache cleared for mapping ${mappingId}`);} else {- // Clear all cache- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify({}));+ await sqliteService.execute('DELETE FROM mapping_cache');console.log('All cache cleared');}} catch (error) {@@ -332,14 +355,7 @@ export class MappingDatabase {await this.ensureInitialized();try {- const cache = this.getCacheFromStorage();- const now = new Date();-- const filtered = Object.fromEntries(- Object.entries(cache).filter(([_, entry]) => new Date(entry.expires_at) > now)- );-- localStorage.setItem(STORAGE_KEYS.CACHE, JSON.stringify(filtered));+ await sqliteService.execute("DELETE FROM mapping_cache WHERE expires_at < datetime('now')");console.log('Expired cache entries cleaned');} catch (error) {console.error('Failed to clean expired cache:', error);@@ -353,8 +369,12 @@ export class MappingDatabase {await this.ensureInitialized();try {- const prefs = this.getPreferencesFromStorage();- return prefs[key] || null;+ const result = await sqliteService.select<{ value: string }>(+ 'SELECT value FROM mapping_preferences WHERE key = ?',+ [key]+ );++ return result && result.length > 0 ? result[0].value : null;} catch (error) {console.error('Failed to get preference:', error);return null;@@ -365,9 +385,10 @@ export class MappingDatabase {await this.ensureInitialized();try {- const prefs = this.getPreferencesFromStorage();- prefs[key] = value;- localStorage.setItem(STORAGE_KEYS.PREFERENCES, JSON.stringify(prefs));+ await sqliteService.execute(+ 'INSERT OR REPLACE INTO mapping_preferences (key, value) VALUES (?, ?)',+ [key, value]+ );} catch (error) {console.error('Failed to set preference:', error);throw error;@@ -419,30 +440,6 @@ export class MappingDatabase {await this.initialize();}}-- /**- * Get mappings from localStorage- */- private getMappingsFromStorage(): Record<string, DataMappingConfig> {- const data = localStorage.getItem(STORAGE_KEYS.MAPPINGS);- return data ? JSON.parse(data) : {};- }-- /**- * Get cache from localStorage- */- private getCacheFromStorage(): Record<string, CacheEntry> {- const data = localStorage.getItem(STORAGE_KEYS.CACHE);- return data ? JSON.parse(data) : {};- }-- /**- * Get preferences from localStorage- */- private getPreferencesFromStorage(): Record<string, string> {- const data = localStorage.getItem(STORAGE_KEYS.PREFERENCES);- return data ? JSON.parse(data) : {};- }}// Export singleton instancediff --git a/fincept-terminal-desktop/test-positions.html b/fincept-terminal-desktop/test-positions.htmlnew file mode 100644index 000000000..b2aa8397a--- /dev/null+++ b/fincept-terminal-desktop/test-positions.html@@ -0,0 +1,75 @@+<!DOCTYPE html>+<html>+<head>+ <title>Test Paper Trading Positions</title>+</head>+<body>+ <h1>Paper Trading Positions Test</h1>+ <button onclick="testPositions()">Test Fetch Positions</button>+ <button onclick="testPortfolios()">Test List Portfolios</button>+ <button onclick="testOrders()">Test Fetch Orders</button>+ <pre id="output"></pre>++ <script>+ const { invoke } = window.__TAURI__.core;++ async function testPortfolios() {+ const output = document.getElementById('output');+ output.textContent = 'Fetching portfolios...\n';++ try {+ const portfolios = await invoke('db_list_portfolios');+ output.textContent += JSON.stringify(portfolios, null, 2);+ } catch (error) {+ output.textContent += 'ERROR: ' + error;+ }+ }++ async function testPositions() {+ const output = document.getElementById('output');+ output.textContent = 'Fetching positions...\n';++ try {+ // Try to get all portfolios first+ const portfolios = await invoke('db_list_portfolios');+ output.textContent += 'Found ' + portfolios.length + ' portfolios:\n';+ output.textContent += JSON.stringify(portfolios, null, 2) + '\n\n';++ // For each portfolio, get positions+ for (const portfolio of portfolios) {+ output.textContent += `\nFetching positions for portfolio: ${portfolio.id}\n`;+ const positions = await invoke('db_get_portfolio_positions', {+ portfolioId: portfolio.id,+ status: null+ });+ output.textContent += `Found ${positions.length} positions:\n`;+ output.textContent += JSON.stringify(positions, null, 2) + '\n';+ }+ } catch (error) {+ output.textContent += '\nERROR: ' + error;+ }+ }++ async function testOrders() {+ const output = document.getElementById('output');+ output.textContent = 'Fetching orders...\n';++ try {+ const portfolios = await invoke('db_list_portfolios');+ output.textContent += 'Found ' + portfolios.length + ' portfolios:\n';++ for (const portfolio of portfolios) {+ output.textContent += `\nFetching orders for portfolio: ${portfolio.id}\n`;+ const orders = await invoke('db_get_portfolio_orders', {+ portfolioId: portfolio.id+ });+ output.textContent += `Found ${orders.length} orders:\n`;+ output.textContent += JSON.stringify(orders, null, 2) + '\n';+ }+ } catch (error) {+ output.textContent += '\nERROR: ' + error;+ }+ }+ </script>+</body>+</html>