oilpriceapi 0.6.0 → 0.7.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 +376 -113
- package/dist/client.d.ts +83 -3
- package/dist/client.js +104 -38
- package/dist/index.d.ts +31 -6
- package/dist/index.js +17 -3
- package/dist/resources/alerts.d.ts +52 -15
- package/dist/resources/alerts.js +143 -85
- package/dist/resources/analytics.d.ts +325 -0
- package/dist/resources/analytics.js +221 -0
- package/dist/resources/bunker-fuels.d.ts +270 -0
- package/dist/resources/bunker-fuels.js +191 -0
- package/dist/resources/commodities.d.ts +148 -0
- package/dist/resources/commodities.js +110 -0
- package/dist/resources/data-quality.d.ts +229 -0
- package/dist/resources/data-quality.js +139 -0
- package/dist/resources/data-sources.d.ts +365 -0
- package/dist/resources/data-sources.js +349 -0
- package/dist/resources/drilling.d.ts +403 -0
- package/dist/resources/drilling.js +264 -0
- package/dist/resources/ei/drilling-productivity.d.ts +173 -0
- package/dist/resources/ei/drilling-productivity.js +103 -0
- package/dist/resources/ei/forecasts.d.ts +177 -0
- package/dist/resources/ei/forecasts.js +101 -0
- package/dist/resources/ei/frac-focus.d.ts +212 -0
- package/dist/resources/ei/frac-focus.js +150 -0
- package/dist/resources/ei/index.d.ts +140 -0
- package/dist/resources/ei/index.js +87 -0
- package/dist/resources/ei/oil-inventories.d.ts +155 -0
- package/dist/resources/ei/oil-inventories.js +92 -0
- package/dist/resources/ei/opec-production.d.ts +146 -0
- package/dist/resources/ei/opec-production.js +92 -0
- package/dist/resources/ei/rig-counts.d.ts +131 -0
- package/dist/resources/ei/rig-counts.js +88 -0
- package/dist/resources/ei/well-permits.d.ts +178 -0
- package/dist/resources/ei/well-permits.js +119 -0
- package/dist/resources/forecasts.d.ts +200 -0
- package/dist/resources/forecasts.js +157 -0
- package/dist/resources/futures.d.ts +322 -0
- package/dist/resources/futures.js +228 -0
- package/dist/resources/rig-counts.d.ts +221 -0
- package/dist/resources/rig-counts.js +157 -0
- package/dist/resources/storage.d.ts +182 -0
- package/dist/resources/storage.js +161 -0
- package/dist/resources/webhooks.d.ts +290 -0
- package/dist/resources/webhooks.js +297 -0
- package/dist/types.d.ts +77 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ Official Node.js SDK for [Oil Price API](https://www.oilpriceapi.com) - Get real
|
|
|
18
18
|
- 🐛 **Debuggable** - Built-in debug logging mode
|
|
19
19
|
- ⛽ **NEW v0.4.0** - Diesel prices (state averages + station-level pricing)
|
|
20
20
|
- 🔔 **NEW v0.5.0** - Price alerts with webhook notifications
|
|
21
|
+
- 📊 **NEW v0.7.0** - Futures, storage, rig counts, analytics, drilling intelligence, webhooks, and energy intelligence
|
|
21
22
|
|
|
22
23
|
## Installation
|
|
23
24
|
|
|
@@ -28,13 +29,13 @@ npm install oilpriceapi
|
|
|
28
29
|
## Quick Start
|
|
29
30
|
|
|
30
31
|
```typescript
|
|
31
|
-
import { OilPriceAPI } from
|
|
32
|
+
import { OilPriceAPI } from "oilpriceapi";
|
|
32
33
|
|
|
33
34
|
// Initialize the client
|
|
34
35
|
const client = new OilPriceAPI({
|
|
35
|
-
apiKey:
|
|
36
|
-
retries: 3,
|
|
37
|
-
timeout: 30000
|
|
36
|
+
apiKey: "your_api_key_here", // Get your free key at https://www.oilpriceapi.com
|
|
37
|
+
retries: 3, // Automatic retries (default: 3)
|
|
38
|
+
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
// Get latest prices
|
|
@@ -68,11 +69,11 @@ const prices = await client.getLatestPrices();
|
|
|
68
69
|
|
|
69
70
|
```typescript
|
|
70
71
|
// Get only WTI crude oil price
|
|
71
|
-
const wti = await client.getLatestPrices({ commodity:
|
|
72
|
+
const wti = await client.getLatestPrices({ commodity: "WTI_USD" });
|
|
72
73
|
console.log(`WTI: ${wti[0].formatted} per barrel`);
|
|
73
74
|
|
|
74
75
|
// Get only Brent crude price
|
|
75
|
-
const brent = await client.getLatestPrices({ commodity:
|
|
76
|
+
const brent = await client.getLatestPrices({ commodity: "BRENT_CRUDE_USD" });
|
|
76
77
|
console.log(`Brent: ${brent[0].formatted} per barrel`);
|
|
77
78
|
```
|
|
78
79
|
|
|
@@ -80,8 +81,8 @@ console.log(`Brent: ${brent[0].formatted} per barrel`);
|
|
|
80
81
|
|
|
81
82
|
```typescript
|
|
82
83
|
const weekPrices = await client.getHistoricalPrices({
|
|
83
|
-
period:
|
|
84
|
-
commodity:
|
|
84
|
+
period: "past_week",
|
|
85
|
+
commodity: "WTI_USD",
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
console.log(`Got ${weekPrices.length} data points from the past week`);
|
|
@@ -91,9 +92,9 @@ console.log(`Got ${weekPrices.length} data points from the past week`);
|
|
|
91
92
|
|
|
92
93
|
```typescript
|
|
93
94
|
const prices = await client.getHistoricalPrices({
|
|
94
|
-
startDate:
|
|
95
|
-
endDate:
|
|
96
|
-
commodity:
|
|
95
|
+
startDate: "2024-01-01",
|
|
96
|
+
endDate: "2024-12-31",
|
|
97
|
+
commodity: "BRENT_CRUDE_USD",
|
|
97
98
|
});
|
|
98
99
|
|
|
99
100
|
console.log(`Got ${prices.length} data points for 2024`);
|
|
@@ -106,9 +107,9 @@ For year-long queries, use the `interval` parameter to dramatically improve resp
|
|
|
106
107
|
```typescript
|
|
107
108
|
// FAST: Daily aggregation returns 365 data points (~1 second)
|
|
108
109
|
const yearlyPrices = await client.getHistoricalPrices({
|
|
109
|
-
period:
|
|
110
|
-
commodity:
|
|
111
|
-
interval:
|
|
110
|
+
period: "past_year",
|
|
111
|
+
commodity: "BRENT_CRUDE_USD",
|
|
112
|
+
interval: "daily", // Options: 'raw', 'hourly', 'daily', 'weekly', 'monthly'
|
|
112
113
|
});
|
|
113
114
|
|
|
114
115
|
console.log(`Got ${yearlyPrices.length} daily averages`);
|
|
@@ -124,7 +125,7 @@ console.log(`Got ${yearlyPrices.length} daily averages`);
|
|
|
124
125
|
|
|
125
126
|
```typescript
|
|
126
127
|
// Get California diesel price
|
|
127
|
-
const caPrice = await client.diesel.getPrice(
|
|
128
|
+
const caPrice = await client.diesel.getPrice("CA");
|
|
128
129
|
console.log(`California diesel: $${caPrice.price}/gallon`);
|
|
129
130
|
console.log(`Source: ${caPrice.source}`);
|
|
130
131
|
console.log(`Last updated: ${caPrice.updated_at}`);
|
|
@@ -140,16 +141,18 @@ console.log(`Last updated: ${caPrice.updated_at}`);
|
|
|
140
141
|
```typescript
|
|
141
142
|
// Find diesel stations near San Francisco
|
|
142
143
|
const result = await client.diesel.getStations({
|
|
143
|
-
lat: 37.7749,
|
|
144
|
+
lat: 37.7749, // San Francisco latitude
|
|
144
145
|
lng: -122.4194, // San Francisco longitude
|
|
145
|
-
radius: 8047
|
|
146
|
+
radius: 8047, // 5 miles in meters (default if not specified)
|
|
146
147
|
});
|
|
147
148
|
|
|
148
149
|
console.log(`Regional average: $${result.regional_average.price}/gallon`);
|
|
149
|
-
console.log(
|
|
150
|
+
console.log(
|
|
151
|
+
`Found ${result.stations.length} stations within ${result.search_area.radius_miles} miles`,
|
|
152
|
+
);
|
|
150
153
|
|
|
151
154
|
// Print each station
|
|
152
|
-
result.stations.forEach(station => {
|
|
155
|
+
result.stations.forEach((station) => {
|
|
153
156
|
console.log(`\n${station.name}`);
|
|
154
157
|
console.log(` Address: ${station.address}`);
|
|
155
158
|
console.log(` Price: ${station.formatted_price}`);
|
|
@@ -175,18 +178,20 @@ result.stations.forEach(station => {
|
|
|
175
178
|
|
|
176
179
|
```typescript
|
|
177
180
|
const result = await client.diesel.getStations({
|
|
178
|
-
lat: 34.0522,
|
|
181
|
+
lat: 34.0522, // Los Angeles
|
|
179
182
|
lng: -118.2437,
|
|
180
|
-
radius: 5000
|
|
183
|
+
radius: 5000, // ~3 miles
|
|
181
184
|
});
|
|
182
185
|
|
|
183
186
|
// Find the cheapest station
|
|
184
187
|
const cheapest = result.stations.reduce((min, station) =>
|
|
185
|
-
station.diesel_price < min.diesel_price ? station : min
|
|
188
|
+
station.diesel_price < min.diesel_price ? station : min,
|
|
186
189
|
);
|
|
187
190
|
|
|
188
191
|
console.log(`Cheapest diesel: ${cheapest.name} at ${cheapest.formatted_price}`);
|
|
189
|
-
console.log(
|
|
192
|
+
console.log(
|
|
193
|
+
`Savings: ${Math.abs(cheapest.price_delta!).toFixed(2)} per gallon vs regional average`,
|
|
194
|
+
);
|
|
190
195
|
```
|
|
191
196
|
|
|
192
197
|
**Note:** Station-level diesel prices are available on paid tiers (Exploration and above). State averages are free.
|
|
@@ -198,13 +203,13 @@ console.log(`Savings: ${Math.abs(cheapest.price_delta!).toFixed(2)} per gallon v
|
|
|
198
203
|
```typescript
|
|
199
204
|
// Create an alert when Brent crude exceeds $85
|
|
200
205
|
const alert = await client.alerts.create({
|
|
201
|
-
name:
|
|
202
|
-
commodity_code:
|
|
203
|
-
condition_operator:
|
|
204
|
-
condition_value: 85.
|
|
205
|
-
webhook_url:
|
|
206
|
+
name: "Brent High Alert",
|
|
207
|
+
commodity_code: "BRENT_CRUDE_USD",
|
|
208
|
+
condition_operator: "greater_than",
|
|
209
|
+
condition_value: 85.0,
|
|
210
|
+
webhook_url: "https://your-app.com/webhooks/price-alert",
|
|
206
211
|
enabled: true,
|
|
207
|
-
cooldown_minutes: 60
|
|
212
|
+
cooldown_minutes: 60, // Wait 60 minutes between triggers
|
|
208
213
|
});
|
|
209
214
|
|
|
210
215
|
console.log(`Alert created: ${alert.name} (ID: ${alert.id})`);
|
|
@@ -215,11 +220,13 @@ console.log(`Alert created: ${alert.name} (ID: ${alert.id})`);
|
|
|
215
220
|
```typescript
|
|
216
221
|
const alerts = await client.alerts.list();
|
|
217
222
|
|
|
218
|
-
alerts.forEach(alert => {
|
|
219
|
-
console.log(
|
|
220
|
-
|
|
223
|
+
alerts.forEach((alert) => {
|
|
224
|
+
console.log(
|
|
225
|
+
`${alert.name}: ${alert.commodity_code} ${alert.condition_operator} ${alert.condition_value}`,
|
|
226
|
+
);
|
|
227
|
+
console.log(` Status: ${alert.enabled ? "Active" : "Disabled"}`);
|
|
221
228
|
console.log(` Triggers: ${alert.trigger_count}`);
|
|
222
|
-
console.log(` Last triggered: ${alert.last_triggered_at ||
|
|
229
|
+
console.log(` Last triggered: ${alert.last_triggered_at || "Never"}`);
|
|
223
230
|
});
|
|
224
231
|
```
|
|
225
232
|
|
|
@@ -231,13 +238,13 @@ await client.alerts.update(alertId, { enabled: false });
|
|
|
231
238
|
|
|
232
239
|
// Change threshold and cooldown
|
|
233
240
|
await client.alerts.update(alertId, {
|
|
234
|
-
condition_value: 90.
|
|
235
|
-
cooldown_minutes: 120
|
|
241
|
+
condition_value: 90.0,
|
|
242
|
+
cooldown_minutes: 120,
|
|
236
243
|
});
|
|
237
244
|
|
|
238
245
|
// Update webhook URL
|
|
239
246
|
await client.alerts.update(alertId, {
|
|
240
|
-
webhook_url:
|
|
247
|
+
webhook_url: "https://new-app.com/webhook",
|
|
241
248
|
});
|
|
242
249
|
```
|
|
243
250
|
|
|
@@ -245,22 +252,25 @@ await client.alerts.update(alertId, {
|
|
|
245
252
|
|
|
246
253
|
```typescript
|
|
247
254
|
await client.alerts.delete(alertId);
|
|
248
|
-
console.log(
|
|
255
|
+
console.log("Alert deleted successfully");
|
|
249
256
|
```
|
|
250
257
|
|
|
251
258
|
#### Test Webhook Endpoint
|
|
252
259
|
|
|
253
260
|
```typescript
|
|
254
|
-
const result = await client.alerts.testWebhook(
|
|
261
|
+
const result = await client.alerts.testWebhook("https://your-app.com/webhook");
|
|
255
262
|
|
|
256
263
|
if (result.success) {
|
|
257
|
-
console.log(
|
|
264
|
+
console.log(
|
|
265
|
+
`Webhook OK (${result.status_code}) - ${result.response_time_ms}ms`,
|
|
266
|
+
);
|
|
258
267
|
} else {
|
|
259
268
|
console.error(`Webhook failed: ${result.error}`);
|
|
260
269
|
}
|
|
261
270
|
```
|
|
262
271
|
|
|
263
272
|
**Alert Operators:**
|
|
273
|
+
|
|
264
274
|
- `greater_than` - Trigger when price exceeds threshold
|
|
265
275
|
- `less_than` - Trigger when price falls below threshold
|
|
266
276
|
- `equals` - Trigger when price matches threshold exactly
|
|
@@ -269,6 +279,7 @@ if (result.success) {
|
|
|
269
279
|
|
|
270
280
|
**Webhook Payload Example:**
|
|
271
281
|
When an alert triggers, a POST request is sent to your webhook URL with:
|
|
282
|
+
|
|
272
283
|
```json
|
|
273
284
|
{
|
|
274
285
|
"event": "price_alert.triggered",
|
|
@@ -276,36 +287,247 @@ When an alert triggers, a POST request is sent to your webhook URL with:
|
|
|
276
287
|
"alert_name": "Brent High Alert",
|
|
277
288
|
"commodity_code": "BRENT_CRUDE_USD",
|
|
278
289
|
"condition_operator": "greater_than",
|
|
279
|
-
"condition_value": 85.
|
|
280
|
-
"current_price": 86.
|
|
290
|
+
"condition_value": 85.0,
|
|
291
|
+
"current_price": 86.5,
|
|
281
292
|
"triggered_at": "2025-12-15T14:30:00Z"
|
|
282
293
|
}
|
|
283
294
|
```
|
|
284
295
|
|
|
285
296
|
**Limits:**
|
|
297
|
+
|
|
286
298
|
- Maximum 100 alerts per user
|
|
287
299
|
- Cooldown period: 0-1440 minutes (24 hours)
|
|
288
300
|
- Condition value: Must be between $0.01 and $1,000,000
|
|
289
301
|
- Webhook URL: Must use HTTPS protocol
|
|
290
302
|
|
|
303
|
+
### Commodities Metadata (New in v0.7.0)
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
// List all available commodities
|
|
307
|
+
const { commodities } = await client.commodities.list();
|
|
308
|
+
console.log(`${commodities.length} commodities available`);
|
|
309
|
+
|
|
310
|
+
// Get specific commodity details
|
|
311
|
+
const wti = await client.commodities.get("WTI_USD");
|
|
312
|
+
console.log(`${wti.name}: ${wti.description}`);
|
|
313
|
+
console.log(`Unit: ${wti.unit}, Currency: ${wti.currency}`);
|
|
314
|
+
|
|
315
|
+
// Get commodities by category
|
|
316
|
+
const categories = await client.commodities.categories();
|
|
317
|
+
console.log(`Oil category: ${categories.oil.commodities.length} commodities`);
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Futures Contracts (New in v0.7.0)
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
// Get latest futures price
|
|
324
|
+
const wti = await client.futures.latest("CL.1");
|
|
325
|
+
console.log(`WTI Front Month: $${wti.price}`);
|
|
326
|
+
|
|
327
|
+
// Get OHLC data
|
|
328
|
+
const ohlc = await client.futures.ohlc("CL.1", "2024-01-15");
|
|
329
|
+
console.log(`High: $${ohlc.high}, Low: $${ohlc.low}`);
|
|
330
|
+
|
|
331
|
+
// Get futures curve
|
|
332
|
+
const curve = await client.futures.curve("CL");
|
|
333
|
+
curve.curve.forEach((point) => {
|
|
334
|
+
console.log(`${point.months_out} months: $${point.price}`);
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Storage Levels (New in v0.7.0)
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// Get total US crude storage
|
|
342
|
+
const storage = await client.storage.all();
|
|
343
|
+
console.log(`US inventory: ${storage.level} ${storage.unit}`);
|
|
344
|
+
|
|
345
|
+
// Get Cushing hub levels
|
|
346
|
+
const cushing = await client.storage.cushing();
|
|
347
|
+
console.log(`Cushing: ${cushing.level} ${cushing.unit}`);
|
|
348
|
+
|
|
349
|
+
// Get Strategic Petroleum Reserve
|
|
350
|
+
const spr = await client.storage.spr();
|
|
351
|
+
console.log(`SPR: ${spr.level} ${spr.unit}`);
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Rig Counts (New in v0.7.0)
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
// Get latest Baker Hughes rig count
|
|
358
|
+
const rigCounts = await client.rigCounts.latest();
|
|
359
|
+
console.log(`Total rigs: ${rigCounts.total}`);
|
|
360
|
+
console.log(`Oil: ${rigCounts.oil}, Gas: ${rigCounts.gas}`);
|
|
361
|
+
|
|
362
|
+
// Get summary with changes
|
|
363
|
+
const summary = await client.rigCounts.summary();
|
|
364
|
+
console.log(`Week-over-week: ${summary.week_change}`);
|
|
365
|
+
console.log(`Year-over-year: ${summary.year_change}`);
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Analytics (New in v0.7.0)
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
// Get performance metrics
|
|
372
|
+
const perf = await client.analytics.performance({
|
|
373
|
+
commodity: "WTI_USD",
|
|
374
|
+
days: 30,
|
|
375
|
+
});
|
|
376
|
+
console.log(`30-day return: ${perf.return_percent}%`);
|
|
377
|
+
console.log(`Volatility: ${perf.volatility}`);
|
|
378
|
+
|
|
379
|
+
// Analyze correlation between commodities
|
|
380
|
+
const corr = await client.analytics.correlation(
|
|
381
|
+
"WTI_USD",
|
|
382
|
+
"BRENT_CRUDE_USD",
|
|
383
|
+
90,
|
|
384
|
+
);
|
|
385
|
+
console.log(`Correlation: ${corr.correlation} (${corr.strength})`);
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Drilling Intelligence (New in v0.7.0)
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
// Get latest drilling activity
|
|
392
|
+
const drilling = await client.drilling.latest();
|
|
393
|
+
console.log(`Active rigs: ${drilling.total_rigs}`);
|
|
394
|
+
console.log(`Frac spreads: ${drilling.total_frac_spreads}`);
|
|
395
|
+
|
|
396
|
+
// Get basin-specific data
|
|
397
|
+
const permian = await client.drilling.basin("Permian");
|
|
398
|
+
console.log(`Permian rigs: ${permian.active_rigs}`);
|
|
399
|
+
console.log(`DUC wells: ${permian.duc_wells}`);
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Energy Intelligence (New in v0.7.0)
|
|
403
|
+
|
|
404
|
+
Access comprehensive energy market intelligence from EIA, Baker Hughes, and FracFocus.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// Rig counts
|
|
408
|
+
const rigCounts = await client.ei.rigCounts.latest();
|
|
409
|
+
console.log(`Total rigs: ${rigCounts.total_rigs}`);
|
|
410
|
+
|
|
411
|
+
// Oil inventories
|
|
412
|
+
const inventories = await client.ei.oilInventories.latest();
|
|
413
|
+
console.log(`Crude stocks: ${inventories.level} ${inventories.unit}`);
|
|
414
|
+
|
|
415
|
+
// OPEC production
|
|
416
|
+
const opec = await client.ei.opecProduction.total();
|
|
417
|
+
console.log(`OPEC production: ${opec.total_production_bpd} bpd`);
|
|
418
|
+
|
|
419
|
+
// Well timeline
|
|
420
|
+
const timeline = await client.ei.wellTimeline("42-123-12345");
|
|
421
|
+
timeline.events.forEach((e) => {
|
|
422
|
+
console.log(`${e.date}: ${e.event_type}`);
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Webhooks (New in v0.7.0)
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
// Create a webhook
|
|
430
|
+
const webhook = await client.webhooks.create({
|
|
431
|
+
name: "Price Updates",
|
|
432
|
+
url: "https://myapp.com/webhooks/prices",
|
|
433
|
+
events: ["price.updated", "alert.triggered"],
|
|
434
|
+
enabled: true,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// Test the webhook
|
|
438
|
+
const test = await client.webhooks.test(webhook.id);
|
|
439
|
+
console.log(`Test ${test.success ? "passed" : "failed"}`);
|
|
440
|
+
|
|
441
|
+
// List all webhooks
|
|
442
|
+
const webhooks = await client.webhooks.list();
|
|
443
|
+
webhooks.forEach((wh) => {
|
|
444
|
+
console.log(`${wh.name}: ${wh.successful_deliveries} successful`);
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Bunker Fuels (New in v0.7.0)
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
// Get bunker fuel prices at all ports
|
|
452
|
+
const bunkerPrices = await client.bunkerFuels.all();
|
|
453
|
+
console.log(`${bunkerPrices.length} port prices available`);
|
|
454
|
+
|
|
455
|
+
// Get prices at specific port
|
|
456
|
+
const singapore = await client.bunkerFuels.port("SGSIN");
|
|
457
|
+
console.log(`Singapore VLSFO: $${singapore.prices.VLSFO}/MT`);
|
|
458
|
+
|
|
459
|
+
// Compare prices across ports
|
|
460
|
+
const comparison = await client.bunkerFuels.compare("VLSFO");
|
|
461
|
+
comparison.ports.forEach((p) => {
|
|
462
|
+
console.log(`${p.port_name}: $${p.price}/MT (rank ${p.rank})`);
|
|
463
|
+
});
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Forecasts (New in v0.7.0)
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
// Get monthly forecasts
|
|
470
|
+
const forecasts = await client.forecasts.monthly();
|
|
471
|
+
forecasts.forEach((f) => {
|
|
472
|
+
console.log(`${f.period}: $${f.forecast_price} (${f.source})`);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
// Check forecast accuracy
|
|
476
|
+
const accuracy = await client.forecasts.accuracy();
|
|
477
|
+
console.log(`EIA MAPE: ${accuracy.mape}%`);
|
|
478
|
+
|
|
479
|
+
// Get specific forecast
|
|
480
|
+
const wtiQ2 = await client.forecasts.get({
|
|
481
|
+
commodity: "WTI_USD",
|
|
482
|
+
period: "2024-Q2",
|
|
483
|
+
});
|
|
484
|
+
console.log(`WTI Q2 forecast: $${wtiQ2.forecast_price}`);
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Data Sources (New in v0.7.0)
|
|
488
|
+
|
|
489
|
+
Manage custom data source integrations for Bring Your Own Source (BYOS).
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
// Create a data source
|
|
493
|
+
const source = await client.dataSources.create({
|
|
494
|
+
name: "Internal Pricing Database",
|
|
495
|
+
type: "database",
|
|
496
|
+
config: { host: "db.example.com", port: 5432 },
|
|
497
|
+
sync_frequency_minutes: 60,
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// Test the connection
|
|
501
|
+
const test = await client.dataSources.test(source.id);
|
|
502
|
+
console.log(`Connection ${test.success ? "OK" : "failed"}`);
|
|
503
|
+
|
|
504
|
+
// View sync logs
|
|
505
|
+
const logs = await client.dataSources.logs(source.id);
|
|
506
|
+
logs.forEach((log) => {
|
|
507
|
+
console.log(
|
|
508
|
+
`${log.timestamp}: ${log.status} - ${log.records_synced} records`,
|
|
509
|
+
);
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
291
513
|
### Advanced Configuration
|
|
292
514
|
|
|
293
515
|
```typescript
|
|
294
|
-
import { OilPriceAPI } from
|
|
516
|
+
import { OilPriceAPI } from "oilpriceapi";
|
|
295
517
|
|
|
296
518
|
const client = new OilPriceAPI({
|
|
297
|
-
apiKey:
|
|
519
|
+
apiKey: "your_key",
|
|
298
520
|
|
|
299
521
|
// Retry configuration
|
|
300
|
-
retries: 3,
|
|
301
|
-
retryDelay: 1000,
|
|
302
|
-
retryStrategy:
|
|
522
|
+
retries: 3, // Max retry attempts (default: 3)
|
|
523
|
+
retryDelay: 1000, // Initial delay in ms (default: 1000)
|
|
524
|
+
retryStrategy: "exponential", // 'exponential', 'linear', or 'fixed'
|
|
303
525
|
|
|
304
526
|
// Timeout configuration
|
|
305
|
-
timeout: 30000,
|
|
527
|
+
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
306
528
|
|
|
307
529
|
// Debug mode
|
|
308
|
-
debug: true
|
|
530
|
+
debug: true, // Enable debug logging (default: false)
|
|
309
531
|
});
|
|
310
532
|
```
|
|
311
533
|
|
|
@@ -318,26 +540,30 @@ import {
|
|
|
318
540
|
RateLimitError,
|
|
319
541
|
NotFoundError,
|
|
320
542
|
TimeoutError,
|
|
321
|
-
ServerError
|
|
322
|
-
} from
|
|
543
|
+
ServerError,
|
|
544
|
+
} from "oilpriceapi";
|
|
323
545
|
|
|
324
|
-
const client = new OilPriceAPI({ apiKey:
|
|
546
|
+
const client = new OilPriceAPI({ apiKey: "your_key" });
|
|
325
547
|
|
|
326
548
|
try {
|
|
327
549
|
const prices = await client.getLatestPrices();
|
|
328
550
|
} catch (error) {
|
|
329
551
|
if (error instanceof AuthenticationError) {
|
|
330
|
-
console.error(
|
|
552
|
+
console.error("Invalid API key:", error.message);
|
|
331
553
|
} else if (error instanceof RateLimitError) {
|
|
332
|
-
console.error(
|
|
554
|
+
console.error(
|
|
555
|
+
"Rate limit exceeded. Retry after:",
|
|
556
|
+
error.retryAfter,
|
|
557
|
+
"seconds",
|
|
558
|
+
);
|
|
333
559
|
} else if (error instanceof TimeoutError) {
|
|
334
|
-
console.error(
|
|
560
|
+
console.error("Request timed out:", error.message);
|
|
335
561
|
} else if (error instanceof ServerError) {
|
|
336
|
-
console.error(
|
|
562
|
+
console.error("Server error:", error.statusCode, error.message);
|
|
337
563
|
} else if (error instanceof NotFoundError) {
|
|
338
|
-
console.error(
|
|
564
|
+
console.error("Commodity not found:", error.message);
|
|
339
565
|
} else {
|
|
340
|
-
console.error(
|
|
566
|
+
console.error("Unknown error:", error);
|
|
341
567
|
}
|
|
342
568
|
}
|
|
343
569
|
```
|
|
@@ -348,8 +574,8 @@ Enable debug logging to see detailed request/response information:
|
|
|
348
574
|
|
|
349
575
|
```typescript
|
|
350
576
|
const client = new OilPriceAPI({
|
|
351
|
-
apiKey:
|
|
352
|
-
debug: true
|
|
577
|
+
apiKey: "your_key",
|
|
578
|
+
debug: true,
|
|
353
579
|
});
|
|
354
580
|
|
|
355
581
|
// This will log all requests, responses, retries, and errors
|
|
@@ -374,49 +600,54 @@ See the [`examples/`](./examples) directory for complete, runnable code examples
|
|
|
374
600
|
### Quick Examples
|
|
375
601
|
|
|
376
602
|
**Get Latest Price:**
|
|
603
|
+
|
|
377
604
|
```typescript
|
|
378
|
-
const prices = await client.getLatestPrices({ commodity:
|
|
605
|
+
const prices = await client.getLatestPrices({ commodity: "WTI_USD" });
|
|
379
606
|
console.log(prices[0].formatted); // "$74.25"
|
|
380
607
|
```
|
|
381
608
|
|
|
382
609
|
**Historical Data:**
|
|
610
|
+
|
|
383
611
|
```typescript
|
|
384
612
|
const history = await client.getHistoricalPrices({
|
|
385
|
-
commodity:
|
|
386
|
-
period:
|
|
613
|
+
commodity: "BRENT_CRUDE_USD",
|
|
614
|
+
period: "past_week",
|
|
387
615
|
});
|
|
388
616
|
```
|
|
389
617
|
|
|
390
618
|
**Commodity Metadata:**
|
|
619
|
+
|
|
391
620
|
```typescript
|
|
392
621
|
const { commodities } = await client.getCommodities();
|
|
393
622
|
console.log(`Found ${commodities.length} commodities`);
|
|
394
623
|
```
|
|
395
624
|
|
|
396
625
|
**Diesel Prices:**
|
|
626
|
+
|
|
397
627
|
```typescript
|
|
398
628
|
// State average (free)
|
|
399
|
-
const caPrice = await client.diesel.getPrice(
|
|
629
|
+
const caPrice = await client.diesel.getPrice("CA");
|
|
400
630
|
console.log(`CA diesel: $${caPrice.price}/gal`);
|
|
401
631
|
|
|
402
632
|
// Nearby stations (paid tiers)
|
|
403
633
|
const stations = await client.diesel.getStations({
|
|
404
634
|
lat: 37.7749,
|
|
405
635
|
lng: -122.4194,
|
|
406
|
-
radius: 8047
|
|
636
|
+
radius: 8047, // 5 miles
|
|
407
637
|
});
|
|
408
638
|
console.log(`Found ${stations.stations.length} stations`);
|
|
409
639
|
```
|
|
410
640
|
|
|
411
641
|
**Price Alerts:**
|
|
642
|
+
|
|
412
643
|
```typescript
|
|
413
644
|
// Create an alert
|
|
414
645
|
const alert = await client.alerts.create({
|
|
415
|
-
name:
|
|
416
|
-
commodity_code:
|
|
417
|
-
condition_operator:
|
|
418
|
-
condition_value: 85.
|
|
419
|
-
webhook_url:
|
|
646
|
+
name: "Brent High Alert",
|
|
647
|
+
commodity_code: "BRENT_CRUDE_USD",
|
|
648
|
+
condition_operator: "greater_than",
|
|
649
|
+
condition_value: 85.0,
|
|
650
|
+
webhook_url: "https://your-app.com/webhook",
|
|
420
651
|
});
|
|
421
652
|
|
|
422
653
|
// List all alerts
|
|
@@ -426,13 +657,37 @@ const alerts = await client.alerts.list();
|
|
|
426
657
|
await client.alerts.update(alert.id, { enabled: false });
|
|
427
658
|
```
|
|
428
659
|
|
|
660
|
+
**Futures & Storage:**
|
|
661
|
+
|
|
662
|
+
```typescript
|
|
663
|
+
// Get WTI futures price
|
|
664
|
+
const wti = await client.futures.latest("CL.1");
|
|
665
|
+
console.log(`WTI: $${wti.price}`);
|
|
666
|
+
|
|
667
|
+
// Get Cushing storage
|
|
668
|
+
const cushing = await client.storage.cushing();
|
|
669
|
+
console.log(`Cushing: ${cushing.level} ${cushing.unit}`);
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
**Analytics:**
|
|
673
|
+
|
|
674
|
+
```typescript
|
|
675
|
+
// Get performance metrics
|
|
676
|
+
const perf = await client.analytics.performance({
|
|
677
|
+
commodity: "WTI_USD",
|
|
678
|
+
days: 30,
|
|
679
|
+
});
|
|
680
|
+
console.log(`30-day return: ${perf.return_percent}%`);
|
|
681
|
+
```
|
|
682
|
+
|
|
429
683
|
**Error Handling:**
|
|
684
|
+
|
|
430
685
|
```typescript
|
|
431
686
|
try {
|
|
432
687
|
const prices = await client.getLatestPrices();
|
|
433
688
|
} catch (error) {
|
|
434
689
|
if (error instanceof RateLimitError) {
|
|
435
|
-
console.log(
|
|
690
|
+
console.log("Rate limited, retry after:", error.retryAfter);
|
|
436
691
|
}
|
|
437
692
|
}
|
|
438
693
|
```
|
|
@@ -450,6 +705,7 @@ new OilPriceAPI(config: OilPriceAPIConfig)
|
|
|
450
705
|
```
|
|
451
706
|
|
|
452
707
|
**Parameters:**
|
|
708
|
+
|
|
453
709
|
- `config.apiKey` (string, required) - Your API key from https://www.oilpriceapi.com
|
|
454
710
|
- `config.baseUrl` (string, optional) - Custom API base URL (for testing)
|
|
455
711
|
|
|
@@ -460,6 +716,7 @@ new OilPriceAPI(config: OilPriceAPIConfig)
|
|
|
460
716
|
Get the latest prices for all commodities or a specific commodity.
|
|
461
717
|
|
|
462
718
|
**Parameters:**
|
|
719
|
+
|
|
463
720
|
- `options.commodity` (string, optional) - Filter by commodity code (e.g., "WTI_USD")
|
|
464
721
|
|
|
465
722
|
**Returns:** `Promise<Price[]>`
|
|
@@ -469,6 +726,7 @@ Get the latest prices for all commodities or a specific commodity.
|
|
|
469
726
|
Get historical prices for a time period.
|
|
470
727
|
|
|
471
728
|
**Parameters:**
|
|
729
|
+
|
|
472
730
|
- `options.period` (string, optional) - One of: "past_week", "past_month", "past_year"
|
|
473
731
|
- `options.commodity` (string, optional) - Filter by commodity code
|
|
474
732
|
- `options.startDate` (string, optional) - Start date in ISO 8601 format (YYYY-MM-DD)
|
|
@@ -496,6 +754,7 @@ Get all commodity categories with their commodities.
|
|
|
496
754
|
Get metadata for a specific commodity by code.
|
|
497
755
|
|
|
498
756
|
**Parameters:**
|
|
757
|
+
|
|
499
758
|
- `code` (string, required) - Commodity code (e.g., "WTI_USD")
|
|
500
759
|
|
|
501
760
|
**Returns:** `Promise<Commodity>` - Commodity metadata object
|
|
@@ -509,13 +768,15 @@ Resource for diesel price data (state averages and station-level pricing).
|
|
|
509
768
|
Get average diesel price for a US state from EIA data.
|
|
510
769
|
|
|
511
770
|
**Parameters:**
|
|
771
|
+
|
|
512
772
|
- `state` (string, required) - Two-letter US state code (e.g., "CA", "TX", "NY")
|
|
513
773
|
|
|
514
774
|
**Returns:** `Promise<DieselPrice>`
|
|
515
775
|
|
|
516
776
|
**Example:**
|
|
777
|
+
|
|
517
778
|
```typescript
|
|
518
|
-
const caPrice = await client.diesel.getPrice(
|
|
779
|
+
const caPrice = await client.diesel.getPrice("CA");
|
|
519
780
|
console.log(`California: $${caPrice.price}/gallon`);
|
|
520
781
|
```
|
|
521
782
|
|
|
@@ -524,6 +785,7 @@ console.log(`California: $${caPrice.price}/gallon`);
|
|
|
524
785
|
Get nearby diesel stations with current pricing from Google Maps data.
|
|
525
786
|
|
|
526
787
|
**Parameters:**
|
|
788
|
+
|
|
527
789
|
- `options.lat` (number, required) - Latitude (-90 to 90)
|
|
528
790
|
- `options.lng` (number, required) - Longitude (-180 to 180)
|
|
529
791
|
- `options.radius` (number, optional) - Search radius in meters (default: 8047 = 5 miles, max: 50000)
|
|
@@ -533,18 +795,19 @@ Get nearby diesel stations with current pricing from Google Maps data.
|
|
|
533
795
|
**Tier Requirements:** Available on paid tiers (Exploration and above)
|
|
534
796
|
|
|
535
797
|
**Example:**
|
|
798
|
+
|
|
536
799
|
```typescript
|
|
537
800
|
const result = await client.diesel.getStations({
|
|
538
801
|
lat: 37.7749,
|
|
539
802
|
lng: -122.4194,
|
|
540
|
-
radius: 8047
|
|
803
|
+
radius: 8047, // 5 miles
|
|
541
804
|
});
|
|
542
805
|
|
|
543
806
|
console.log(`Found ${result.stations.length} stations`);
|
|
544
807
|
console.log(`Regional average: $${result.regional_average.price}/gallon`);
|
|
545
808
|
|
|
546
809
|
const cheapest = result.stations.reduce((min, s) =>
|
|
547
|
-
s.diesel_price < min.diesel_price ? s : min
|
|
810
|
+
s.diesel_price < min.diesel_price ? s : min,
|
|
548
811
|
);
|
|
549
812
|
console.log(`Cheapest: ${cheapest.name} at ${cheapest.formatted_price}`);
|
|
550
813
|
```
|
|
@@ -555,14 +818,14 @@ console.log(`Cheapest: ${cheapest.name} at ${cheapest.formatted_price}`);
|
|
|
555
818
|
|
|
556
819
|
```typescript
|
|
557
820
|
interface Price {
|
|
558
|
-
code: string;
|
|
559
|
-
name: string;
|
|
560
|
-
value: number;
|
|
561
|
-
currency: string;
|
|
562
|
-
unit: string;
|
|
563
|
-
timestamp: string;
|
|
564
|
-
created_at: string;
|
|
565
|
-
updated_at: string;
|
|
821
|
+
code: string; // Commodity code (e.g., "WTI_USD")
|
|
822
|
+
name: string; // Human-readable name
|
|
823
|
+
value: number; // Price value
|
|
824
|
+
currency: string; // Currency code (e.g., "USD")
|
|
825
|
+
unit: string; // Unit of measurement (e.g., "barrel")
|
|
826
|
+
timestamp: string; // ISO 8601 timestamp
|
|
827
|
+
created_at: string; // ISO 8601 timestamp
|
|
828
|
+
updated_at: string; // ISO 8601 timestamp
|
|
566
829
|
}
|
|
567
830
|
```
|
|
568
831
|
|
|
@@ -570,14 +833,14 @@ interface Price {
|
|
|
570
833
|
|
|
571
834
|
```typescript
|
|
572
835
|
interface DieselPrice {
|
|
573
|
-
state: string;
|
|
574
|
-
price: number;
|
|
575
|
-
currency: string;
|
|
576
|
-
unit: string;
|
|
577
|
-
granularity: string;
|
|
578
|
-
source: string;
|
|
579
|
-
updated_at: string;
|
|
580
|
-
cached?: boolean;
|
|
836
|
+
state: string; // State code (e.g., "CA", "TX")
|
|
837
|
+
price: number; // Average diesel price in USD per gallon
|
|
838
|
+
currency: string; // Currency code (always "USD")
|
|
839
|
+
unit: string; // Unit of measurement (always "gallon")
|
|
840
|
+
granularity: string; // Level (e.g., "state", "national")
|
|
841
|
+
source: string; // Data source (e.g., "EIA")
|
|
842
|
+
updated_at: string; // ISO 8601 timestamp of last update
|
|
843
|
+
cached?: boolean; // Whether served from cache
|
|
581
844
|
}
|
|
582
845
|
```
|
|
583
846
|
|
|
@@ -585,20 +848,20 @@ interface DieselPrice {
|
|
|
585
848
|
|
|
586
849
|
```typescript
|
|
587
850
|
interface DieselStation {
|
|
588
|
-
name: string;
|
|
589
|
-
address: string;
|
|
851
|
+
name: string; // Station name
|
|
852
|
+
address: string; // Full street address
|
|
590
853
|
location: {
|
|
591
|
-
lat: number;
|
|
592
|
-
lng: number;
|
|
854
|
+
lat: number; // Latitude
|
|
855
|
+
lng: number; // Longitude
|
|
593
856
|
};
|
|
594
|
-
diesel_price: number;
|
|
595
|
-
formatted_price: string
|
|
596
|
-
currency: string;
|
|
597
|
-
unit: string;
|
|
598
|
-
price_delta?: number;
|
|
857
|
+
diesel_price: number; // Price at this station (USD per gallon)
|
|
858
|
+
formatted_price: string; // Formatted price (e.g., "$3.89")
|
|
859
|
+
currency: string; // Currency code (always "USD")
|
|
860
|
+
unit: string; // Unit (always "gallon")
|
|
861
|
+
price_delta?: number; // Difference from regional average
|
|
599
862
|
price_vs_average?: string; // Human-readable comparison
|
|
600
|
-
fuel_types?: string[];
|
|
601
|
-
last_updated?: string;
|
|
863
|
+
fuel_types?: string[]; // Available fuel types
|
|
864
|
+
last_updated?: string; // ISO 8601 timestamp
|
|
602
865
|
}
|
|
603
866
|
```
|
|
604
867
|
|
|
@@ -607,28 +870,28 @@ interface DieselStation {
|
|
|
607
870
|
```typescript
|
|
608
871
|
interface DieselStationsResponse {
|
|
609
872
|
regional_average: {
|
|
610
|
-
price: number;
|
|
611
|
-
currency: string;
|
|
612
|
-
unit: string;
|
|
613
|
-
region: string;
|
|
614
|
-
granularity: string;
|
|
615
|
-
source: string;
|
|
873
|
+
price: number; // Regional average price
|
|
874
|
+
currency: string; // Currency code
|
|
875
|
+
unit: string; // Unit
|
|
876
|
+
region: string; // Region name
|
|
877
|
+
granularity: string; // Granularity level
|
|
878
|
+
source: string; // Data source
|
|
616
879
|
};
|
|
617
880
|
stations: DieselStation[]; // List of nearby stations
|
|
618
881
|
search_area: {
|
|
619
882
|
center: {
|
|
620
|
-
lat: number;
|
|
621
|
-
lng: number;
|
|
883
|
+
lat: number; // Search center latitude
|
|
884
|
+
lng: number; // Search center longitude
|
|
622
885
|
};
|
|
623
|
-
radius_meters: number
|
|
886
|
+
radius_meters: number; // Search radius in meters
|
|
624
887
|
radius_miles: number; // Search radius in miles
|
|
625
888
|
};
|
|
626
889
|
metadata: {
|
|
627
890
|
total_stations: number; // Number of stations found
|
|
628
|
-
source: string;
|
|
629
|
-
cached: boolean;
|
|
630
|
-
api_cost: number;
|
|
631
|
-
timestamp: string;
|
|
891
|
+
source: string; // Data source
|
|
892
|
+
cached: boolean; // Whether served from cache
|
|
893
|
+
api_cost: number; // Cost in dollars
|
|
894
|
+
timestamp: string; // ISO 8601 timestamp
|
|
632
895
|
cache_age_hours?: number; // Cache age in hours
|
|
633
896
|
};
|
|
634
897
|
}
|