initial commit

This commit is contained in:
Jose Selesan
2026-05-28 14:33:16 -03:00
commit 7bc3d9f898
211 changed files with 161253 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
export type Quote = {
id: number;
timeStamp: string;
buy: string;
sell: string;
type: "BELO" | "BLUE" | "BNA";
difference: string;
percentage: string;
previousDayDifference: string;
previousDayPercentage: string;
};
export type FetchResult = {
type: string;
status: string;
error?: string;
};
export type HistoryQuote = {
id: number;
timeStamp: string;
buy: string;
sell: string;
type: "BELO" | "BLUE" | "BNA";
};
export type DailyMinMax = {
date: string;
minBuy: number;
maxBuy: number;
minSell: number;
maxSell: number;
};
export type DailyQuote = {
date: string;
buy: number;
sell: number;
};
async function fetcher<T>(url: string): Promise<T> {
const res = await fetch(url);
if (!res.ok) {
throw new Error(`API error: ${res.status} ${res.statusText}`);
}
return res.json();
}
export function getQuotes(): Promise<Quote[]> {
return fetcher<Quote[]>("/api/quotes");
}
export function fetchQuotes(): Promise<FetchResult[]> {
return fetcher<FetchResult[]>("/api/quotes/fetch");
}
export function getQuoteHistory(
type: string,
startDate: string,
endDate: string,
): Promise<HistoryQuote[]> {
const params = new URLSearchParams({ startDate, endDate });
return fetcher<HistoryQuote[]>(`/api/quotes/${type}/history?${params}`);
}
export function getDailyMinMax(
type: string,
startDate: string,
endDate: string,
): Promise<DailyMinMax[]> {
const params = new URLSearchParams({ startDate, endDate });
return fetcher<DailyMinMax[]>(`/api/quotes/${type}/min-max?${params}`);
}
export function getDailyQuotes(
type: string,
startDate: string,
endDate: string,
): Promise<DailyQuote[]> {
const params = new URLSearchParams({ startDate, endDate });
return fetcher<DailyQuote[]>(`/api/quotes/${type}/daily?${params}`);
}