This commit is contained in:
2023-11-16 11:26:17 +01:00
parent 98ce81dfb2
commit a1bffa1cdb
8 changed files with 73 additions and 17 deletions

View File

@@ -0,0 +1,36 @@
import { logResource } from '@/service';
import axios from 'axios';
import { MarketType } from "../type";
import { PriceGetter } from './MarketTypePrice';
export const fuzzworkAxiosInstance = axios.create({
baseURL: '/fuzzwork/',
headers: {
'accept': 'application/json',
"Content-Type": "application/json"
},
})
logResource(fuzzworkAxiosInstance)
const batchSize = 100;
export const getfuzzworkPrices: PriceGetter = async types => {
const batches = [];
for (let i = 0; i < types.length; i += batchSize) {
batches.push(fuzzworkAxiosInstance.post(`/aggregates/?station=60003760&types=${types.slice(i, i + batchSize).map(t => t.id).join(",")}`));
}
return (await Promise.all(batches))
.flatMap(b => Object.entries(b.data))
.map(entry => {
const id = parseInt(entry[0]);
const prices = entry[1] as any;
return {
type: types.find(t => t.id === id) as MarketType,
buy: parseFloat(prices.buy.max),
sell: parseFloat(prices.sell.min),
orderCount: parseInt(prices.buy.order_count) + parseInt(prices.sell.order_count)
}
});
};