oilpriceapi 0.7.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 +43 -11
- 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 +33 -2
- package/dist/client.js +70 -14
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +25 -16
- package/dist/index.d.ts +16 -2
- package/dist/index.js +24 -1
- package/dist/resources/alerts.js +31 -77
- package/dist/resources/analytics.js +8 -7
- package/dist/resources/bunker-fuels.js +5 -4
- package/dist/resources/commodities.js +2 -1
- package/dist/resources/data-quality.js +2 -1
- package/dist/resources/data-sources.js +21 -77
- package/dist/resources/diesel.d.ts +1 -1
- package/dist/resources/diesel.js +9 -38
- package/dist/resources/drilling.js +2 -1
- package/dist/resources/ei/drilling-productivity.js +2 -1
- package/dist/resources/ei/forecasts.js +2 -1
- package/dist/resources/ei/frac-focus.js +4 -3
- package/dist/resources/ei/index.js +2 -1
- package/dist/resources/ei/oil-inventories.js +2 -1
- package/dist/resources/ei/opec-production.js +2 -1
- package/dist/resources/ei/rig-counts.js +2 -1
- package/dist/resources/ei/well-permits.js +2 -1
- package/dist/resources/forecasts.js +2 -1
- package/dist/resources/futures.js +9 -8
- package/dist/resources/storage.js +2 -1
- package/dist/resources/webhooks.d.ts +36 -0
- package/dist/resources/webhooks.js +60 -67
- package/dist/types.d.ts +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/package.json +15 -6
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Analytics Resource
|
|
4
|
+
*
|
|
5
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
6
|
+
* correlations, trend detection, spreads, and forecasts.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AnalyticsResource = void 0;
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
/**
|
|
12
|
+
* Analytics Resource
|
|
13
|
+
*
|
|
14
|
+
* Access advanced analytics including performance metrics, statistical analysis,
|
|
15
|
+
* correlations, trends, spreads, and forecasts.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
20
|
+
*
|
|
21
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
22
|
+
*
|
|
23
|
+
* // Get performance metrics
|
|
24
|
+
* const perf = await client.analytics.performance({ commodity: 'WTI_USD', days: 30 });
|
|
25
|
+
* console.log(`30-day return: ${perf.return_percent}%`);
|
|
26
|
+
* console.log(`Volatility: ${perf.volatility}`);
|
|
27
|
+
*
|
|
28
|
+
* // Analyze correlation
|
|
29
|
+
* const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
|
|
30
|
+
* console.log(`Correlation: ${corr.correlation}`);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class AnalyticsResource {
|
|
34
|
+
constructor(client) {
|
|
35
|
+
this.client = client;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get performance metrics for a commodity
|
|
39
|
+
*
|
|
40
|
+
* Returns key performance indicators including returns, volatility,
|
|
41
|
+
* and price range over a specified period.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Analysis parameters
|
|
44
|
+
* @returns Performance metrics
|
|
45
|
+
*
|
|
46
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const metrics = await client.analytics.performance({
|
|
51
|
+
* commodity: 'WTI_USD',
|
|
52
|
+
* days: 30
|
|
53
|
+
* });
|
|
54
|
+
* console.log(`Return: ${metrics.return_percent}%`);
|
|
55
|
+
* console.log(`Volatility: ${metrics.volatility}`);
|
|
56
|
+
* console.log(`High: $${metrics.high}, Low: $${metrics.low}`);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
async performance(options) {
|
|
60
|
+
const params = {};
|
|
61
|
+
if (options?.commodity)
|
|
62
|
+
params.commodity = options.commodity;
|
|
63
|
+
if (options?.days)
|
|
64
|
+
params.days = options.days.toString();
|
|
65
|
+
return this.client["request"]("/v1/analytics/performance", params);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get statistical analysis for a commodity
|
|
69
|
+
*
|
|
70
|
+
* Returns comprehensive statistical metrics including mean, median,
|
|
71
|
+
* standard deviation, and distribution characteristics.
|
|
72
|
+
*
|
|
73
|
+
* @param commodity - Commodity code to analyze
|
|
74
|
+
* @param days - Number of days to analyze (default: 30)
|
|
75
|
+
* @returns Statistical analysis
|
|
76
|
+
*
|
|
77
|
+
* @throws {NotFoundError} If commodity not found
|
|
78
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const stats = await client.analytics.statistics('BRENT_CRUDE_USD', 90);
|
|
83
|
+
* console.log(`Mean: $${stats.mean}`);
|
|
84
|
+
* console.log(`Std Dev: ${stats.std_dev}`);
|
|
85
|
+
* console.log(`Range: $${stats.min} - $${stats.max}`);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
async statistics(commodity, days) {
|
|
89
|
+
if (!commodity || typeof commodity !== "string") {
|
|
90
|
+
throw new errors_js_1.ValidationError("Commodity code must be a non-empty string");
|
|
91
|
+
}
|
|
92
|
+
const params = { commodity };
|
|
93
|
+
if (days)
|
|
94
|
+
params.days = days.toString();
|
|
95
|
+
return this.client["request"]("/v1/analytics/statistics", params);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Analyze correlation between two commodities
|
|
99
|
+
*
|
|
100
|
+
* Calculates the Pearson correlation coefficient to measure how closely
|
|
101
|
+
* two commodities move together.
|
|
102
|
+
*
|
|
103
|
+
* @param commodity1 - First commodity code
|
|
104
|
+
* @param commodity2 - Second commodity code
|
|
105
|
+
* @param days - Number of days to analyze (default: 30)
|
|
106
|
+
* @returns Correlation analysis
|
|
107
|
+
*
|
|
108
|
+
* @throws {NotFoundError} If either commodity not found
|
|
109
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const corr = await client.analytics.correlation('WTI_USD', 'BRENT_CRUDE_USD', 90);
|
|
114
|
+
* console.log(`Correlation: ${corr.correlation}`);
|
|
115
|
+
* console.log(`Strength: ${corr.strength}`);
|
|
116
|
+
* console.log(`R-squared: ${corr.r_squared}`);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
async correlation(commodity1, commodity2, days) {
|
|
120
|
+
if (!commodity1 || typeof commodity1 !== "string") {
|
|
121
|
+
throw new errors_js_1.ValidationError("First commodity code must be a non-empty string");
|
|
122
|
+
}
|
|
123
|
+
if (!commodity2 || typeof commodity2 !== "string") {
|
|
124
|
+
throw new errors_js_1.ValidationError("Second commodity code must be a non-empty string");
|
|
125
|
+
}
|
|
126
|
+
const params = {
|
|
127
|
+
commodity1,
|
|
128
|
+
commodity2,
|
|
129
|
+
};
|
|
130
|
+
if (days)
|
|
131
|
+
params.days = days.toString();
|
|
132
|
+
return this.client["request"]("/v1/analytics/correlation", params);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Analyze price trend for a commodity
|
|
136
|
+
*
|
|
137
|
+
* Detects trend direction, strength, and key levels (support/resistance).
|
|
138
|
+
*
|
|
139
|
+
* @param commodity - Commodity code to analyze
|
|
140
|
+
* @param days - Number of days to analyze (default: 30)
|
|
141
|
+
* @returns Trend analysis
|
|
142
|
+
*
|
|
143
|
+
* @throws {NotFoundError} If commodity not found
|
|
144
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const trend = await client.analytics.trend('WTI_USD', 60);
|
|
149
|
+
* console.log(`Trend: ${trend.trend} (strength: ${trend.strength})`);
|
|
150
|
+
* console.log(`Support: $${trend.support}`);
|
|
151
|
+
* console.log(`Resistance: $${trend.resistance}`);
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async trend(commodity, days) {
|
|
155
|
+
if (!commodity || typeof commodity !== "string") {
|
|
156
|
+
throw new errors_js_1.ValidationError("Commodity code must be a non-empty string");
|
|
157
|
+
}
|
|
158
|
+
const params = { commodity };
|
|
159
|
+
if (days)
|
|
160
|
+
params.days = days.toString();
|
|
161
|
+
return this.client["request"]("/v1/analytics/trend", params);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Analyze spread between two commodities
|
|
165
|
+
*
|
|
166
|
+
* Calculates current spread and compares to historical patterns.
|
|
167
|
+
*
|
|
168
|
+
* @param commodity1 - First commodity code
|
|
169
|
+
* @param commodity2 - Second commodity code
|
|
170
|
+
* @returns Spread analysis
|
|
171
|
+
*
|
|
172
|
+
* @throws {NotFoundError} If either commodity not found
|
|
173
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const spread = await client.analytics.spread('BRENT_CRUDE_USD', 'WTI_USD');
|
|
178
|
+
* console.log(`Current spread: $${spread.spread}`);
|
|
179
|
+
* console.log(`Average spread: $${spread.average_spread}`);
|
|
180
|
+
* console.log(`Z-score: ${spread.z_score}`);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
async spread(commodity1, commodity2) {
|
|
184
|
+
if (!commodity1 || typeof commodity1 !== "string") {
|
|
185
|
+
throw new errors_js_1.ValidationError("First commodity code must be a non-empty string");
|
|
186
|
+
}
|
|
187
|
+
if (!commodity2 || typeof commodity2 !== "string") {
|
|
188
|
+
throw new errors_js_1.ValidationError("Second commodity code must be a non-empty string");
|
|
189
|
+
}
|
|
190
|
+
return this.client["request"]("/v1/analytics/spread", {
|
|
191
|
+
commodity1,
|
|
192
|
+
commodity2,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get price forecast for a commodity
|
|
197
|
+
*
|
|
198
|
+
* Returns forecasted prices with confidence intervals.
|
|
199
|
+
*
|
|
200
|
+
* @param commodity - Commodity code to forecast
|
|
201
|
+
* @returns Price forecast
|
|
202
|
+
*
|
|
203
|
+
* @throws {NotFoundError} If commodity not found
|
|
204
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const forecast = await client.analytics.forecast('WTI_USD');
|
|
209
|
+
* console.log(`Forecast model: ${forecast.model}`);
|
|
210
|
+
* console.log(`Horizon: ${forecast.horizon_days} days`);
|
|
211
|
+
*
|
|
212
|
+
* forecast.forecast.forEach(point => {
|
|
213
|
+
* console.log(`${point.date}: $${point.price} (${point.lower_bound}-${point.upper_bound})`);
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
async forecast(commodity) {
|
|
218
|
+
if (!commodity || typeof commodity !== "string") {
|
|
219
|
+
throw new errors_js_1.ValidationError("Commodity code must be a non-empty string");
|
|
220
|
+
}
|
|
221
|
+
return this.client["request"]("/v1/analytics/forecast", {
|
|
222
|
+
commodity,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.AnalyticsResource = AnalyticsResource;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bunker Fuels Resource
|
|
4
|
+
*
|
|
5
|
+
* Access bunker fuel prices at major ports worldwide, including VLSFO, MGO,
|
|
6
|
+
* and IFO380. Compare prices across ports and track historical trends.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BunkerFuelsResource = void 0;
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
/**
|
|
12
|
+
* Bunker Fuels Resource
|
|
13
|
+
*
|
|
14
|
+
* Access bunker fuel prices at major ports worldwide. Track VLSFO, MGO, and
|
|
15
|
+
* IFO380 prices, compare across ports, and analyze historical trends.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
20
|
+
*
|
|
21
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
22
|
+
*
|
|
23
|
+
* // Get all bunker fuel prices
|
|
24
|
+
* const prices = await client.bunkerFuels.all();
|
|
25
|
+
*
|
|
26
|
+
* // Get prices for specific port
|
|
27
|
+
* const singapore = await client.bunkerFuels.port('SIN');
|
|
28
|
+
* console.log(`Singapore VLSFO: $${singapore.prices.VLSFO}/MT`);
|
|
29
|
+
*
|
|
30
|
+
* // Compare prices across ports
|
|
31
|
+
* const comparison = await client.bunkerFuels.compare(['SIN', 'RTM', 'HOU']);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class BunkerFuelsResource {
|
|
35
|
+
constructor(client) {
|
|
36
|
+
this.client = client;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get all current bunker fuel prices
|
|
40
|
+
*
|
|
41
|
+
* Returns prices for all tracked ports and fuel types.
|
|
42
|
+
*
|
|
43
|
+
* @returns Array of bunker fuel prices
|
|
44
|
+
*
|
|
45
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
46
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const prices = await client.bunkerFuels.all();
|
|
51
|
+
* prices.forEach(price => {
|
|
52
|
+
* console.log(`${price.port_name} ${price.fuel_type}: $${price.price}/${price.unit}`);
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async all() {
|
|
57
|
+
const response = await this.client["request"]("/v1/bunker-fuels", {});
|
|
58
|
+
return Array.isArray(response) ? response : response.prices;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get bunker fuel prices for a specific port
|
|
62
|
+
*
|
|
63
|
+
* @param code - Port code (e.g., "SIN" for Singapore, "RTM" for Rotterdam)
|
|
64
|
+
* @returns Port-specific prices across fuel types
|
|
65
|
+
*
|
|
66
|
+
* @throws {NotFoundError} If port code not found
|
|
67
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const singapore = await client.bunkerFuels.port('SIN');
|
|
72
|
+
* console.log(`Singapore Bunker Prices (${singapore.timestamp}):`);
|
|
73
|
+
* console.log(`VLSFO: $${singapore.prices.VLSFO}/${singapore.unit}`);
|
|
74
|
+
* console.log(`MGO: $${singapore.prices.MGO}/${singapore.unit}`);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
async port(code) {
|
|
78
|
+
if (!code || typeof code !== "string") {
|
|
79
|
+
throw new errors_js_1.ValidationError("Port code must be a non-empty string");
|
|
80
|
+
}
|
|
81
|
+
return this.client["request"](`/v1/bunker-fuels/ports/${code}`, {});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Compare prices across multiple ports
|
|
85
|
+
*
|
|
86
|
+
* @param ports - Array of port codes to compare
|
|
87
|
+
* @returns Price comparison data
|
|
88
|
+
*
|
|
89
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const comparison = await client.bunkerFuels.compare(['SIN', 'RTM', 'HOU', 'FUJ']);
|
|
94
|
+
*
|
|
95
|
+
* console.log(`Comparing ${comparison.fuel_type} prices:`);
|
|
96
|
+
* comparison.ports.forEach((port, index) => {
|
|
97
|
+
* console.log(`${index + 1}. ${port.port_name}: $${port.price}`);
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async compare(ports) {
|
|
102
|
+
if (!Array.isArray(ports) || ports.length === 0) {
|
|
103
|
+
throw new errors_js_1.ValidationError("Ports must be a non-empty array of port codes");
|
|
104
|
+
}
|
|
105
|
+
return this.client["request"]("/v1/bunker-fuels/compare", {
|
|
106
|
+
ports: ports.join(","),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get bunker fuel price spreads
|
|
111
|
+
*
|
|
112
|
+
* Returns spreads between different fuel grades (e.g., VLSFO-IFO380).
|
|
113
|
+
*
|
|
114
|
+
* @returns Fuel price spreads
|
|
115
|
+
*
|
|
116
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const spreads = await client.bunkerFuels.spreads();
|
|
121
|
+
* spreads.spreads.forEach(spread => {
|
|
122
|
+
* console.log(`${spread.fuel1}-${spread.fuel2} spread: $${spread.average_spread}`);
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
async spreads() {
|
|
127
|
+
return this.client["request"]("/v1/bunker-fuels/spreads", {});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get historical bunker fuel prices
|
|
131
|
+
*
|
|
132
|
+
* @param port - Port code (e.g., "SIN", "RTM")
|
|
133
|
+
* @param fuelType - Fuel type (e.g., "VLSFO", "MGO", "IFO380")
|
|
134
|
+
* @param options - Date range filters
|
|
135
|
+
* @returns Array of historical prices
|
|
136
|
+
*
|
|
137
|
+
* @throws {NotFoundError} If port or fuel type not found
|
|
138
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const history = await client.bunkerFuels.historical('SIN', 'VLSFO', {
|
|
143
|
+
* startDate: '2024-01-01',
|
|
144
|
+
* endDate: '2024-12-31'
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* history.forEach(point => {
|
|
148
|
+
* console.log(`${point.date}: $${point.price}/${point.unit}`);
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
async historical(port, fuelType, options) {
|
|
153
|
+
if (!port || typeof port !== "string") {
|
|
154
|
+
throw new errors_js_1.ValidationError("Port code must be a non-empty string");
|
|
155
|
+
}
|
|
156
|
+
if (!fuelType || typeof fuelType !== "string") {
|
|
157
|
+
throw new errors_js_1.ValidationError("Fuel type must be a non-empty string");
|
|
158
|
+
}
|
|
159
|
+
const params = {
|
|
160
|
+
port,
|
|
161
|
+
fuel_type: fuelType,
|
|
162
|
+
};
|
|
163
|
+
if (options?.startDate)
|
|
164
|
+
params.start_date = options.startDate;
|
|
165
|
+
if (options?.endDate)
|
|
166
|
+
params.end_date = options.endDate;
|
|
167
|
+
const response = await this.client["request"]("/v1/bunker-fuels/historical", params);
|
|
168
|
+
return Array.isArray(response) ? response : response.data;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Export bunker fuel data
|
|
172
|
+
*
|
|
173
|
+
* Export bunker fuel prices in specified format (CSV, JSON, Excel).
|
|
174
|
+
*
|
|
175
|
+
* @param format - Export format (default: "csv")
|
|
176
|
+
* @returns Export data or download URL
|
|
177
|
+
*
|
|
178
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // Export as CSV
|
|
183
|
+
* const csvData = await client.bunkerFuels.export('csv');
|
|
184
|
+
*
|
|
185
|
+
* // Export as JSON
|
|
186
|
+
* const jsonData = await client.bunkerFuels.export('json');
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
async export(format) {
|
|
190
|
+
const params = {};
|
|
191
|
+
if (format)
|
|
192
|
+
params.format = format;
|
|
193
|
+
return this.client["request"]("/v1/bunker-fuels/export", params);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.BunkerFuelsResource = BunkerFuelsResource;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Commodities Resource
|
|
4
|
+
*
|
|
5
|
+
* Get metadata about supported commodities and categories.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CommoditiesResource = void 0;
|
|
9
|
+
const errors_js_1 = require("../errors.js");
|
|
10
|
+
/**
|
|
11
|
+
* Commodities Resource
|
|
12
|
+
*
|
|
13
|
+
* Access metadata about supported commodities and categories.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
18
|
+
*
|
|
19
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
20
|
+
*
|
|
21
|
+
* // List all commodities
|
|
22
|
+
* const response = await client.commodities.list();
|
|
23
|
+
* console.log(`${response.commodities.length} commodities available`);
|
|
24
|
+
*
|
|
25
|
+
* // Get specific commodity
|
|
26
|
+
* const wti = await client.commodities.get('WTI_USD');
|
|
27
|
+
* console.log(`${wti.name}: ${wti.description}`);
|
|
28
|
+
*
|
|
29
|
+
* // Get categories
|
|
30
|
+
* const categories = await client.commodities.categories();
|
|
31
|
+
* console.log(`Oil category has ${categories.oil.commodities.length} commodities`);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class CommoditiesResource {
|
|
35
|
+
constructor(client) {
|
|
36
|
+
this.client = client;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* List all supported commodities
|
|
40
|
+
*
|
|
41
|
+
* Returns metadata for all commodities available in the API, including
|
|
42
|
+
* codes, names, units, and validation ranges.
|
|
43
|
+
*
|
|
44
|
+
* @returns Object containing array of commodities
|
|
45
|
+
*
|
|
46
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
47
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const response = await client.commodities.list();
|
|
52
|
+
*
|
|
53
|
+
* response.commodities.forEach(commodity => {
|
|
54
|
+
* console.log(`${commodity.code}: ${commodity.name} (${commodity.unit})`);
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async list() {
|
|
59
|
+
return this.client["request"]("/v1/commodities", {});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get metadata for a specific commodity by code
|
|
63
|
+
*
|
|
64
|
+
* @param code - Commodity code (e.g., "WTI_USD", "BRENT_CRUDE_USD")
|
|
65
|
+
* @returns Commodity metadata object
|
|
66
|
+
*
|
|
67
|
+
* @throws {NotFoundError} If commodity code is invalid
|
|
68
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
69
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const commodity = await client.commodities.get('WTI_USD');
|
|
74
|
+
* console.log(`Name: ${commodity.name}`);
|
|
75
|
+
* console.log(`Unit: ${commodity.unit}`);
|
|
76
|
+
* console.log(`Currency: ${commodity.currency}`);
|
|
77
|
+
* console.log(`Category: ${commodity.category}`);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
async get(code) {
|
|
81
|
+
if (!code || typeof code !== "string") {
|
|
82
|
+
throw new errors_js_1.ValidationError("Commodity code must be a non-empty string");
|
|
83
|
+
}
|
|
84
|
+
return this.client["request"](`/v1/commodities/${code}`, {});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get all commodity categories with their commodities
|
|
88
|
+
*
|
|
89
|
+
* Returns commodities grouped by category (oil, gas, renewable, etc.).
|
|
90
|
+
* Useful for building navigation or filtering UIs.
|
|
91
|
+
*
|
|
92
|
+
* @returns Object with category keys mapped to category objects
|
|
93
|
+
*
|
|
94
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
95
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const categories = await client.commodities.categories();
|
|
100
|
+
*
|
|
101
|
+
* // Access by category key
|
|
102
|
+
* console.log(`Oil: ${categories.oil.name}`);
|
|
103
|
+
* console.log(`Commodities: ${categories.oil.commodities.length}`);
|
|
104
|
+
*
|
|
105
|
+
* // Iterate all categories
|
|
106
|
+
* Object.entries(categories).forEach(([key, category]) => {
|
|
107
|
+
* console.log(`${category.name}: ${category.commodities.length} commodities`);
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
async categories() {
|
|
112
|
+
return this.client["request"]("/v1/commodities/categories", {});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CommoditiesResource = CommoditiesResource;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Data Quality Resource
|
|
4
|
+
*
|
|
5
|
+
* Access data quality metrics, reports, and monitoring for commodity price data.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DataQualityResource = void 0;
|
|
9
|
+
const errors_js_1 = require("../errors.js");
|
|
10
|
+
/**
|
|
11
|
+
* Data Quality Resource
|
|
12
|
+
*
|
|
13
|
+
* Monitor data quality metrics and access detailed quality reports for
|
|
14
|
+
* commodity price data sources.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
19
|
+
*
|
|
20
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
21
|
+
*
|
|
22
|
+
* // Get quality summary
|
|
23
|
+
* const summary = await client.dataQuality.summary();
|
|
24
|
+
* console.log(`Overall quality: ${summary.overall_score}/100`);
|
|
25
|
+
* console.log(`Sources monitored: ${summary.sources_monitored}`);
|
|
26
|
+
*
|
|
27
|
+
* // Get all reports
|
|
28
|
+
* const reports = await client.dataQuality.reports();
|
|
29
|
+
* reports.forEach(report => {
|
|
30
|
+
* console.log(`${report.name}: ${report.status}`);
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class DataQualityResource {
|
|
35
|
+
constructor(client) {
|
|
36
|
+
this.client = client;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get data quality summary
|
|
40
|
+
*
|
|
41
|
+
* Returns overall data quality metrics and recent alerts.
|
|
42
|
+
*
|
|
43
|
+
* @returns Data quality summary
|
|
44
|
+
*
|
|
45
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
46
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const summary = await client.dataQuality.summary();
|
|
51
|
+
*
|
|
52
|
+
* console.log(`Overall score: ${summary.overall_score}/100`);
|
|
53
|
+
* console.log(`Completeness: ${summary.breakdown.completeness}%`);
|
|
54
|
+
* console.log(`Timeliness: ${summary.breakdown.timeliness}%`);
|
|
55
|
+
* console.log(`Accuracy: ${summary.breakdown.accuracy}%`);
|
|
56
|
+
* console.log(`Consistency: ${summary.breakdown.consistency}%`);
|
|
57
|
+
*
|
|
58
|
+
* if (summary.recent_alerts && summary.recent_alerts.length > 0) {
|
|
59
|
+
* console.log('\nRecent Alerts:');
|
|
60
|
+
* summary.recent_alerts.forEach(alert => {
|
|
61
|
+
* console.log(`[${alert.severity.toUpperCase()}] ${alert.message}`);
|
|
62
|
+
* });
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async summary() {
|
|
67
|
+
return this.client["request"]("/v1/data-quality/summary", {});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get all data quality reports
|
|
71
|
+
*
|
|
72
|
+
* Returns metadata for all available quality reports.
|
|
73
|
+
*
|
|
74
|
+
* @returns Array of report metadata
|
|
75
|
+
*
|
|
76
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
77
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const reports = await client.dataQuality.reports();
|
|
82
|
+
*
|
|
83
|
+
* console.log(`${reports.length} quality reports available:\n`);
|
|
84
|
+
* reports.forEach(report => {
|
|
85
|
+
* console.log(`${report.name}`);
|
|
86
|
+
* console.log(` Code: ${report.code}`);
|
|
87
|
+
* console.log(` Scope: ${report.scope}`);
|
|
88
|
+
* console.log(` Status: ${report.status}`);
|
|
89
|
+
* console.log(` Last generated: ${report.last_generated}\n`);
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
async reports() {
|
|
94
|
+
const response = await this.client["request"]("/v1/data-quality/reports", {});
|
|
95
|
+
return Array.isArray(response) ? response : response.reports;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get detailed data quality report
|
|
99
|
+
*
|
|
100
|
+
* Returns comprehensive quality analysis for a specific source or commodity.
|
|
101
|
+
*
|
|
102
|
+
* @param code - Report code (e.g., "WTI_USD", "BRENT_CRUDE_USD", "EIA")
|
|
103
|
+
* @returns Detailed quality report
|
|
104
|
+
*
|
|
105
|
+
* @throws {NotFoundError} If report code not found
|
|
106
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const report = await client.dataQuality.report('WTI_USD');
|
|
111
|
+
*
|
|
112
|
+
* console.log(`Report: ${report.name}`);
|
|
113
|
+
* console.log(`Scope: ${report.scope}`);
|
|
114
|
+
* console.log(`Period: ${report.period.start} to ${report.period.end}\n`);
|
|
115
|
+
*
|
|
116
|
+
* console.log('Metrics:');
|
|
117
|
+
* console.log(` Completeness: ${report.metrics.completeness}%`);
|
|
118
|
+
* console.log(` Timeliness: ${report.metrics.timeliness}%`);
|
|
119
|
+
* console.log(` Accuracy: ${report.metrics.accuracy}%`);
|
|
120
|
+
* console.log(` Consistency: ${report.metrics.consistency}%`);
|
|
121
|
+
*
|
|
122
|
+
* if (report.issues && report.issues.length > 0) {
|
|
123
|
+
* console.log('\nIssues:');
|
|
124
|
+
* report.issues.forEach(issue => {
|
|
125
|
+
* console.log(` [${issue.severity.toUpperCase()}] ${issue.description}`);
|
|
126
|
+
* });
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* if (report.recommendations && report.recommendations.length > 0) {
|
|
130
|
+
* console.log('\nRecommendations:');
|
|
131
|
+
* report.recommendations.forEach(rec => {
|
|
132
|
+
* console.log(` - ${rec}`);
|
|
133
|
+
* });
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
async report(code) {
|
|
138
|
+
if (!code || typeof code !== "string") {
|
|
139
|
+
throw new errors_js_1.ValidationError("Report code must be a non-empty string");
|
|
140
|
+
}
|
|
141
|
+
return this.client["request"](`/v1/data-quality/reports/${code}`, {});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.DataQualityResource = DataQualityResource;
|