scan front
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { getHistory, getHistoryQuartils, HistoryQuartils, MarketType, MarketTypePrice } from "@/market";
|
||||
import { MarketScanResponse } from "@/generated/mammon";
|
||||
|
||||
export type ScanResult = {
|
||||
type: MarketType;
|
||||
buy: number;
|
||||
sell: number;
|
||||
q1: number;
|
||||
median: number;
|
||||
q3: number;
|
||||
totalVolume: number;
|
||||
profit: number;
|
||||
score: number;
|
||||
}
|
||||
|
||||
// Mirrors mammon's MarketScoreCalculator so the client-side path matches the backend scan.
|
||||
export const calculateScore = (quartils: HistoryQuartils, profit: number, orderCount: number, days: number): number => {
|
||||
if (profit <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.sqrt((Math.pow(quartils.totalVolume, 1.1) * Math.pow(quartils.q1, 1.2) * Math.pow(profit, 0.5) * Math.pow(Math.max(1, orderCount), -0.7)) / days);
|
||||
}
|
||||
|
||||
export const toScanResult = (res: MarketScanResponse, type: MarketType, price: MarketTypePrice): ScanResult => ({
|
||||
type,
|
||||
buy: price.buy,
|
||||
sell: price.sell,
|
||||
q1: res.q1,
|
||||
median: res.median,
|
||||
q3: res.q3,
|
||||
totalVolume: res.totalVolume,
|
||||
profit: res.profit,
|
||||
score: res.score,
|
||||
});
|
||||
|
||||
// Client-side scan result for a single type (used where the scan endpoint can't be queried per-type).
|
||||
export const buildScanResult = async (price: MarketTypePrice, days: number, calculateProfit: (buy: number, sell: number) => number): Promise<ScanResult> => {
|
||||
const history = await getHistory(price.type.id);
|
||||
const quartils = getHistoryQuartils(history, days);
|
||||
const profit = quartils.q1 === 0 || quartils.q3 === 0 ? 0 : calculateProfit(quartils.q1, quartils.q3);
|
||||
|
||||
return {
|
||||
type: price.type,
|
||||
buy: price.buy,
|
||||
sell: price.sell,
|
||||
q1: quartils.q1,
|
||||
median: quartils.median,
|
||||
q3: quartils.q3,
|
||||
totalVolume: quartils.totalVolume,
|
||||
profit,
|
||||
score: calculateScore(quartils, profit, price.orderCount, days),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user