oilpriceapi 0.8.2 → 0.9.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.
Files changed (53) hide show
  1. package/README.md +201 -19
  2. package/dist/cjs/client.js +139 -19
  3. package/dist/cjs/index.js +17 -3
  4. package/dist/cjs/resources/analytics.js +99 -137
  5. package/dist/cjs/resources/bunker-fuels.js +37 -23
  6. package/dist/cjs/resources/data-sources.js +13 -12
  7. package/dist/cjs/resources/ei/frac-focus.js +16 -6
  8. package/dist/cjs/resources/ei/well-permits.js +18 -6
  9. package/dist/cjs/resources/forecasts.js +11 -5
  10. package/dist/cjs/resources/futures.js +244 -16
  11. package/dist/cjs/resources/indicators.js +79 -0
  12. package/dist/cjs/resources/raw.js +128 -0
  13. package/dist/cjs/resources/rig-counts.js +5 -2
  14. package/dist/cjs/resources/spreads.js +105 -0
  15. package/dist/cjs/resources/storage.js +5 -5
  16. package/dist/cjs/resources/streaming.js +350 -0
  17. package/dist/cjs/resources/webhooks.js +3 -14
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/client.d.ts +97 -1
  20. package/dist/client.js +139 -19
  21. package/dist/index.d.ts +12 -3
  22. package/dist/index.js +5 -0
  23. package/dist/resources/analytics.d.ts +147 -214
  24. package/dist/resources/analytics.js +99 -137
  25. package/dist/resources/bunker-fuels.d.ts +35 -12
  26. package/dist/resources/bunker-fuels.js +37 -23
  27. package/dist/resources/data-sources.d.ts +31 -31
  28. package/dist/resources/data-sources.js +13 -12
  29. package/dist/resources/ei/frac-focus.d.ts +23 -9
  30. package/dist/resources/ei/frac-focus.js +16 -6
  31. package/dist/resources/ei/well-permits.d.ts +25 -9
  32. package/dist/resources/ei/well-permits.js +18 -6
  33. package/dist/resources/forecasts.d.ts +4 -1
  34. package/dist/resources/forecasts.js +11 -5
  35. package/dist/resources/futures.d.ts +287 -33
  36. package/dist/resources/futures.js +241 -15
  37. package/dist/resources/indicators.d.ts +170 -0
  38. package/dist/resources/indicators.js +75 -0
  39. package/dist/resources/raw.d.ts +94 -0
  40. package/dist/resources/raw.js +124 -0
  41. package/dist/resources/rig-counts.js +5 -2
  42. package/dist/resources/spreads.d.ts +121 -0
  43. package/dist/resources/spreads.js +101 -0
  44. package/dist/resources/storage.d.ts +5 -4
  45. package/dist/resources/storage.js +5 -5
  46. package/dist/resources/streaming.d.ts +272 -0
  47. package/dist/resources/streaming.js +342 -0
  48. package/dist/resources/webhooks.d.ts +37 -23
  49. package/dist/resources/webhooks.js +3 -14
  50. package/dist/types.d.ts +41 -0
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +7 -1
@@ -3,166 +3,152 @@
3
3
  *
4
4
  * Access advanced analytics including performance metrics, statistical analysis,
5
5
  * correlations, trend detection, spreads, and forecasts.
6
+ *
7
+ * NOTE ON PARAMETERS: The OilPriceAPI analytics controller reads commodity
8
+ * identifiers as `code` / `code1` / `code2` and the lookback window as `period`
9
+ * (in days). Earlier versions of this SDK sent `commodity` / `commodity1` /
10
+ * `commodity2` / `days`, which the API silently ignored (and `correlation`
11
+ * returned "code1 and code2 parameters are required"). These methods now send
12
+ * the parameter names the controller actually reads.
6
13
  */
7
14
  import type { OilPriceAPI } from "../client.js";
8
15
  /**
9
- * Performance metrics for commodities
16
+ * Performance metrics for the authenticated user's API usage.
17
+ *
18
+ * NOTE: `/v1/analytics/performance` returns the user's API usage analytics
19
+ * (request counts, error rate, endpoint breakdown) for a dashboard, NOT
20
+ * commodity price performance. It accepts a `range` of `7d` | `30d` | `90d`.
10
21
  */
11
22
  export interface PerformanceMetrics {
12
- /** Commodity code */
13
- commodity?: string;
14
- /** Time period analyzed (in days) */
15
- period_days: number;
16
- /** Average price over period */
17
- average_price: number;
18
- /** Price volatility (standard deviation) */
19
- volatility: number;
20
- /** Percentage return over period */
21
- return_percent: number;
22
- /** Highest price in period */
23
- high: number;
24
- /** Lowest price in period */
25
- low: number;
26
- /** ISO timestamp */
27
- timestamp: string;
23
+ overview?: Record<string, unknown>;
24
+ dailyUsage?: Array<Record<string, unknown>>;
25
+ hourlyDistribution?: Array<Record<string, unknown>>;
26
+ endpointBreakdown?: Array<Record<string, unknown>>;
27
+ geographicData?: Array<Record<string, unknown>>;
28
+ [key: string]: unknown;
28
29
  }
29
30
  /**
30
31
  * Options for performance query
31
32
  */
32
33
  export interface PerformanceOptions {
33
- /** Commodity code to analyze */
34
- commodity?: string;
35
- /** Number of days to analyze (default: 30) */
36
- days?: number;
34
+ /** Time range for usage analytics: '7d' | '30d' | '90d' (default: '30d') */
35
+ range?: "7d" | "30d" | "90d";
37
36
  }
38
37
  /**
39
38
  * Statistical analysis results
40
39
  */
41
40
  export interface StatisticalAnalysis {
42
41
  /** Commodity code */
43
- commodity: string;
42
+ code: string;
44
43
  /** Time period analyzed (in days) */
45
- period_days: number;
46
- /** Mean price */
47
- mean: number;
48
- /** Median price */
49
- median: number;
50
- /** Standard deviation */
51
- std_dev: number;
52
- /** Variance */
53
- variance: number;
54
- /** Minimum price */
55
- min: number;
56
- /** Maximum price */
57
- max: number;
58
- /** 25th percentile */
59
- percentile_25?: number;
60
- /** 75th percentile */
61
- percentile_75?: number;
62
- /** Skewness */
63
- skewness?: number;
64
- /** Kurtosis */
65
- kurtosis?: number;
66
- /** ISO timestamp */
67
- timestamp: string;
44
+ period: number;
45
+ /** Statistical metrics computed for the commodity */
46
+ statistics: Record<string, unknown>;
47
+ /** Tier of the requesting user */
48
+ tier?: string;
49
+ [key: string]: unknown;
68
50
  }
69
51
  /**
70
52
  * Correlation analysis between two commodities
71
53
  */
72
54
  export interface CorrelationAnalysis {
55
+ /** Response type: 'analysis' | 'rolling' | 'matrix' */
56
+ type?: string;
73
57
  /** First commodity code */
74
- commodity1: string;
58
+ code1?: string;
75
59
  /** Second commodity code */
76
- commodity2: string;
60
+ code2?: string;
77
61
  /** Time period analyzed (in days) */
78
- period_days: number;
62
+ period?: number;
79
63
  /** Pearson correlation coefficient (-1 to 1) */
80
- correlation: number;
64
+ correlation?: number;
81
65
  /** Correlation strength description */
82
- strength?: "strong" | "moderate" | "weak" | "none";
83
- /** R-squared value */
84
- r_squared?: number;
85
- /** ISO timestamp */
86
- timestamp: string;
66
+ strength?: string;
67
+ /** Tier of the requesting user */
68
+ tier?: string;
69
+ [key: string]: unknown;
70
+ }
71
+ /**
72
+ * Options for correlation query
73
+ */
74
+ export interface CorrelationOptions {
75
+ /** Lookback window in days (default: 30) */
76
+ period?: number;
77
+ /** Correlation variant: 'analysis' (default), 'rolling', or 'matrix' */
78
+ type?: "analysis" | "rolling" | "matrix";
79
+ /** Rolling window size in days (only used when type === 'rolling') */
80
+ window?: number;
81
+ /** Comma-separated codes for a correlation matrix (only when type === 'matrix') */
82
+ codes?: string[];
87
83
  }
88
84
  /**
89
85
  * Trend analysis results
90
86
  */
91
87
  export interface TrendAnalysis {
88
+ /** Response type: 'analysis' | 'sma' | 'ema' | 'rsi' | 'levels' */
89
+ type?: string;
92
90
  /** Commodity code */
93
- commodity: string;
91
+ code?: string;
94
92
  /** Time period analyzed (in days) */
95
- period_days: number;
96
- /** Overall trend direction */
97
- trend: "upward" | "downward" | "sideways";
98
- /** Trend strength (0-100) */
99
- strength: number;
100
- /** Slope of trend line */
101
- slope?: number;
102
- /** Price momentum */
103
- momentum?: number;
104
- /** Support level */
105
- support?: number;
106
- /** Resistance level */
107
- resistance?: number;
108
- /** ISO timestamp */
109
- timestamp: string;
93
+ period?: number;
94
+ /** Tier of the requesting user */
95
+ tier?: string;
96
+ [key: string]: unknown;
97
+ }
98
+ /**
99
+ * Options for trend query
100
+ */
101
+ export interface TrendOptions {
102
+ /** Lookback window in days (default: 30) */
103
+ period?: number;
104
+ /** Trend variant: 'analysis' (default), 'sma', 'ema', 'rsi', or 'levels' */
105
+ type?: "analysis" | "sma" | "ema" | "rsi" | "levels";
106
+ /** Moving-average / indicator window (used by sma/ema/rsi) */
107
+ window?: number;
110
108
  }
111
109
  /**
112
- * Spread analysis between commodities
110
+ * Spread analysis for a named commodity spread (e.g. 'wti_brent')
113
111
  */
114
112
  export interface SpreadAnalysis {
115
- /** First commodity code */
116
- commodity1: string;
117
- /** Second commodity code */
118
- commodity2: string;
119
- /** Current spread (commodity1 - commodity2) */
120
- spread: number;
121
- /** Historical average spread */
122
- average_spread?: number;
123
- /** Spread standard deviation */
124
- spread_volatility?: number;
125
- /** Z-score of current spread */
126
- z_score?: number;
127
- /** ISO timestamp */
128
- timestamp: string;
113
+ /** Response type: 'current' | 'historical' */
114
+ type?: string;
115
+ /** The named spread analyzed */
116
+ spread?: string;
117
+ /** Time period analyzed (in days) */
118
+ period?: number;
119
+ /** Tier of the requesting user */
120
+ tier?: string;
121
+ [key: string]: unknown;
129
122
  }
130
123
  /**
131
- * Forecast data point
124
+ * Options for spread query
132
125
  */
133
- export interface ForecastPoint {
134
- /** Forecast date */
135
- date: string;
136
- /** Forecasted price */
137
- price: number;
138
- /** Lower bound of confidence interval */
139
- lower_bound?: number;
140
- /** Upper bound of confidence interval */
141
- upper_bound?: number;
142
- /** Confidence level (e.g., 0.95 for 95%) */
143
- confidence?: number;
126
+ export interface SpreadOptions {
127
+ /** Lookback window in days (default: 30) */
128
+ period?: number;
129
+ /** Spread variant: 'current' (default) or 'historical' */
130
+ type?: "current" | "historical";
144
131
  }
145
132
  /**
146
133
  * Price forecast
147
134
  */
148
135
  export interface PriceForecast {
149
136
  /** Commodity code */
150
- commodity: string;
151
- /** Forecast model used */
152
- model?: string;
153
- /** Forecast horizon (days ahead) */
154
- horizon_days: number;
155
- /** Array of forecast points */
156
- forecast: ForecastPoint[];
157
- /** Model accuracy metrics */
158
- accuracy?: {
159
- /** Mean Absolute Percentage Error */
160
- mape?: number;
161
- /** Root Mean Squared Error */
162
- rmse?: number;
163
- };
164
- /** ISO timestamp when forecast was generated */
165
- timestamp: string;
137
+ code?: string;
138
+ /** Forecast method used */
139
+ method?: string;
140
+ /** Tier of the requesting user */
141
+ tier?: string;
142
+ [key: string]: unknown;
143
+ }
144
+ /**
145
+ * Options for forecast query
146
+ */
147
+ export interface ForecastOptions {
148
+ /** Forecast method (default: 'ema') */
149
+ method?: string;
150
+ /** Lookback window in days (default: 90) */
151
+ period?: number;
166
152
  }
167
153
  /**
168
154
  * Analytics Resource
@@ -176,13 +162,8 @@ export interface PriceForecast {
176
162
  *
177
163
  * const client = new OilPriceAPI({ apiKey: 'your_key' });
178
164
  *
179
- * // Get performance metrics
180
- * const perf = await client.analytics.performance({ commodity: 'WTI_USD', days: 30 });
181
- * console.log(`30-day return: ${perf.return_percent}%`);
182
- * console.log(`Volatility: ${perf.volatility}`);
183
- *
184
- * // Analyze correlation
185
- * const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
165
+ * // Analyze correlation between two commodities (90-day window)
166
+ * const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', { period: 90 });
186
167
  * console.log(`Correlation: ${corr.correlation}`);
187
168
  * ```
188
169
  */
@@ -190,136 +171,88 @@ export declare class AnalyticsResource {
190
171
  private client;
191
172
  constructor(client: OilPriceAPI);
192
173
  /**
193
- * Get performance metrics for a commodity
194
- *
195
- * Returns key performance indicators including returns, volatility,
196
- * and price range over a specified period.
197
- *
198
- * @param options - Analysis parameters
199
- * @returns Performance metrics
174
+ * Get the authenticated user's API usage analytics for the dashboard.
200
175
  *
201
- * @throws {OilPriceAPIError} If API request fails
176
+ * Maps to `GET /v1/analytics/performance`, which reads a `range`
177
+ * parameter (`7d` | `30d` | `90d`).
202
178
  *
203
- * @example
204
- * ```typescript
205
- * const metrics = await client.analytics.performance({
206
- * commodity: 'WTI_USD',
207
- * days: 30
208
- * });
209
- * console.log(`Return: ${metrics.return_percent}%`);
210
- * console.log(`Volatility: ${metrics.volatility}`);
211
- * console.log(`High: $${metrics.high}, Low: $${metrics.low}`);
212
- * ```
179
+ * @param options - `{ range }` (default range '30d')
180
+ * @returns Usage analytics (overview, daily usage, endpoint breakdown, ...)
213
181
  */
214
182
  performance(options?: PerformanceOptions): Promise<PerformanceMetrics>;
215
183
  /**
216
- * Get statistical analysis for a commodity
184
+ * Get statistical analysis for a commodity.
217
185
  *
218
- * Returns comprehensive statistical metrics including mean, median,
219
- * standard deviation, and distribution characteristics.
186
+ * Maps to `GET /v1/analytics/statistics`, which reads `code` and `period`.
220
187
  *
221
- * @param commodity - Commodity code to analyze
222
- * @param days - Number of days to analyze (default: 30)
188
+ * @param code - Commodity code to analyze (e.g. 'WTI_USD')
189
+ * @param period - Lookback window in days (default: 30)
223
190
  * @returns Statistical analysis
224
191
  *
225
- * @throws {NotFoundError} If commodity not found
226
- * @throws {OilPriceAPIError} If API request fails
227
- *
228
- * @example
229
- * ```typescript
230
- * const stats = await client.analytics.statistics('BRENT_CRUDE_USD', 90);
231
- * console.log(`Mean: $${stats.mean}`);
232
- * console.log(`Std Dev: ${stats.std_dev}`);
233
- * console.log(`Range: $${stats.min} - $${stats.max}`);
234
- * ```
192
+ * @throws {ValidationError} If code is empty
235
193
  */
236
- statistics(commodity: string, days?: number): Promise<StatisticalAnalysis>;
194
+ statistics(code: string, period?: number): Promise<StatisticalAnalysis>;
237
195
  /**
238
- * Analyze correlation between two commodities
196
+ * Analyze correlation between two commodities.
239
197
  *
240
- * Calculates the Pearson correlation coefficient to measure how closely
241
- * two commodities move together.
198
+ * Maps to `GET /v1/analytics/correlation`, which reads `code1`, `code2`,
199
+ * `period` and optional `type`, `window`, `codes`.
242
200
  *
243
- * @param commodity1 - First commodity code
244
- * @param commodity2 - Second commodity code
245
- * @param days - Number of days to analyze (default: 30)
201
+ * @param code1 - First commodity code
202
+ * @param code2 - Second commodity code
203
+ * @param options - Lookback window in days, or `{ period, type, window, codes }`
246
204
  * @returns Correlation analysis
247
205
  *
248
- * @throws {NotFoundError} If either commodity not found
249
- * @throws {OilPriceAPIError} If API request fails
206
+ * @throws {ValidationError} If either code is empty
250
207
  *
251
208
  * @example
252
209
  * ```typescript
253
- * const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
254
- * console.log(`Correlation: ${corr.correlation}`);
255
- * console.log(`Strength: ${corr.strength}`);
256
- * console.log(`R-squared: ${corr.r_squared}`);
210
+ * const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', { period: 90 });
211
+ * console.log(corr.correlation);
257
212
  * ```
258
213
  */
259
- correlation(commodity1: string, commodity2: string, days?: number): Promise<CorrelationAnalysis>;
214
+ correlation(code1: string, code2: string, options?: number | CorrelationOptions): Promise<CorrelationAnalysis>;
260
215
  /**
261
- * Analyze price trend for a commodity
216
+ * Analyze price trend for a commodity.
262
217
  *
263
- * Detects trend direction, strength, and key levels (support/resistance).
218
+ * Maps to `GET /v1/analytics/trend`, which reads `code`, `period` and
219
+ * optional `type` ('analysis' | 'sma' | 'ema' | 'rsi' | 'levels') and `window`.
264
220
  *
265
- * @param commodity - Commodity code to analyze
266
- * @param days - Number of days to analyze (default: 30)
221
+ * @param code - Commodity code to analyze
222
+ * @param options - Lookback window in days, or `{ period, type, window }`
267
223
  * @returns Trend analysis
268
224
  *
269
- * @throws {NotFoundError} If commodity not found
270
- * @throws {OilPriceAPIError} If API request fails
271
- *
272
- * @example
273
- * ```typescript
274
- * const trend = await client.analytics.trend('WTI_USD', 60);
275
- * console.log(`Trend: ${trend.trend} (strength: ${trend.strength})`);
276
- * console.log(`Support: $${trend.support}`);
277
- * console.log(`Resistance: $${trend.resistance}`);
278
- * ```
225
+ * @throws {ValidationError} If code is empty
279
226
  */
280
- trend(commodity: string, days?: number): Promise<TrendAnalysis>;
227
+ trend(code: string, options?: number | TrendOptions): Promise<TrendAnalysis>;
281
228
  /**
282
- * Analyze spread between two commodities
283
- *
284
- * Calculates current spread and compares to historical patterns.
229
+ * Analyze a named commodity spread (basis / crack / ratio).
285
230
  *
286
- * @param commodity1 - First commodity code
287
- * @param commodity2 - Second commodity code
288
- * @returns Spread analysis
231
+ * Maps to `GET /v1/analytics/spread`, which reads `spread` (the named spread,
232
+ * e.g. 'wti_brent'), `period` and optional `type` ('current' | 'historical').
233
+ * Call with no `spread` to list the available named spreads.
289
234
  *
290
- * @throws {NotFoundError} If either commodity not found
291
- * @throws {OilPriceAPIError} If API request fails
235
+ * @param spread - Named spread (e.g. 'wti_brent'); omit to list available spreads
236
+ * @param options - Lookback window in days, or `{ period, type }`
237
+ * @returns Spread analysis (or the list of available spreads)
292
238
  *
293
239
  * @example
294
240
  * ```typescript
295
- * const spread = await client.analytics.spread('BRENT_CRUDE_USD', 'WTI_USD');
296
- * console.log(`Current spread: $${spread.spread}`);
297
- * console.log(`Average spread: $${spread.average_spread}`);
298
- * console.log(`Z-score: ${spread.z_score}`);
241
+ * const spread = await client.analytics.spread('wti_brent', { period: 30 });
242
+ * console.log(spread.current_spread);
299
243
  * ```
300
244
  */
301
- spread(commodity1: string, commodity2: string): Promise<SpreadAnalysis>;
245
+ spread(spread?: string, options?: number | SpreadOptions): Promise<SpreadAnalysis>;
302
246
  /**
303
- * Get price forecast for a commodity
304
- *
305
- * Returns forecasted prices with confidence intervals.
306
- *
307
- * @param commodity - Commodity code to forecast
308
- * @returns Price forecast
247
+ * Get a statistical price forecast for a commodity.
309
248
  *
310
- * @throws {NotFoundError} If commodity not found
311
- * @throws {OilPriceAPIError} If API request fails
249
+ * Maps to `GET /v1/analytics/forecast`, which reads `code`, `method`
250
+ * (default 'ema') and `period` (default 90). Call with no `code` to list
251
+ * the available forecast methods.
312
252
  *
313
- * @example
314
- * ```typescript
315
- * const forecast = await client.analytics.forecast('WTI_USD');
316
- * console.log(`Forecast model: ${forecast.model}`);
317
- * console.log(`Horizon: ${forecast.horizon_days} days`);
318
- *
319
- * forecast.forecast.forEach(point => {
320
- * console.log(`${point.date}: $${point.price} (${point.lower_bound}-${point.upper_bound})`);
321
- * });
322
- * ```
253
+ * @param code - Commodity code to forecast; omit to list available methods
254
+ * @param options - `{ method, period }`
255
+ * @returns Price forecast (or the list of available methods)
323
256
  */
324
- forecast(commodity: string): Promise<PriceForecast>;
257
+ forecast(code?: string, options?: ForecastOptions): Promise<PriceForecast>;
325
258
  }