oilpriceapi 0.5.3 → 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.
Files changed (49) hide show
  1. package/README.md +395 -110
  2. package/dist/client.d.ts +83 -3
  3. package/dist/client.js +118 -38
  4. package/dist/index.d.ts +31 -6
  5. package/dist/index.js +17 -3
  6. package/dist/resources/alerts.d.ts +52 -15
  7. package/dist/resources/alerts.js +143 -85
  8. package/dist/resources/analytics.d.ts +325 -0
  9. package/dist/resources/analytics.js +221 -0
  10. package/dist/resources/bunker-fuels.d.ts +270 -0
  11. package/dist/resources/bunker-fuels.js +191 -0
  12. package/dist/resources/commodities.d.ts +148 -0
  13. package/dist/resources/commodities.js +110 -0
  14. package/dist/resources/data-quality.d.ts +229 -0
  15. package/dist/resources/data-quality.js +139 -0
  16. package/dist/resources/data-sources.d.ts +365 -0
  17. package/dist/resources/data-sources.js +349 -0
  18. package/dist/resources/drilling.d.ts +403 -0
  19. package/dist/resources/drilling.js +264 -0
  20. package/dist/resources/ei/drilling-productivity.d.ts +173 -0
  21. package/dist/resources/ei/drilling-productivity.js +103 -0
  22. package/dist/resources/ei/forecasts.d.ts +177 -0
  23. package/dist/resources/ei/forecasts.js +101 -0
  24. package/dist/resources/ei/frac-focus.d.ts +212 -0
  25. package/dist/resources/ei/frac-focus.js +150 -0
  26. package/dist/resources/ei/index.d.ts +140 -0
  27. package/dist/resources/ei/index.js +87 -0
  28. package/dist/resources/ei/oil-inventories.d.ts +155 -0
  29. package/dist/resources/ei/oil-inventories.js +92 -0
  30. package/dist/resources/ei/opec-production.d.ts +146 -0
  31. package/dist/resources/ei/opec-production.js +92 -0
  32. package/dist/resources/ei/rig-counts.d.ts +131 -0
  33. package/dist/resources/ei/rig-counts.js +88 -0
  34. package/dist/resources/ei/well-permits.d.ts +178 -0
  35. package/dist/resources/ei/well-permits.js +119 -0
  36. package/dist/resources/forecasts.d.ts +200 -0
  37. package/dist/resources/forecasts.js +157 -0
  38. package/dist/resources/futures.d.ts +322 -0
  39. package/dist/resources/futures.js +228 -0
  40. package/dist/resources/rig-counts.d.ts +221 -0
  41. package/dist/resources/rig-counts.js +157 -0
  42. package/dist/resources/storage.d.ts +182 -0
  43. package/dist/resources/storage.js +161 -0
  44. package/dist/resources/webhooks.d.ts +290 -0
  45. package/dist/resources/webhooks.js +297 -0
  46. package/dist/types.d.ts +106 -6
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/package.json +3 -3
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Futures Resource
3
+ *
4
+ * Access futures contract data including latest prices, historical data,
5
+ * OHLC, intraday, spreads, curves, and continuous contracts.
6
+ */
7
+ import type { OilPriceAPI } from "../client.js";
8
+ /**
9
+ * Futures contract price data
10
+ */
11
+ export interface FuturesPrice {
12
+ /** Contract symbol */
13
+ contract: string;
14
+ /** Current price */
15
+ price: number;
16
+ /** Formatted price string */
17
+ formatted?: string;
18
+ /** Currency code */
19
+ currency: string;
20
+ /** Contract expiration date */
21
+ expiration?: string;
22
+ /** ISO timestamp when price was recorded */
23
+ timestamp: string;
24
+ /** Additional metadata */
25
+ metadata?: Record<string, unknown>;
26
+ }
27
+ /**
28
+ * Historical futures price data
29
+ */
30
+ export interface HistoricalFuturesPrice {
31
+ /** Contract symbol */
32
+ contract: string;
33
+ /** Price */
34
+ price: number;
35
+ /** ISO timestamp */
36
+ timestamp: string;
37
+ /** Volume */
38
+ volume?: number;
39
+ /** Open interest */
40
+ open_interest?: number;
41
+ }
42
+ /**
43
+ * Options for historical futures query
44
+ */
45
+ export interface HistoricalFuturesOptions {
46
+ /** Start date in ISO 8601 format (YYYY-MM-DD) */
47
+ startDate?: string;
48
+ /** End date in ISO 8601 format (YYYY-MM-DD) */
49
+ endDate?: string;
50
+ }
51
+ /**
52
+ * OHLC (Open, High, Low, Close) data for a futures contract
53
+ */
54
+ export interface FuturesOHLC {
55
+ /** Contract symbol */
56
+ contract: string;
57
+ /** Date for this OHLC data */
58
+ date: string;
59
+ /** Opening price */
60
+ open: number;
61
+ /** Highest price */
62
+ high: number;
63
+ /** Lowest price */
64
+ low: number;
65
+ /** Closing price */
66
+ close: number;
67
+ /** Trading volume */
68
+ volume?: number;
69
+ /** Open interest */
70
+ open_interest?: number;
71
+ }
72
+ /**
73
+ * Intraday price point
74
+ */
75
+ export interface IntradayPrice {
76
+ /** Time of day (e.g., "09:30", "14:00") */
77
+ time: string;
78
+ /** Price at this time */
79
+ price: number;
80
+ /** Volume at this time */
81
+ volume?: number;
82
+ }
83
+ /**
84
+ * Intraday futures data
85
+ */
86
+ export interface IntradayFuturesData {
87
+ /** Contract symbol */
88
+ contract: string;
89
+ /** Date for this intraday data */
90
+ date: string;
91
+ /** Array of intraday price points */
92
+ prices: IntradayPrice[];
93
+ }
94
+ /**
95
+ * Futures spread data
96
+ */
97
+ export interface FuturesSpread {
98
+ /** First contract symbol */
99
+ contract1: string;
100
+ /** Second contract symbol */
101
+ contract2: string;
102
+ /** Spread value (contract1 - contract2) */
103
+ spread: number;
104
+ /** Percentage spread */
105
+ spread_percent?: number;
106
+ /** ISO timestamp */
107
+ timestamp: string;
108
+ }
109
+ /**
110
+ * Futures curve point
111
+ */
112
+ export interface FuturesCurvePoint {
113
+ /** Contract expiration date */
114
+ expiration: string;
115
+ /** Months until expiration */
116
+ months_out: number;
117
+ /** Price */
118
+ price: number;
119
+ /** Contract symbol */
120
+ contract?: string;
121
+ }
122
+ /**
123
+ * Futures curve data
124
+ */
125
+ export interface FuturesCurveData {
126
+ /** Base contract */
127
+ contract: string;
128
+ /** ISO timestamp when curve was generated */
129
+ timestamp: string;
130
+ /** Array of curve points */
131
+ curve: FuturesCurvePoint[];
132
+ }
133
+ /**
134
+ * Continuous contract data point
135
+ */
136
+ export interface ContinuousContractPrice {
137
+ /** Date */
138
+ date: string;
139
+ /** Price */
140
+ price: number;
141
+ /** Active contract at this date */
142
+ active_contract?: string;
143
+ }
144
+ /**
145
+ * Continuous futures contract data
146
+ */
147
+ export interface ContinuousFuturesData {
148
+ /** Base contract */
149
+ contract: string;
150
+ /** Number of months for continuous contract */
151
+ months: number;
152
+ /** Array of continuous prices */
153
+ prices: ContinuousContractPrice[];
154
+ }
155
+ /**
156
+ * Futures Resource
157
+ *
158
+ * Access futures contract data including latest, historical, OHLC, intraday,
159
+ * spreads, curves, and continuous contracts.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * import { OilPriceAPI } from 'oilpriceapi';
164
+ *
165
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
166
+ *
167
+ * // Get latest price
168
+ * const latest = await client.futures.latest('CL.1');
169
+ * console.log(`${latest.contract}: $${latest.price}`);
170
+ *
171
+ * // Get OHLC data
172
+ * const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
173
+ * console.log(`High: $${ohlc.high}, Low: $${ohlc.low}`);
174
+ *
175
+ * // Get futures curve
176
+ * const curve = await client.futures.curve('CL');
177
+ * curve.curve.forEach(point => {
178
+ * console.log(`${point.months_out}mo: $${point.price}`);
179
+ * });
180
+ * ```
181
+ */
182
+ export declare class FuturesResource {
183
+ private client;
184
+ constructor(client: OilPriceAPI);
185
+ /**
186
+ * Get latest price for a futures contract
187
+ *
188
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
189
+ * @returns Latest futures price data
190
+ *
191
+ * @throws {NotFoundError} If contract not found
192
+ * @throws {OilPriceAPIError} If API request fails
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const price = await client.futures.latest('CL.1');
197
+ * console.log(`WTI Front Month: $${price.price}`);
198
+ * ```
199
+ */
200
+ latest(contract: string): Promise<FuturesPrice>;
201
+ /**
202
+ * Get historical prices for a futures contract
203
+ *
204
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
205
+ * @param options - Date range filters
206
+ * @returns Array of historical prices
207
+ *
208
+ * @throws {NotFoundError} If contract not found
209
+ * @throws {OilPriceAPIError} If API request fails
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const history = await client.futures.historical('CL.1', {
214
+ * startDate: '2024-01-01',
215
+ * endDate: '2024-01-31'
216
+ * });
217
+ * console.log(`${history.length} historical prices`);
218
+ * ```
219
+ */
220
+ historical(contract: string, options?: HistoricalFuturesOptions): Promise<HistoricalFuturesPrice[]>;
221
+ /**
222
+ * Get OHLC (Open, High, Low, Close) data for a futures contract
223
+ *
224
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
225
+ * @param date - Optional date in YYYY-MM-DD format (defaults to latest)
226
+ * @returns OHLC data
227
+ *
228
+ * @throws {NotFoundError} If contract not found
229
+ * @throws {OilPriceAPIError} If API request fails
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
234
+ * console.log(`Open: $${ohlc.open}`);
235
+ * console.log(`High: $${ohlc.high}`);
236
+ * console.log(`Low: $${ohlc.low}`);
237
+ * console.log(`Close: $${ohlc.close}`);
238
+ * ```
239
+ */
240
+ ohlc(contract: string, date?: string): Promise<FuturesOHLC>;
241
+ /**
242
+ * Get intraday price data for a futures contract
243
+ *
244
+ * Returns price points throughout the trading day.
245
+ *
246
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
247
+ * @returns Intraday price data
248
+ *
249
+ * @throws {NotFoundError} If contract not found
250
+ * @throws {OilPriceAPIError} If API request fails
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const intraday = await client.futures.intraday('CL.1');
255
+ * intraday.prices.forEach(point => {
256
+ * console.log(`${point.time}: $${point.price}`);
257
+ * });
258
+ * ```
259
+ */
260
+ intraday(contract: string): Promise<IntradayFuturesData>;
261
+ /**
262
+ * Get spread between two futures contracts
263
+ *
264
+ * Calculates the price difference between two contracts (contract1 - contract2).
265
+ *
266
+ * @param contract1 - First contract symbol
267
+ * @param contract2 - Second contract symbol
268
+ * @returns Spread data
269
+ *
270
+ * @throws {NotFoundError} If either contract not found
271
+ * @throws {OilPriceAPIError} If API request fails
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Calculate spread between front month and second month
276
+ * const spread = await client.futures.spreads('CL.1', 'CL.2');
277
+ * console.log(`CL.1 - CL.2 spread: $${spread.spread}`);
278
+ * ```
279
+ */
280
+ spreads(contract1: string, contract2: string): Promise<FuturesSpread>;
281
+ /**
282
+ * Get futures curve for a contract
283
+ *
284
+ * Returns the forward curve showing prices across different expiration dates.
285
+ *
286
+ * @param contract - Base contract symbol (e.g., "CL", "BZ")
287
+ * @returns Futures curve data
288
+ *
289
+ * @throws {NotFoundError} If contract not found
290
+ * @throws {OilPriceAPIError} If API request fails
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const curve = await client.futures.curve('CL');
295
+ * console.log('WTI Futures Curve:');
296
+ * curve.curve.forEach(point => {
297
+ * console.log(`${point.months_out} months: $${point.price}`);
298
+ * });
299
+ * ```
300
+ */
301
+ curve(contract: string): Promise<FuturesCurveData>;
302
+ /**
303
+ * Get continuous futures contract data
304
+ *
305
+ * Returns a continuous time series by rolling contracts before expiration.
306
+ *
307
+ * @param contract - Base contract symbol (e.g., "CL", "BZ")
308
+ * @param months - Number of months for continuous contract (default: 1 for front month)
309
+ * @returns Continuous contract data
310
+ *
311
+ * @throws {NotFoundError} If contract not found
312
+ * @throws {OilPriceAPIError} If API request fails
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // Get continuous front month contract
317
+ * const continuous = await client.futures.continuous('CL', 1);
318
+ * console.log(`${continuous.prices.length} data points`);
319
+ * ```
320
+ */
321
+ continuous(contract: string, months?: number): Promise<ContinuousFuturesData>;
322
+ }
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Futures Resource
3
+ *
4
+ * Access futures contract data including latest prices, historical data,
5
+ * OHLC, intraday, spreads, curves, and continuous contracts.
6
+ */
7
+ /**
8
+ * Futures Resource
9
+ *
10
+ * Access futures contract data including latest, historical, OHLC, intraday,
11
+ * spreads, curves, and continuous contracts.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { OilPriceAPI } from 'oilpriceapi';
16
+ *
17
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
18
+ *
19
+ * // Get latest price
20
+ * const latest = await client.futures.latest('CL.1');
21
+ * console.log(`${latest.contract}: $${latest.price}`);
22
+ *
23
+ * // Get OHLC data
24
+ * const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
25
+ * console.log(`High: $${ohlc.high}, Low: $${ohlc.low}`);
26
+ *
27
+ * // Get futures curve
28
+ * const curve = await client.futures.curve('CL');
29
+ * curve.curve.forEach(point => {
30
+ * console.log(`${point.months_out}mo: $${point.price}`);
31
+ * });
32
+ * ```
33
+ */
34
+ export class FuturesResource {
35
+ constructor(client) {
36
+ this.client = client;
37
+ }
38
+ /**
39
+ * Get latest price for a futures contract
40
+ *
41
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
42
+ * @returns Latest futures price data
43
+ *
44
+ * @throws {NotFoundError} If contract not found
45
+ * @throws {OilPriceAPIError} If API request fails
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const price = await client.futures.latest('CL.1');
50
+ * console.log(`WTI Front Month: $${price.price}`);
51
+ * ```
52
+ */
53
+ async latest(contract) {
54
+ if (!contract || typeof contract !== "string") {
55
+ throw new Error("Contract symbol must be a non-empty string");
56
+ }
57
+ return this.client["request"](`/v1/futures/${contract}`, {});
58
+ }
59
+ /**
60
+ * Get historical prices for a futures contract
61
+ *
62
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
63
+ * @param options - Date range filters
64
+ * @returns Array of historical prices
65
+ *
66
+ * @throws {NotFoundError} If contract not found
67
+ * @throws {OilPriceAPIError} If API request fails
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const history = await client.futures.historical('CL.1', {
72
+ * startDate: '2024-01-01',
73
+ * endDate: '2024-01-31'
74
+ * });
75
+ * console.log(`${history.length} historical prices`);
76
+ * ```
77
+ */
78
+ async historical(contract, options) {
79
+ if (!contract || typeof contract !== "string") {
80
+ throw new Error("Contract symbol must be a non-empty string");
81
+ }
82
+ const params = {};
83
+ if (options?.startDate)
84
+ params.start_date = options.startDate;
85
+ if (options?.endDate)
86
+ params.end_date = options.endDate;
87
+ const response = await this.client["request"](`/v1/futures/${contract}/historical`, params);
88
+ return Array.isArray(response) ? response : response.prices;
89
+ }
90
+ /**
91
+ * Get OHLC (Open, High, Low, Close) data for a futures contract
92
+ *
93
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
94
+ * @param date - Optional date in YYYY-MM-DD format (defaults to latest)
95
+ * @returns OHLC data
96
+ *
97
+ * @throws {NotFoundError} If contract not found
98
+ * @throws {OilPriceAPIError} If API request fails
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
103
+ * console.log(`Open: $${ohlc.open}`);
104
+ * console.log(`High: $${ohlc.high}`);
105
+ * console.log(`Low: $${ohlc.low}`);
106
+ * console.log(`Close: $${ohlc.close}`);
107
+ * ```
108
+ */
109
+ async ohlc(contract, date) {
110
+ if (!contract || typeof contract !== "string") {
111
+ throw new Error("Contract symbol must be a non-empty string");
112
+ }
113
+ const params = {};
114
+ if (date)
115
+ params.date = date;
116
+ return this.client["request"](`/v1/futures/${contract}/ohlc`, params);
117
+ }
118
+ /**
119
+ * Get intraday price data for a futures contract
120
+ *
121
+ * Returns price points throughout the trading day.
122
+ *
123
+ * @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
124
+ * @returns Intraday price data
125
+ *
126
+ * @throws {NotFoundError} If contract not found
127
+ * @throws {OilPriceAPIError} If API request fails
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const intraday = await client.futures.intraday('CL.1');
132
+ * intraday.prices.forEach(point => {
133
+ * console.log(`${point.time}: $${point.price}`);
134
+ * });
135
+ * ```
136
+ */
137
+ async intraday(contract) {
138
+ if (!contract || typeof contract !== "string") {
139
+ throw new Error("Contract symbol must be a non-empty string");
140
+ }
141
+ return this.client["request"](`/v1/futures/${contract}/intraday`, {});
142
+ }
143
+ /**
144
+ * Get spread between two futures contracts
145
+ *
146
+ * Calculates the price difference between two contracts (contract1 - contract2).
147
+ *
148
+ * @param contract1 - First contract symbol
149
+ * @param contract2 - Second contract symbol
150
+ * @returns Spread data
151
+ *
152
+ * @throws {NotFoundError} If either contract not found
153
+ * @throws {OilPriceAPIError} If API request fails
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Calculate spread between front month and second month
158
+ * const spread = await client.futures.spreads('CL.1', 'CL.2');
159
+ * console.log(`CL.1 - CL.2 spread: $${spread.spread}`);
160
+ * ```
161
+ */
162
+ async spreads(contract1, contract2) {
163
+ if (!contract1 || typeof contract1 !== "string") {
164
+ throw new Error("First contract symbol must be a non-empty string");
165
+ }
166
+ if (!contract2 || typeof contract2 !== "string") {
167
+ throw new Error("Second contract symbol must be a non-empty string");
168
+ }
169
+ return this.client["request"]("/v1/futures/spreads", {
170
+ contract1,
171
+ contract2,
172
+ });
173
+ }
174
+ /**
175
+ * Get futures curve for a contract
176
+ *
177
+ * Returns the forward curve showing prices across different expiration dates.
178
+ *
179
+ * @param contract - Base contract symbol (e.g., "CL", "BZ")
180
+ * @returns Futures curve data
181
+ *
182
+ * @throws {NotFoundError} If contract not found
183
+ * @throws {OilPriceAPIError} If API request fails
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const curve = await client.futures.curve('CL');
188
+ * console.log('WTI Futures Curve:');
189
+ * curve.curve.forEach(point => {
190
+ * console.log(`${point.months_out} months: $${point.price}`);
191
+ * });
192
+ * ```
193
+ */
194
+ async curve(contract) {
195
+ if (!contract || typeof contract !== "string") {
196
+ throw new Error("Contract symbol must be a non-empty string");
197
+ }
198
+ return this.client["request"](`/v1/futures/${contract}/curve`, {});
199
+ }
200
+ /**
201
+ * Get continuous futures contract data
202
+ *
203
+ * Returns a continuous time series by rolling contracts before expiration.
204
+ *
205
+ * @param contract - Base contract symbol (e.g., "CL", "BZ")
206
+ * @param months - Number of months for continuous contract (default: 1 for front month)
207
+ * @returns Continuous contract data
208
+ *
209
+ * @throws {NotFoundError} If contract not found
210
+ * @throws {OilPriceAPIError} If API request fails
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * // Get continuous front month contract
215
+ * const continuous = await client.futures.continuous('CL', 1);
216
+ * console.log(`${continuous.prices.length} data points`);
217
+ * ```
218
+ */
219
+ async continuous(contract, months) {
220
+ if (!contract || typeof contract !== "string") {
221
+ throw new Error("Contract symbol must be a non-empty string");
222
+ }
223
+ const params = {};
224
+ if (months !== undefined)
225
+ params.months = months.toString();
226
+ return this.client["request"](`/v1/futures/${contract}/continuous`, params);
227
+ }
228
+ }