mammon market history
This commit is contained in:
@@ -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);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EsiMarketOrderHistory } from "@/market";
|
import { MarketHistory } from "@/market";
|
||||||
|
|
||||||
export type HistoryQuartils = {
|
export type HistoryQuartils = {
|
||||||
totalVolume: number,
|
totalVolume: number,
|
||||||
@@ -7,7 +7,7 @@ export type HistoryQuartils = {
|
|||||||
q3: number,
|
q3: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getHistoryQuartils = (history: EsiMarketOrderHistory[], days?: number): HistoryQuartils => {
|
export const getHistoryQuartils = (history: MarketHistory[], days?: number): HistoryQuartils => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const volumes = history
|
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) {
|
if (history.volume === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,2 +1,2 @@
|
|||||||
export * from './EsiMarketOrderHistory';
|
export * from './MarketHistory';
|
||||||
export * from './HistoryQuartils';
|
export * from './HistoryQuartils';
|
||||||
|
|||||||
Reference in New Issue
Block a user