oilpriceapi 0.5.3 → 0.6.0
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 +22 -0
- package/dist/client.js +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +30 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,25 @@ const prices = await client.getHistoricalPrices({
|
|
|
99
99
|
console.log(`Got ${prices.length} data points for 2024`);
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
### Performance Optimization (New in v0.6.0)
|
|
103
|
+
|
|
104
|
+
For year-long queries, use the `interval` parameter to dramatically improve response times:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// FAST: Daily aggregation returns 365 data points (~1 second)
|
|
108
|
+
const yearlyPrices = await client.getHistoricalPrices({
|
|
109
|
+
period: 'past_year',
|
|
110
|
+
commodity: 'BRENT_CRUDE_USD',
|
|
111
|
+
interval: 'daily' // Options: 'raw', 'hourly', 'daily', 'weekly', 'monthly'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log(`Got ${yearlyPrices.length} daily averages`);
|
|
115
|
+
// Output: Got 365 daily averages
|
|
116
|
+
|
|
117
|
+
// SLOW: Raw data returns 600k+ points (can take 74+ seconds)
|
|
118
|
+
// Only use 'raw' when you need every individual price point
|
|
119
|
+
```
|
|
120
|
+
|
|
102
121
|
### Get Diesel Prices (New in v0.4.0)
|
|
103
122
|
|
|
104
123
|
#### Get State Average Diesel Price
|
|
@@ -454,6 +473,9 @@ Get historical prices for a time period.
|
|
|
454
473
|
- `options.commodity` (string, optional) - Filter by commodity code
|
|
455
474
|
- `options.startDate` (string, optional) - Start date in ISO 8601 format (YYYY-MM-DD)
|
|
456
475
|
- `options.endDate` (string, optional) - End date in ISO 8601 format (YYYY-MM-DD)
|
|
476
|
+
- `options.interval` (string, optional) - Aggregation interval: "raw", "hourly", "daily", "weekly", "monthly". **Performance tip:** Use "daily" for year-long queries (365 points vs 600k+ raw points)
|
|
477
|
+
- `options.perPage` (number, optional) - Results per page (default: 100, max: 1000)
|
|
478
|
+
- `options.page` (number, optional) - Page number for pagination (default: 1)
|
|
457
479
|
|
|
458
480
|
**Returns:** `Promise<Price[]>`
|
|
459
481
|
|
package/dist/client.js
CHANGED
|
@@ -294,6 +294,20 @@ export class OilPriceAPI {
|
|
|
294
294
|
if (options?.endDate) {
|
|
295
295
|
params.end_date = options.endDate;
|
|
296
296
|
}
|
|
297
|
+
// PERFORMANCE FIX (December 24, 2025):
|
|
298
|
+
// Pass interval parameter to enable aggregated queries
|
|
299
|
+
// This reduces response times from 74s to <1s for year-long queries
|
|
300
|
+
// by returning 365 daily points instead of 600k+ raw points
|
|
301
|
+
if (options?.interval) {
|
|
302
|
+
params.interval = options.interval;
|
|
303
|
+
}
|
|
304
|
+
// Pagination parameters
|
|
305
|
+
if (options?.perPage !== undefined) {
|
|
306
|
+
params.per_page = options.perPage.toString();
|
|
307
|
+
}
|
|
308
|
+
if (options?.page !== undefined) {
|
|
309
|
+
params.page = options.page.toString();
|
|
310
|
+
}
|
|
297
311
|
// CRITICAL FIX (December 17, 2025):
|
|
298
312
|
// Use /v1/prices/past_year endpoint instead of /v1/prices
|
|
299
313
|
// The /v1/prices endpoint does NOT correctly handle start_date/end_date parameters
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { OilPriceAPI } from './client.js';
|
|
9
9
|
export { SDK_VERSION, SDK_NAME } from './version.js';
|
|
10
|
-
export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, } from './types.js';
|
|
10
|
+
export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, AggregationInterval, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, } from './types.js';
|
|
11
11
|
export type { DieselPrice, DieselStation, DieselStationsResponse, GetDieselStationsOptions, } from './resources/diesel.js';
|
|
12
12
|
export type { PriceAlert, CreateAlertParams, UpdateAlertParams, AlertOperator, WebhookTestResponse, } from './resources/alerts.js';
|
|
13
13
|
export { OilPriceAPIError, AuthenticationError, RateLimitError, NotFoundError, ServerError, TimeoutError, } from './errors.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -120,6 +120,14 @@ export interface LatestPricesOptions {
|
|
|
120
120
|
* Time period options for historical data
|
|
121
121
|
*/
|
|
122
122
|
export type HistoricalPeriod = 'past_week' | 'past_month' | 'past_year';
|
|
123
|
+
/**
|
|
124
|
+
* Aggregation interval for historical data
|
|
125
|
+
*
|
|
126
|
+
* PERFORMANCE TIP: Use 'daily' or 'weekly' for year-long queries to reduce
|
|
127
|
+
* response times from 74s to <1s. The 'raw' option returns individual price
|
|
128
|
+
* points which can be 600k+ records for a year of BRENT data.
|
|
129
|
+
*/
|
|
130
|
+
export type AggregationInterval = 'raw' | 'hourly' | 'daily' | 'weekly' | 'monthly';
|
|
123
131
|
/**
|
|
124
132
|
* Options for fetching historical prices
|
|
125
133
|
*/
|
|
@@ -142,6 +150,28 @@ export interface HistoricalPricesOptions {
|
|
|
142
150
|
* Example: "2024-12-31"
|
|
143
151
|
*/
|
|
144
152
|
endDate?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Aggregation interval for the data
|
|
155
|
+
*
|
|
156
|
+
* PERFORMANCE: For year-long queries, use 'daily' (365 points) or 'weekly' (52 points)
|
|
157
|
+
* instead of 'raw' (600k+ points for BRENT) to dramatically improve response times.
|
|
158
|
+
*
|
|
159
|
+
* @default API default (raw for short periods, may be aggregated for long periods)
|
|
160
|
+
*/
|
|
161
|
+
interval?: AggregationInterval;
|
|
162
|
+
/**
|
|
163
|
+
* Number of results per page
|
|
164
|
+
*
|
|
165
|
+
* @default 100 (API default)
|
|
166
|
+
* @max 1000
|
|
167
|
+
*/
|
|
168
|
+
perPage?: number;
|
|
169
|
+
/**
|
|
170
|
+
* Page number for pagination (1-indexed)
|
|
171
|
+
*
|
|
172
|
+
* @default 1
|
|
173
|
+
*/
|
|
174
|
+
page?: number;
|
|
145
175
|
}
|
|
146
176
|
/**
|
|
147
177
|
* Represents commodity metadata
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED