call mammon for single scan

This commit is contained in:
Sirttas
2026-06-13 12:31:01 +02:00
parent 3348b9f668
commit cc3bdccd9a
4 changed files with 453 additions and 128 deletions
+1 -28
View File
@@ -1,4 +1,4 @@
import { getHistory, getHistoryQuartils, HistoryQuartils, MarketType, MarketTypePrice } from "@/market";
import { MarketType } from "@/market";
import { MarketScanResponse } from "@/generated/mammon";
export type ScanResult = {
@@ -13,14 +13,6 @@ export type ScanResult = {
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): ScanResult => ({
type,
buy: res.buy,
@@ -32,22 +24,3 @@ export const toScanResult = (res: MarketScanResponse, type: MarketType): ScanRes
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),
};
}