fuzzwork
This commit is contained in:
36
src/market/appraisal/fuzzwork.ts
Normal file
36
src/market/appraisal/fuzzwork.ts
Normal 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)
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user