| |
| |
| |
| |
|
|
| import { API_BASE } from '@/lib/runtime-config'; |
| import { fetchJson } from '@/lib/http'; |
|
|
| class ApiClient { |
| |
| |
| |
| async getStockData(symbol: string, period = '1y', interval = '1d') { |
| const url = `${API_BASE}/api/stock-data?symbol=${symbol}&period=${period}&interval=${interval}`; |
| |
| try { |
| return await fetchJson<Record<string, unknown>>(url, { method: 'GET' }, { timeoutMs: 45000, retries: 2 }); |
| } catch (error) { |
| console.error('getStockData error:', error); |
| throw error; |
| } |
| } |
|
|
| |
| |
| |
| async getMLPredictions(symbols: string[], daysAhead = 5, model = 'ensemble') { |
| const url = `${API_BASE}/api/ml-predictions`; |
| |
| try { |
| return await fetchJson<Record<string, unknown>>( |
| url, |
| { method: 'POST' }, |
| { timeoutMs: 30000, retries: 0, jsonBody: { symbols, days_ahead: daysAhead, model } } |
| ); |
| } catch (error) { |
| console.error('getMLPredictions error:', error); |
| throw error; |
| } |
| } |
|
|
| |
| |
| |
| async getTechnicalAnalysis(symbol: string) { |
| const url = `${API_BASE}/api/technical-analysis?symbol=${symbol}`; |
| |
| try { |
| return await fetchJson<Record<string, unknown>>(url, { method: 'GET' }, { timeoutMs: 45000, retries: 2 }); |
| } catch (error) { |
| console.error('getTechnicalAnalysis error:', error); |
| throw error; |
| } |
| } |
|
|
| |
| |
| |
| async getMarketOverview() { |
| const url = `${API_BASE}/api/market-overview`; |
| |
| try { |
| return await fetchJson<Record<string, unknown>>(url, { method: 'GET' }, { timeoutMs: 45000, retries: 2 }); |
| } catch (error) { |
| console.error('getMarketOverview error:', error); |
| throw error; |
| } |
| } |
| } |
|
|
| export const apiClient = new ApiClient(); |
| export default apiClient; |
|
|