borsa / nextjs-app /src /lib /api-client.ts
veteroner's picture
feat: live position monitoring with charts + trading system production ready
656ac31
/**
* Hugging Face ML API Client
* Python FastAPI Backend ile iletişim kurar
*/
import { API_BASE } from '@/lib/runtime-config';
import { fetchJson } from '@/lib/http';
class ApiClient {
/**
* Hisse senedi verilerini getir
*/
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;
}
}
/**
* ML tahminlerini getir
*/
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;
}
}
/**
* Teknik analiz getir
*/
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;
}
}
/**
* Piyasa özetini getir
*/
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;