mammon market history

This commit is contained in:
Sirttas
2026-06-11 20:46:40 +02:00
parent 3981475c55
commit 2ab3f01d89
4 changed files with 11 additions and 34 deletions
@@ -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<EsiMarketOrderHistory[]> = 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<EsiMarketOrderHistory[]> => {
const rId = regionId ?? jitaId;
return historyCache.computeIfAbsent(rId, typeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: typeId } })).data);
}
+3 -3
View File
@@ -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;
}
+7
View File
@@ -0,0 +1,7 @@
import { MarketHistoryResponse } from "@/generated/mammon";
import { marketApi } from "@/mammon";
export type MarketHistory = MarketHistoryResponse;
export const getHistory = async (typeId: number): Promise<MarketHistory[]> =>
(await marketApi.findHistory(typeId)).data;
+1 -1
View File
@@ -1,2 +1,2 @@
export * from './EsiMarketOrderHistory';
export * from './MarketHistory';
export * from './HistoryQuartils';