oilpriceapi 0.6.0 → 0.8.2
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 +418 -123
- package/dist/cjs/client.js +490 -0
- package/dist/cjs/errors.js +80 -0
- package/dist/cjs/index.js +82 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/alerts.js +387 -0
- package/dist/cjs/resources/analytics.js +226 -0
- package/dist/cjs/resources/bunker-fuels.js +196 -0
- package/dist/cjs/resources/commodities.js +115 -0
- package/dist/cjs/resources/data-quality.js +144 -0
- package/dist/cjs/resources/data-sources.js +297 -0
- package/dist/cjs/resources/diesel.js +119 -0
- package/dist/cjs/resources/drilling.js +269 -0
- package/dist/cjs/resources/ei/drilling-productivity.js +108 -0
- package/dist/cjs/resources/ei/forecasts.js +106 -0
- package/dist/cjs/resources/ei/frac-focus.js +155 -0
- package/dist/cjs/resources/ei/index.js +98 -0
- package/dist/cjs/resources/ei/oil-inventories.js +97 -0
- package/dist/cjs/resources/ei/opec-production.js +97 -0
- package/dist/cjs/resources/ei/rig-counts.js +93 -0
- package/dist/cjs/resources/ei/well-permits.js +124 -0
- package/dist/cjs/resources/forecasts.js +162 -0
- package/dist/cjs/resources/futures.js +233 -0
- package/dist/cjs/resources/rig-counts.js +161 -0
- package/dist/cjs/resources/storage.js +166 -0
- package/dist/cjs/resources/webhooks.js +294 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.js +24 -0
- package/dist/client.d.ts +116 -5
- package/dist/client.js +169 -47
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +25 -16
- package/dist/index.d.ts +45 -6
- package/dist/index.js +40 -3
- package/dist/resources/alerts.d.ts +52 -15
- package/dist/resources/alerts.js +121 -109
- package/dist/resources/analytics.d.ts +325 -0
- package/dist/resources/analytics.js +222 -0
- package/dist/resources/bunker-fuels.d.ts +270 -0
- package/dist/resources/bunker-fuels.js +192 -0
- package/dist/resources/commodities.d.ts +148 -0
- package/dist/resources/commodities.js +111 -0
- package/dist/resources/data-quality.d.ts +229 -0
- package/dist/resources/data-quality.js +140 -0
- package/dist/resources/data-sources.d.ts +365 -0
- package/dist/resources/data-sources.js +293 -0
- package/dist/resources/diesel.d.ts +1 -1
- package/dist/resources/diesel.js +9 -38
- package/dist/resources/drilling.d.ts +403 -0
- package/dist/resources/drilling.js +265 -0
- package/dist/resources/ei/drilling-productivity.d.ts +173 -0
- package/dist/resources/ei/drilling-productivity.js +104 -0
- package/dist/resources/ei/forecasts.d.ts +177 -0
- package/dist/resources/ei/forecasts.js +102 -0
- package/dist/resources/ei/frac-focus.d.ts +212 -0
- package/dist/resources/ei/frac-focus.js +151 -0
- package/dist/resources/ei/index.d.ts +140 -0
- package/dist/resources/ei/index.js +88 -0
- package/dist/resources/ei/oil-inventories.d.ts +155 -0
- package/dist/resources/ei/oil-inventories.js +93 -0
- package/dist/resources/ei/opec-production.d.ts +146 -0
- package/dist/resources/ei/opec-production.js +93 -0
- package/dist/resources/ei/rig-counts.d.ts +131 -0
- package/dist/resources/ei/rig-counts.js +89 -0
- package/dist/resources/ei/well-permits.d.ts +178 -0
- package/dist/resources/ei/well-permits.js +120 -0
- package/dist/resources/forecasts.d.ts +200 -0
- package/dist/resources/forecasts.js +158 -0
- package/dist/resources/futures.d.ts +322 -0
- package/dist/resources/futures.js +229 -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 +162 -0
- package/dist/resources/webhooks.d.ts +326 -0
- package/dist/resources/webhooks.js +290 -0
- package/dist/types.d.ts +79 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/package.json +17 -8
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Resource
|
|
3
|
+
*
|
|
4
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
5
|
+
* correlations, trend detection, spreads, and forecasts.
|
|
6
|
+
*/
|
|
7
|
+
import type { OilPriceAPI } from "../client.js";
|
|
8
|
+
/**
|
|
9
|
+
* Performance metrics for commodities
|
|
10
|
+
*/
|
|
11
|
+
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;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for performance query
|
|
31
|
+
*/
|
|
32
|
+
export interface PerformanceOptions {
|
|
33
|
+
/** Commodity code to analyze */
|
|
34
|
+
commodity?: string;
|
|
35
|
+
/** Number of days to analyze (default: 30) */
|
|
36
|
+
days?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Statistical analysis results
|
|
40
|
+
*/
|
|
41
|
+
export interface StatisticalAnalysis {
|
|
42
|
+
/** Commodity code */
|
|
43
|
+
commodity: string;
|
|
44
|
+
/** 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;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Correlation analysis between two commodities
|
|
71
|
+
*/
|
|
72
|
+
export interface CorrelationAnalysis {
|
|
73
|
+
/** First commodity code */
|
|
74
|
+
commodity1: string;
|
|
75
|
+
/** Second commodity code */
|
|
76
|
+
commodity2: string;
|
|
77
|
+
/** Time period analyzed (in days) */
|
|
78
|
+
period_days: number;
|
|
79
|
+
/** Pearson correlation coefficient (-1 to 1) */
|
|
80
|
+
correlation: number;
|
|
81
|
+
/** Correlation strength description */
|
|
82
|
+
strength?: "strong" | "moderate" | "weak" | "none";
|
|
83
|
+
/** R-squared value */
|
|
84
|
+
r_squared?: number;
|
|
85
|
+
/** ISO timestamp */
|
|
86
|
+
timestamp: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Trend analysis results
|
|
90
|
+
*/
|
|
91
|
+
export interface TrendAnalysis {
|
|
92
|
+
/** Commodity code */
|
|
93
|
+
commodity: string;
|
|
94
|
+
/** 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;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Spread analysis between commodities
|
|
113
|
+
*/
|
|
114
|
+
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;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Forecast data point
|
|
132
|
+
*/
|
|
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;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Price forecast
|
|
147
|
+
*/
|
|
148
|
+
export interface PriceForecast {
|
|
149
|
+
/** 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;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Analytics Resource
|
|
169
|
+
*
|
|
170
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
171
|
+
* correlations, trends, spreads, and forecasts.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
176
|
+
*
|
|
177
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
178
|
+
*
|
|
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);
|
|
186
|
+
* console.log(`Correlation: ${corr.correlation}`);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export declare class AnalyticsResource {
|
|
190
|
+
private client;
|
|
191
|
+
constructor(client: OilPriceAPI);
|
|
192
|
+
/**
|
|
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
|
|
200
|
+
*
|
|
201
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
202
|
+
*
|
|
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
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
performance(options?: PerformanceOptions): Promise<PerformanceMetrics>;
|
|
215
|
+
/**
|
|
216
|
+
* Get statistical analysis for a commodity
|
|
217
|
+
*
|
|
218
|
+
* Returns comprehensive statistical metrics including mean, median,
|
|
219
|
+
* standard deviation, and distribution characteristics.
|
|
220
|
+
*
|
|
221
|
+
* @param commodity - Commodity code to analyze
|
|
222
|
+
* @param days - Number of days to analyze (default: 30)
|
|
223
|
+
* @returns Statistical analysis
|
|
224
|
+
*
|
|
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
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
statistics(commodity: string, days?: number): Promise<StatisticalAnalysis>;
|
|
237
|
+
/**
|
|
238
|
+
* Analyze correlation between two commodities
|
|
239
|
+
*
|
|
240
|
+
* Calculates the Pearson correlation coefficient to measure how closely
|
|
241
|
+
* two commodities move together.
|
|
242
|
+
*
|
|
243
|
+
* @param commodity1 - First commodity code
|
|
244
|
+
* @param commodity2 - Second commodity code
|
|
245
|
+
* @param days - Number of days to analyze (default: 30)
|
|
246
|
+
* @returns Correlation analysis
|
|
247
|
+
*
|
|
248
|
+
* @throws {NotFoundError} If either commodity not found
|
|
249
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```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}`);
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
correlation(commodity1: string, commodity2: string, days?: number): Promise<CorrelationAnalysis>;
|
|
260
|
+
/**
|
|
261
|
+
* Analyze price trend for a commodity
|
|
262
|
+
*
|
|
263
|
+
* Detects trend direction, strength, and key levels (support/resistance).
|
|
264
|
+
*
|
|
265
|
+
* @param commodity - Commodity code to analyze
|
|
266
|
+
* @param days - Number of days to analyze (default: 30)
|
|
267
|
+
* @returns Trend analysis
|
|
268
|
+
*
|
|
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
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
trend(commodity: string, days?: number): Promise<TrendAnalysis>;
|
|
281
|
+
/**
|
|
282
|
+
* Analyze spread between two commodities
|
|
283
|
+
*
|
|
284
|
+
* Calculates current spread and compares to historical patterns.
|
|
285
|
+
*
|
|
286
|
+
* @param commodity1 - First commodity code
|
|
287
|
+
* @param commodity2 - Second commodity code
|
|
288
|
+
* @returns Spread analysis
|
|
289
|
+
*
|
|
290
|
+
* @throws {NotFoundError} If either commodity not found
|
|
291
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```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}`);
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
spread(commodity1: string, commodity2: string): Promise<SpreadAnalysis>;
|
|
302
|
+
/**
|
|
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
|
|
309
|
+
*
|
|
310
|
+
* @throws {NotFoundError} If commodity not found
|
|
311
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
312
|
+
*
|
|
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
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
forecast(commodity: string): Promise<PriceForecast>;
|
|
325
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Resource
|
|
3
|
+
*
|
|
4
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
5
|
+
* correlations, trend detection, spreads, and forecasts.
|
|
6
|
+
*/
|
|
7
|
+
import { ValidationError } from "../errors.js";
|
|
8
|
+
/**
|
|
9
|
+
* Analytics Resource
|
|
10
|
+
*
|
|
11
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
12
|
+
* correlations, trends, spreads, and forecasts.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
17
|
+
*
|
|
18
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
19
|
+
*
|
|
20
|
+
* // Get performance metrics
|
|
21
|
+
* const perf = await client.analytics.performance({ commodity: 'WTI_USD', days: 30 });
|
|
22
|
+
* console.log(`30-day return: ${perf.return_percent}%`);
|
|
23
|
+
* console.log(`Volatility: ${perf.volatility}`);
|
|
24
|
+
*
|
|
25
|
+
* // Analyze correlation
|
|
26
|
+
* const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
|
|
27
|
+
* console.log(`Correlation: ${corr.correlation}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class AnalyticsResource {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get performance metrics for a commodity
|
|
36
|
+
*
|
|
37
|
+
* Returns key performance indicators including returns, volatility,
|
|
38
|
+
* and price range over a specified period.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Analysis parameters
|
|
41
|
+
* @returns Performance metrics
|
|
42
|
+
*
|
|
43
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const metrics = await client.analytics.performance({
|
|
48
|
+
* commodity: 'WTI_USD',
|
|
49
|
+
* days: 30
|
|
50
|
+
* });
|
|
51
|
+
* console.log(`Return: ${metrics.return_percent}%`);
|
|
52
|
+
* console.log(`Volatility: ${metrics.volatility}`);
|
|
53
|
+
* console.log(`High: $${metrics.high}, Low: $${metrics.low}`);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async performance(options) {
|
|
57
|
+
const params = {};
|
|
58
|
+
if (options?.commodity)
|
|
59
|
+
params.commodity = options.commodity;
|
|
60
|
+
if (options?.days)
|
|
61
|
+
params.days = options.days.toString();
|
|
62
|
+
return this.client["request"]("/v1/analytics/performance", params);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get statistical analysis for a commodity
|
|
66
|
+
*
|
|
67
|
+
* Returns comprehensive statistical metrics including mean, median,
|
|
68
|
+
* standard deviation, and distribution characteristics.
|
|
69
|
+
*
|
|
70
|
+
* @param commodity - Commodity code to analyze
|
|
71
|
+
* @param days - Number of days to analyze (default: 30)
|
|
72
|
+
* @returns Statistical analysis
|
|
73
|
+
*
|
|
74
|
+
* @throws {NotFoundError} If commodity not found
|
|
75
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const stats = await client.analytics.statistics('BRENT_CRUDE_USD', 90);
|
|
80
|
+
* console.log(`Mean: $${stats.mean}`);
|
|
81
|
+
* console.log(`Std Dev: ${stats.std_dev}`);
|
|
82
|
+
* console.log(`Range: $${stats.min} - $${stats.max}`);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
async statistics(commodity, days) {
|
|
86
|
+
if (!commodity || typeof commodity !== "string") {
|
|
87
|
+
throw new ValidationError("Commodity code must be a non-empty string");
|
|
88
|
+
}
|
|
89
|
+
const params = { commodity };
|
|
90
|
+
if (days)
|
|
91
|
+
params.days = days.toString();
|
|
92
|
+
return this.client["request"]("/v1/analytics/statistics", params);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Analyze correlation between two commodities
|
|
96
|
+
*
|
|
97
|
+
* Calculates the Pearson correlation coefficient to measure how closely
|
|
98
|
+
* two commodities move together.
|
|
99
|
+
*
|
|
100
|
+
* @param commodity1 - First commodity code
|
|
101
|
+
* @param commodity2 - Second commodity code
|
|
102
|
+
* @param days - Number of days to analyze (default: 30)
|
|
103
|
+
* @returns Correlation analysis
|
|
104
|
+
*
|
|
105
|
+
* @throws {NotFoundError} If either commodity not found
|
|
106
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
|
|
111
|
+
* console.log(`Correlation: ${corr.correlation}`);
|
|
112
|
+
* console.log(`Strength: ${corr.strength}`);
|
|
113
|
+
* console.log(`R-squared: ${corr.r_squared}`);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
async correlation(commodity1, commodity2, days) {
|
|
117
|
+
if (!commodity1 || typeof commodity1 !== "string") {
|
|
118
|
+
throw new ValidationError("First commodity code must be a non-empty string");
|
|
119
|
+
}
|
|
120
|
+
if (!commodity2 || typeof commodity2 !== "string") {
|
|
121
|
+
throw new ValidationError("Second commodity code must be a non-empty string");
|
|
122
|
+
}
|
|
123
|
+
const params = {
|
|
124
|
+
commodity1,
|
|
125
|
+
commodity2,
|
|
126
|
+
};
|
|
127
|
+
if (days)
|
|
128
|
+
params.days = days.toString();
|
|
129
|
+
return this.client["request"]("/v1/analytics/correlation", params);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Analyze price trend for a commodity
|
|
133
|
+
*
|
|
134
|
+
* Detects trend direction, strength, and key levels (support/resistance).
|
|
135
|
+
*
|
|
136
|
+
* @param commodity - Commodity code to analyze
|
|
137
|
+
* @param days - Number of days to analyze (default: 30)
|
|
138
|
+
* @returns Trend analysis
|
|
139
|
+
*
|
|
140
|
+
* @throws {NotFoundError} If commodity not found
|
|
141
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const trend = await client.analytics.trend('WTI_USD', 60);
|
|
146
|
+
* console.log(`Trend: ${trend.trend} (strength: ${trend.strength})`);
|
|
147
|
+
* console.log(`Support: $${trend.support}`);
|
|
148
|
+
* console.log(`Resistance: $${trend.resistance}`);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
async trend(commodity, days) {
|
|
152
|
+
if (!commodity || typeof commodity !== "string") {
|
|
153
|
+
throw new ValidationError("Commodity code must be a non-empty string");
|
|
154
|
+
}
|
|
155
|
+
const params = { commodity };
|
|
156
|
+
if (days)
|
|
157
|
+
params.days = days.toString();
|
|
158
|
+
return this.client["request"]("/v1/analytics/trend", params);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Analyze spread between two commodities
|
|
162
|
+
*
|
|
163
|
+
* Calculates current spread and compares to historical patterns.
|
|
164
|
+
*
|
|
165
|
+
* @param commodity1 - First commodity code
|
|
166
|
+
* @param commodity2 - Second commodity code
|
|
167
|
+
* @returns Spread analysis
|
|
168
|
+
*
|
|
169
|
+
* @throws {NotFoundError} If either commodity not found
|
|
170
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const spread = await client.analytics.spread('BRENT_CRUDE_USD', 'WTI_USD');
|
|
175
|
+
* console.log(`Current spread: $${spread.spread}`);
|
|
176
|
+
* console.log(`Average spread: $${spread.average_spread}`);
|
|
177
|
+
* console.log(`Z-score: ${spread.z_score}`);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
async spread(commodity1, commodity2) {
|
|
181
|
+
if (!commodity1 || typeof commodity1 !== "string") {
|
|
182
|
+
throw new ValidationError("First commodity code must be a non-empty string");
|
|
183
|
+
}
|
|
184
|
+
if (!commodity2 || typeof commodity2 !== "string") {
|
|
185
|
+
throw new ValidationError("Second commodity code must be a non-empty string");
|
|
186
|
+
}
|
|
187
|
+
return this.client["request"]("/v1/analytics/spread", {
|
|
188
|
+
commodity1,
|
|
189
|
+
commodity2,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get price forecast for a commodity
|
|
194
|
+
*
|
|
195
|
+
* Returns forecasted prices with confidence intervals.
|
|
196
|
+
*
|
|
197
|
+
* @param commodity - Commodity code to forecast
|
|
198
|
+
* @returns Price forecast
|
|
199
|
+
*
|
|
200
|
+
* @throws {NotFoundError} If commodity not found
|
|
201
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const forecast = await client.analytics.forecast('WTI_USD');
|
|
206
|
+
* console.log(`Forecast model: ${forecast.model}`);
|
|
207
|
+
* console.log(`Horizon: ${forecast.horizon_days} days`);
|
|
208
|
+
*
|
|
209
|
+
* forecast.forecast.forEach(point => {
|
|
210
|
+
* console.log(`${point.date}: $${point.price} (${point.lower_bound}-${point.upper_bound})`);
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
async forecast(commodity) {
|
|
215
|
+
if (!commodity || typeof commodity !== "string") {
|
|
216
|
+
throw new ValidationError("Commodity code must be a non-empty string");
|
|
217
|
+
}
|
|
218
|
+
return this.client["request"]("/v1/analytics/forecast", {
|
|
219
|
+
commodity,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|