Initial commit of integrated agent system
This commit is contained in:
55
frontend/src/services/tradingApi.js
Normal file
55
frontend/src/services/tradingApi.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const trimTrailingSlash = (value) => value.replace(/\/+$/, '');
|
||||
const isLocalDevHost = () => {
|
||||
if (typeof window === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
const host = String(window.location.hostname || '').trim().toLowerCase();
|
||||
return host === 'localhost' || host === '127.0.0.1';
|
||||
};
|
||||
|
||||
const TRADING_SERVICE_BASE = trimTrailingSlash(import.meta.env.VITE_TRADING_SERVICE_URL || '') || (
|
||||
isLocalDevHost() ? 'http://localhost:8001' : ''
|
||||
);
|
||||
|
||||
export function hasDirectTradingService() {
|
||||
return Boolean(TRADING_SERVICE_BASE);
|
||||
}
|
||||
|
||||
export async function fetchInsiderTradesDirect(ticker, startDate = null, endDate = null, limit = 50) {
|
||||
if (!TRADING_SERVICE_BASE) {
|
||||
throw new Error('Direct trading service is not configured');
|
||||
}
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.set('ticker', ticker);
|
||||
params.set('limit', String(limit));
|
||||
if (startDate) {
|
||||
params.set('start_date', startDate);
|
||||
}
|
||||
if (endDate) {
|
||||
params.set('end_date', endDate);
|
||||
}
|
||||
|
||||
const response = await fetch(`${TRADING_SERVICE_BASE}/api/insider-trades?${params.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function fetchStockHistoryDirect(ticker, startDate, endDate) {
|
||||
if (!TRADING_SERVICE_BASE) {
|
||||
throw new Error('Direct trading service is not configured');
|
||||
}
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.set('ticker', ticker);
|
||||
params.set('start_date', startDate);
|
||||
params.set('end_date', endDate);
|
||||
|
||||
const response = await fetch(`${TRADING_SERVICE_BASE}/api/prices?${params.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
Reference in New Issue
Block a user