diff --git a/src/market/history/EsiMarketOrderHistory.ts b/src/market/history/EsiMarketOrderHistory.ts deleted file mode 100644 index 821e8ef..0000000 --- a/src/market/history/EsiMarketOrderHistory.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { esiAxiosInstance } from "@/service"; -import { RegionalMarketCache } from '../RegionalMarketCache'; -import { jitaId } from "../market"; - - -export type EsiMarketOrderHistory = { - average: number; - date: string; - highest: number; - lowest: number; - order_count: number; - volume: number; -} - -// TODO use pinia store -const historyCache: RegionalMarketCache = new RegionalMarketCache(() => { - const date = new Date(); - - if (date.getUTCHours() >= 11) { - date.setUTCDate(date.getUTCDate() + 1); - } - date.setUTCHours(11, 0, 0, 0); - return date; -}); - -export const getHistory = async (typeId: number, regionId?: number): Promise => { - const rId = regionId ?? jitaId; - - return historyCache.computeIfAbsent(rId, typeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: typeId } })).data); -} diff --git a/src/market/history/HistoryQuartils.ts b/src/market/history/HistoryQuartils.ts index d1cfcd9..c144245 100644 --- a/src/market/history/HistoryQuartils.ts +++ b/src/market/history/HistoryQuartils.ts @@ -1,4 +1,4 @@ -import { EsiMarketOrderHistory } from "@/market"; +import { MarketHistory } from "@/market"; export type HistoryQuartils = { totalVolume: number, @@ -7,7 +7,7 @@ export type HistoryQuartils = { q3: number, } -export const getHistoryQuartils = (history: EsiMarketOrderHistory[], days?: number): HistoryQuartils => { +export const getHistoryQuartils = (history: MarketHistory[], days?: number): HistoryQuartils => { const now = Date.now(); const volumes = history @@ -51,7 +51,7 @@ export const getHistoryQuartils = (history: EsiMarketOrderHistory[], days?: numb }; } -const estimateVolume = (history: EsiMarketOrderHistory): number => { +const estimateVolume = (history: MarketHistory): number => { if (history.volume === 0) { return 0; } diff --git a/src/market/history/MarketHistory.ts b/src/market/history/MarketHistory.ts new file mode 100644 index 0000000..588fcd5 --- /dev/null +++ b/src/market/history/MarketHistory.ts @@ -0,0 +1,7 @@ +import { MarketHistoryResponse } from "@/generated/mammon"; +import { marketApi } from "@/mammon"; + +export type MarketHistory = MarketHistoryResponse; + +export const getHistory = async (typeId: number): Promise => + (await marketApi.findHistory(typeId)).data; \ No newline at end of file diff --git a/src/market/history/index.ts b/src/market/history/index.ts index c035bba..1fc7a88 100644 --- a/src/market/history/index.ts +++ b/src/market/history/index.ts @@ -1,2 +1,2 @@ -export * from './EsiMarketOrderHistory'; +export * from './MarketHistory'; export * from './HistoryQuartils';