extract evepraisal from apraisal

This commit is contained in:
2023-11-16 09:54:23 +01:00
parent f115381955
commit 98ce81dfb2
7 changed files with 43 additions and 30 deletions
+21
View File
@@ -0,0 +1,21 @@
import { evepraisalAxiosInstance } from '@/service';
import { MarketType } from "../type";
import { MarketTypePrice, PriceGetter } from './MarketTypePrice';
const batchSize = 100;
export const getEvepraisalPrices: PriceGetter = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
const batches = [];
for (let i = 0; i < types.length; i += batchSize) {
batches.push(evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.slice(i, i + batchSize).map(t => t.name).join("%0A")}`));
}
return (await Promise.all(batches))
.flatMap(b => b.data.appraisal.items)
.map((item: any) => ({
type: types.find(t => t.name === item.typeName) as MarketType,
buy: item.prices.buy.max,
sell: item.prices.sell.min,
orderCount: item.prices.all.order_count
}));
};