warframe-nexus-query 2.3.10 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -5
- package/dist/basedir.d.mts +3 -0
- package/dist/basedir.mjs +7 -0
- package/dist/index.d.mts +868 -0
- package/dist/index.mjs +1778 -0
- package/package.json +31 -17
- package/basedir.js +0 -4
- package/index.js +0 -172
- package/lib/AttachmentCreator.js +0 -198
- package/lib/Settings.js +0 -53
- package/lib/market/v2/MarketFetcherV2.js +0 -447
- package/lib/market/v2/constants.js +0 -60
- package/lib/market/v2/index.js +0 -12
- package/lib/market/v2/models/Item.js +0 -135
- package/lib/market/v2/models/Order.js +0 -197
- package/lib/market/v2/models/Summary.js +0 -165
- package/lib/market/v2/types.d.ts +0 -137
- package/lib/market/v2/utils/cache.js +0 -291
- package/lib/market/v2/utils/http.js +0 -246
- package/lib/market/v2/utils/i18n.js +0 -40
- package/lib/market/v2/utils/statistics.js +0 -185
- package/lib/priceCheckOptions.js +0 -71
- package/lib/promiseTimeout.js +0 -19
- package/types/index.d.ts +0 -522
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Statistics calculator for order data
|
|
3
|
-
* Replaces v1's pre-calculated statistics with client-side calculation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Calculate statistics from order list
|
|
8
|
-
* @param {Array<Order>} orders - Array of orders
|
|
9
|
-
* @param {Object} options - Calculation options
|
|
10
|
-
* @param {string} [options.type='sell'] - Order type ('buy' or 'sell')
|
|
11
|
-
* @param {boolean} [options.onlineOnly=true] - Only include online users
|
|
12
|
-
* @param {boolean} [options.includeOutliers=true] - Include price outliers
|
|
13
|
-
* @returns {Object} Statistics object
|
|
14
|
-
*/
|
|
15
|
-
export function calculateStatistics(orders, options = {}) {
|
|
16
|
-
const { type = 'sell', onlineOnly = true, includeOutliers = true } = options;
|
|
17
|
-
|
|
18
|
-
// Filter orders
|
|
19
|
-
let filtered = orders.filter((o) => o.type === type);
|
|
20
|
-
|
|
21
|
-
// Filter online users only
|
|
22
|
-
if (onlineOnly) {
|
|
23
|
-
filtered = filtered.filter((o) => o.isUserOnline());
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Extract prices
|
|
27
|
-
let prices = filtered.map((o) => o.platinum).sort((a, b) => a - b);
|
|
28
|
-
|
|
29
|
-
// Remove outliers if requested (using IQR method)
|
|
30
|
-
if (!includeOutliers && prices.length > 4) {
|
|
31
|
-
prices = removeOutliers(prices);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// If no prices, return empty stats
|
|
35
|
-
if (prices.length === 0) {
|
|
36
|
-
return {
|
|
37
|
-
volume: 0,
|
|
38
|
-
orderCount: 0,
|
|
39
|
-
median: 0,
|
|
40
|
-
min: 0,
|
|
41
|
-
max: 0,
|
|
42
|
-
avg: 0,
|
|
43
|
-
q1: 0,
|
|
44
|
-
q3: 0,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Calculate volume
|
|
49
|
-
const volume = filtered.reduce((sum, o) => sum + o.quantity, 0);
|
|
50
|
-
|
|
51
|
-
// Calculate statistics
|
|
52
|
-
const median = calculateMedian(prices);
|
|
53
|
-
const min = prices[0];
|
|
54
|
-
const max = prices[prices.length - 1];
|
|
55
|
-
const avg = prices.reduce((a, b) => a + b, 0) / prices.length;
|
|
56
|
-
const q1 = calculatePercentile(prices, 25);
|
|
57
|
-
const q3 = calculatePercentile(prices, 75);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
volume,
|
|
61
|
-
orderCount: filtered.length,
|
|
62
|
-
median: Math.round(median),
|
|
63
|
-
min,
|
|
64
|
-
max,
|
|
65
|
-
avg: Math.round(avg),
|
|
66
|
-
q1: Math.round(q1),
|
|
67
|
-
q3: Math.round(q3),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Calculate median of sorted array
|
|
73
|
-
* @param {number[]} sortedPrices - Sorted price array
|
|
74
|
-
* @returns {number}
|
|
75
|
-
*/
|
|
76
|
-
function calculateMedian(sortedPrices) {
|
|
77
|
-
const len = sortedPrices.length;
|
|
78
|
-
if (len === 0) return 0;
|
|
79
|
-
if (len === 1) return sortedPrices[0];
|
|
80
|
-
|
|
81
|
-
const mid = Math.floor(len / 2);
|
|
82
|
-
if (len % 2 === 0) {
|
|
83
|
-
return (sortedPrices[mid - 1] + sortedPrices[mid]) / 2;
|
|
84
|
-
}
|
|
85
|
-
return sortedPrices[mid];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Calculate percentile of sorted array
|
|
90
|
-
* @param {number[]} sortedPrices - Sorted price array
|
|
91
|
-
* @param {number} percentile - Percentile (0-100)
|
|
92
|
-
* @returns {number}
|
|
93
|
-
*/
|
|
94
|
-
function calculatePercentile(sortedPrices, percentile) {
|
|
95
|
-
if (sortedPrices.length === 0) return 0;
|
|
96
|
-
if (sortedPrices.length === 1) return sortedPrices[0];
|
|
97
|
-
|
|
98
|
-
const index = (percentile / 100) * (sortedPrices.length - 1);
|
|
99
|
-
const lower = Math.floor(index);
|
|
100
|
-
const upper = Math.ceil(index);
|
|
101
|
-
const weight = index - lower;
|
|
102
|
-
|
|
103
|
-
return sortedPrices[lower] * (1 - weight) + sortedPrices[upper] * weight;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Remove outliers using IQR method
|
|
108
|
-
* @param {number[]} sortedPrices - Sorted price array
|
|
109
|
-
* @returns {number[]}
|
|
110
|
-
*/
|
|
111
|
-
function removeOutliers(sortedPrices) {
|
|
112
|
-
const q1 = calculatePercentile(sortedPrices, 25);
|
|
113
|
-
const q3 = calculatePercentile(sortedPrices, 75);
|
|
114
|
-
const iqr = q3 - q1;
|
|
115
|
-
const lowerBound = q1 - 1.5 * iqr;
|
|
116
|
-
const upperBound = q3 + 1.5 * iqr;
|
|
117
|
-
|
|
118
|
-
return sortedPrices.filter((price) => price >= lowerBound && price <= upperBound);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Get best orders (lowest sell / highest buy)
|
|
123
|
-
* @param {Array<Order>} orders - Array of orders
|
|
124
|
-
* @param {Object} options - Options
|
|
125
|
-
* @param {number} [options.limit=5] - Number of orders to return
|
|
126
|
-
* @param {boolean} [options.onlineOnly=true] - Only online users
|
|
127
|
-
* @returns {Object} { buy: Order[], sell: Order[] }
|
|
128
|
-
*/
|
|
129
|
-
export function getBestOrders(orders, options = {}) {
|
|
130
|
-
const { limit = 5, onlineOnly = true } = options;
|
|
131
|
-
|
|
132
|
-
// Filter online if requested
|
|
133
|
-
let filtered = orders;
|
|
134
|
-
if (onlineOnly) {
|
|
135
|
-
filtered = orders.filter((o) => o.isUserOnline());
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Separate buy and sell orders
|
|
139
|
-
const buyOrders = filtered.filter((o) => o.isBuyOrder()).sort((a, b) => b.platinum - a.platinum);
|
|
140
|
-
|
|
141
|
-
const sellOrders = filtered.filter((o) => o.isSellOrder()).sort((a, b) => a.platinum - b.platinum);
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
buy: buyOrders.slice(0, limit),
|
|
145
|
-
sell: sellOrders.slice(0, limit),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Format price range string
|
|
151
|
-
* @param {Object} stats - Statistics object
|
|
152
|
-
* @returns {string}
|
|
153
|
-
*/
|
|
154
|
-
export function formatPriceRange(stats) {
|
|
155
|
-
if (stats.orderCount === 0) {
|
|
156
|
-
return 'No orders found';
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (stats.min === stats.max) {
|
|
160
|
-
return `${stats.min}p`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return `${stats.min}p - ${stats.max}p (median: ${stats.median}p)`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Format statistics for display
|
|
168
|
-
* @param {Object} stats - Statistics object
|
|
169
|
-
* @param {string} type - Order type ('buy' or 'sell')
|
|
170
|
-
* @returns {string}
|
|
171
|
-
*/
|
|
172
|
-
export function formatStatistics(stats, type = 'sell') {
|
|
173
|
-
const action = type === 'sell' ? 'Sellers' : 'Buyers';
|
|
174
|
-
|
|
175
|
-
if (stats.orderCount === 0) {
|
|
176
|
-
return `No ${action.toLowerCase()} found`;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return [
|
|
180
|
-
`**${action}:** ${stats.orderCount} orders (${stats.volume} items)`,
|
|
181
|
-
`**Median:** ${stats.median}p`,
|
|
182
|
-
`**Range:** ${stats.min}p - ${stats.max}p`,
|
|
183
|
-
`**Average:** ${stats.avg}p`,
|
|
184
|
-
].join('\n');
|
|
185
|
-
}
|
package/lib/priceCheckOptions.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export const ORDER_FILTER_KEYS = [
|
|
2
|
-
'rank',
|
|
3
|
-
'rankLt',
|
|
4
|
-
'charges',
|
|
5
|
-
'chargesLt',
|
|
6
|
-
'amberStars',
|
|
7
|
-
'amberStarsLt',
|
|
8
|
-
'cyanStars',
|
|
9
|
-
'cyanStarsLt',
|
|
10
|
-
'subtype',
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {unknown} value - Rank value from query options
|
|
15
|
-
* @returns {number|undefined}
|
|
16
|
-
*/
|
|
17
|
-
export function parseRankValue(value) {
|
|
18
|
-
if (value === undefined || value === '') return undefined;
|
|
19
|
-
const rank = Number(value);
|
|
20
|
-
if (!Number.isInteger(rank) || rank < 0) return undefined;
|
|
21
|
-
return rank;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Resolve which mod ranks to price-check. `[undefined]` means no rank filter.
|
|
26
|
-
* @param {Record<string, unknown>} [options={}] - Price check options
|
|
27
|
-
* @returns {Array<number|undefined>}
|
|
28
|
-
*/
|
|
29
|
-
export function normalizePriceCheckRanks(options = {}) {
|
|
30
|
-
if (Array.isArray(options.ranks) && options.ranks.length) {
|
|
31
|
-
const parsed = options.ranks.map(parseRankValue).filter((rank) => rank !== undefined);
|
|
32
|
-
if (parsed.length) {
|
|
33
|
-
return [...new Set(parsed)].sort((a, b) => a - b);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const single = parseRankValue(options.rank);
|
|
38
|
-
if (single !== undefined) return [single];
|
|
39
|
-
|
|
40
|
-
return [undefined];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {Record<string, unknown>} [options={}] - Price check options
|
|
45
|
-
* @returns {Record<string, unknown>}
|
|
46
|
-
*/
|
|
47
|
-
export function extractOrderFilters(options = {}) {
|
|
48
|
-
/** @type {Record<string, unknown>} */
|
|
49
|
-
const filters = {};
|
|
50
|
-
|
|
51
|
-
ORDER_FILTER_KEYS.forEach((key) => {
|
|
52
|
-
if (options[key] !== undefined) filters[key] = options[key];
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return filters;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {{ name: string }} summary - Market summary to label
|
|
60
|
-
* @param {Record<string, unknown>} filters - Active order filters
|
|
61
|
-
* @returns {{ name: string }}
|
|
62
|
-
*/
|
|
63
|
-
export function labelSummaryForFilters(summary, filters) {
|
|
64
|
-
if (filters.rank !== undefined) {
|
|
65
|
-
summary.name = `${summary.name} (R${filters.rank})`;
|
|
66
|
-
} else if (filters.rankLt !== undefined) {
|
|
67
|
-
summary.name = `${summary.name} (<R${filters.rankLt})`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return summary;
|
|
71
|
-
}
|
package/lib/promiseTimeout.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copied from https://italonascimento.github.io/applying-a-timeout-to-your-promises
|
|
3
|
-
* Apply a timeout to your promise
|
|
4
|
-
* @param {number} ms Milliseconds to time out after
|
|
5
|
-
* @param {Promise} promise Promise to time out
|
|
6
|
-
* @returns {Promise} Pending promise that works or rejects with an error
|
|
7
|
-
*/
|
|
8
|
-
export default (ms, promise) => {
|
|
9
|
-
// Create a promise that rejects in <ms> milliseconds
|
|
10
|
-
const timeout = new Promise((resolve, reject) => {
|
|
11
|
-
const id = setTimeout(() => {
|
|
12
|
-
clearTimeout(id);
|
|
13
|
-
reject(new Error(`Timed out in ${ms}ms.`));
|
|
14
|
-
}, ms);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Returns a race between our timeout and the passed in promise
|
|
18
|
-
return Promise.race([promise, timeout]);
|
|
19
|
-
};
|