oilpriceapi 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -30
- package/dist/cjs/client.js +610 -0
- package/dist/cjs/errors.js +80 -0
- package/dist/cjs/index.js +96 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/alerts.js +387 -0
- package/dist/cjs/resources/analytics.js +188 -0
- package/dist/cjs/resources/bunker-fuels.js +210 -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 +298 -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 +165 -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 +136 -0
- package/dist/cjs/resources/forecasts.js +168 -0
- package/dist/cjs/resources/futures.js +424 -0
- package/dist/cjs/resources/indicators.js +79 -0
- package/dist/cjs/resources/raw.js +128 -0
- package/dist/cjs/resources/rig-counts.js +164 -0
- package/dist/cjs/resources/spreads.js +105 -0
- package/dist/cjs/resources/storage.js +166 -0
- package/dist/cjs/resources/streaming.js +350 -0
- package/dist/cjs/resources/webhooks.js +283 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.js +24 -0
- package/dist/client.d.ts +130 -3
- package/dist/client.js +206 -30
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +25 -16
- package/dist/index.d.ts +28 -5
- package/dist/index.js +29 -1
- package/dist/resources/alerts.js +31 -77
- package/dist/resources/analytics.d.ts +147 -214
- package/dist/resources/analytics.js +104 -141
- package/dist/resources/bunker-fuels.d.ts +35 -12
- package/dist/resources/bunker-fuels.js +41 -26
- package/dist/resources/commodities.js +2 -1
- package/dist/resources/data-quality.js +2 -1
- package/dist/resources/data-sources.d.ts +31 -31
- package/dist/resources/data-sources.js +30 -85
- 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.d.ts +23 -9
- package/dist/resources/ei/frac-focus.js +20 -9
- 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.d.ts +25 -9
- package/dist/resources/ei/well-permits.js +20 -7
- package/dist/resources/forecasts.d.ts +4 -1
- package/dist/resources/forecasts.js +13 -6
- package/dist/resources/futures.d.ts +178 -1
- package/dist/resources/futures.js +199 -8
- package/dist/resources/indicators.d.ts +170 -0
- package/dist/resources/indicators.js +75 -0
- package/dist/resources/raw.d.ts +94 -0
- package/dist/resources/raw.js +124 -0
- package/dist/resources/rig-counts.js +5 -2
- package/dist/resources/spreads.d.ts +121 -0
- package/dist/resources/spreads.js +101 -0
- package/dist/resources/storage.d.ts +5 -4
- package/dist/resources/storage.js +7 -6
- package/dist/resources/streaming.d.ts +272 -0
- package/dist/resources/streaming.js +342 -0
- package/dist/resources/webhooks.d.ts +73 -23
- package/dist/resources/webhooks.js +59 -77
- package/dist/types.d.ts +43 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/package.json +21 -6
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Futures Resource
|
|
4
|
+
*
|
|
5
|
+
* Access futures contract data including latest prices, historical data,
|
|
6
|
+
* OHLC, intraday, spreads, curves, and continuous contracts.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FuturesResource = exports.FuturesContractFamily = exports.FUTURES_FAMILY_SLUGS = exports.FUTURES_CONTRACTS = void 0;
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
/**
|
|
12
|
+
* Ergonomic contract codes for the most-requested futures families (issue #1).
|
|
13
|
+
*
|
|
14
|
+
* Use with the generic {@link FuturesResource} methods, or use the typed
|
|
15
|
+
* {@link FuturesResource.family} helper for direct access to a family's
|
|
16
|
+
* endpoints.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { FUTURES_CONTRACTS } from 'oilpriceapi';
|
|
21
|
+
*
|
|
22
|
+
* const brent = await client.futures.latest(FUTURES_CONTRACTS.BRENT); // "BZ"
|
|
23
|
+
* const gasoil = await client.futures.family('ice-gasoil').latest();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
exports.FUTURES_CONTRACTS = {
|
|
27
|
+
/** ICE Brent crude */
|
|
28
|
+
BRENT: "BZ",
|
|
29
|
+
/** NYMEX WTI crude */
|
|
30
|
+
WTI: "CL",
|
|
31
|
+
/** ICE Gasoil */
|
|
32
|
+
GASOIL: "G",
|
|
33
|
+
/** Henry Hub natural gas */
|
|
34
|
+
NATURAL_GAS: "NG",
|
|
35
|
+
/** TTF natural gas (Europe) */
|
|
36
|
+
TTF_GAS: "TTF",
|
|
37
|
+
/** LNG JKM (Asia) */
|
|
38
|
+
LNG_JKM: "JKM",
|
|
39
|
+
/** EU carbon allowance */
|
|
40
|
+
EUA_CARBON: "EUA",
|
|
41
|
+
/** UK carbon allowance */
|
|
42
|
+
UK_CARBON: "UKA",
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Mapping of ergonomic contract codes to their API contract-family slugs.
|
|
46
|
+
*
|
|
47
|
+
* Lets you resolve a contract code (e.g., `"BZ"`) to the `/v1/futures/{slug}`
|
|
48
|
+
* path segment used by the typed family helpers.
|
|
49
|
+
*/
|
|
50
|
+
exports.FUTURES_FAMILY_SLUGS = {
|
|
51
|
+
[exports.FUTURES_CONTRACTS.BRENT]: "ice-brent",
|
|
52
|
+
[exports.FUTURES_CONTRACTS.WTI]: "ice-wti",
|
|
53
|
+
[exports.FUTURES_CONTRACTS.GASOIL]: "ice-gasoil",
|
|
54
|
+
[exports.FUTURES_CONTRACTS.NATURAL_GAS]: "natural-gas",
|
|
55
|
+
[exports.FUTURES_CONTRACTS.TTF_GAS]: "ttf-gas",
|
|
56
|
+
[exports.FUTURES_CONTRACTS.LNG_JKM]: "lng-jkm",
|
|
57
|
+
[exports.FUTURES_CONTRACTS.EUA_CARBON]: "eua-carbon",
|
|
58
|
+
[exports.FUTURES_CONTRACTS.UK_CARBON]: "uk-carbon",
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Typed helper for a single futures contract family (e.g., ICE Brent, Gasoil).
|
|
62
|
+
*
|
|
63
|
+
* Provides ergonomic access to the family's endpoints without having to
|
|
64
|
+
* remember the URL slug. Obtain an instance via {@link FuturesResource.family},
|
|
65
|
+
* {@link FuturesResource.brent}, {@link FuturesResource.gasoil}, etc.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const gasoil = client.futures.gasoil();
|
|
70
|
+
* const latest = await gasoil.latest();
|
|
71
|
+
* const curve = await gasoil.curve();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
class FuturesContractFamily {
|
|
75
|
+
constructor(client,
|
|
76
|
+
/** The contract-family slug used in the API path. */
|
|
77
|
+
slug) {
|
|
78
|
+
this.client = client;
|
|
79
|
+
this.slug = slug;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the latest price for this contract family.
|
|
83
|
+
*/
|
|
84
|
+
async latest() {
|
|
85
|
+
return this.client["request"](`/v1/futures/${this.slug}/latest`, {});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get historical prices for this contract family.
|
|
89
|
+
*
|
|
90
|
+
* @param options - Optional date range filters.
|
|
91
|
+
*/
|
|
92
|
+
async historical(options) {
|
|
93
|
+
const params = {};
|
|
94
|
+
if (options?.startDate)
|
|
95
|
+
params.from = options.startDate;
|
|
96
|
+
if (options?.endDate)
|
|
97
|
+
params.to = options.endDate;
|
|
98
|
+
if (options?.interval)
|
|
99
|
+
params.interval = options.interval;
|
|
100
|
+
if (options?.contracts)
|
|
101
|
+
params.contracts = options.contracts;
|
|
102
|
+
const response = await this.client["request"](`/v1/futures/${this.slug}/historical`, params);
|
|
103
|
+
return Array.isArray(response) ? response : response.prices;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get OHLC data for this contract family.
|
|
107
|
+
*
|
|
108
|
+
* @param options - `{ days, contract, interval }` (the API has no `date` param here).
|
|
109
|
+
*/
|
|
110
|
+
async ohlc(options) {
|
|
111
|
+
const params = {};
|
|
112
|
+
if (options?.days !== undefined)
|
|
113
|
+
params.days = options.days.toString();
|
|
114
|
+
if (options?.contract)
|
|
115
|
+
params.contract = options.contract;
|
|
116
|
+
if (options?.interval)
|
|
117
|
+
params.interval = options.interval;
|
|
118
|
+
return this.client["request"](`/v1/futures/${this.slug}/ohlc`, params);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get intraday price data for this contract family.
|
|
122
|
+
*/
|
|
123
|
+
async intraday() {
|
|
124
|
+
return this.client["request"](`/v1/futures/${this.slug}/intraday`, {});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the spreads for this contract family.
|
|
128
|
+
*/
|
|
129
|
+
async spreads() {
|
|
130
|
+
const response = await this.client["request"](`/v1/futures/${this.slug}/spreads`, {});
|
|
131
|
+
return Array.isArray(response) ? response : response.data;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the forward curve for this contract family.
|
|
135
|
+
*/
|
|
136
|
+
async curve() {
|
|
137
|
+
return this.client["request"](`/v1/futures/${this.slug}/curve`, {});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get historical spread data for this contract family.
|
|
141
|
+
*/
|
|
142
|
+
async spreadHistory() {
|
|
143
|
+
return this.client["request"](`/v1/futures/${this.slug}/spread-history`, {});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.FuturesContractFamily = FuturesContractFamily;
|
|
147
|
+
/**
|
|
148
|
+
* Futures Resource
|
|
149
|
+
*
|
|
150
|
+
* Access futures contract data including latest, historical, OHLC, intraday,
|
|
151
|
+
* spreads, curves, and continuous contracts.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
156
|
+
*
|
|
157
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
158
|
+
*
|
|
159
|
+
* // Get latest price
|
|
160
|
+
* const latest = await client.futures.latest('CL.1');
|
|
161
|
+
* console.log(`${latest.contract}: $${latest.price}`);
|
|
162
|
+
*
|
|
163
|
+
* // Get OHLC data
|
|
164
|
+
* const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
|
|
165
|
+
* console.log(`High: $${ohlc.high}, Low: $${ohlc.low}`);
|
|
166
|
+
*
|
|
167
|
+
* // Get futures curve
|
|
168
|
+
* const curve = await client.futures.curve('CL');
|
|
169
|
+
* curve.curve.forEach(point => {
|
|
170
|
+
* console.log(`${point.months_out}mo: $${point.price}`);
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
class FuturesResource {
|
|
175
|
+
constructor(client) {
|
|
176
|
+
this.client = client;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get latest price for a futures contract
|
|
180
|
+
*
|
|
181
|
+
* @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
|
|
182
|
+
* @returns Latest futures price data
|
|
183
|
+
*
|
|
184
|
+
* @throws {NotFoundError} If contract not found
|
|
185
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const price = await client.futures.latest('CL.1');
|
|
190
|
+
* console.log(`WTI Front Month: $${price.price}`);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async latest(contract) {
|
|
194
|
+
if (!contract || typeof contract !== "string") {
|
|
195
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
196
|
+
}
|
|
197
|
+
return this.client["request"](`/v1/futures/${contract}`, {});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get historical prices for a futures contract
|
|
201
|
+
*
|
|
202
|
+
* @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
|
|
203
|
+
* @param options - Date range filters
|
|
204
|
+
* @returns Array of historical prices
|
|
205
|
+
*
|
|
206
|
+
* @throws {NotFoundError} If contract not found
|
|
207
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const history = await client.futures.historical('CL.1', {
|
|
212
|
+
* startDate: '2024-01-01',
|
|
213
|
+
* endDate: '2024-01-31'
|
|
214
|
+
* });
|
|
215
|
+
* console.log(`${history.length} historical prices`);
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
async historical(contract, options) {
|
|
219
|
+
if (!contract || typeof contract !== "string") {
|
|
220
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
221
|
+
}
|
|
222
|
+
const params = {};
|
|
223
|
+
if (options?.startDate)
|
|
224
|
+
params.start_date = options.startDate;
|
|
225
|
+
if (options?.endDate)
|
|
226
|
+
params.end_date = options.endDate;
|
|
227
|
+
const response = await this.client["request"](`/v1/futures/${contract}/historical`, params);
|
|
228
|
+
return Array.isArray(response) ? response : response.prices;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get OHLC (Open, High, Low, Close) data for a futures contract
|
|
232
|
+
*
|
|
233
|
+
* @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
|
|
234
|
+
* @param date - Optional date in YYYY-MM-DD format (defaults to latest)
|
|
235
|
+
* @returns OHLC data
|
|
236
|
+
*
|
|
237
|
+
* @throws {NotFoundError} If contract not found
|
|
238
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const ohlc = await client.futures.ohlc('CL.1', '2024-01-15');
|
|
243
|
+
* console.log(`Open: $${ohlc.open}`);
|
|
244
|
+
* console.log(`High: $${ohlc.high}`);
|
|
245
|
+
* console.log(`Low: $${ohlc.low}`);
|
|
246
|
+
* console.log(`Close: $${ohlc.close}`);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async ohlc(contract, date) {
|
|
250
|
+
if (!contract || typeof contract !== "string") {
|
|
251
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
252
|
+
}
|
|
253
|
+
const params = {};
|
|
254
|
+
if (date)
|
|
255
|
+
params.date = date;
|
|
256
|
+
return this.client["request"](`/v1/futures/${contract}/ohlc`, params);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get intraday price data for a futures contract
|
|
260
|
+
*
|
|
261
|
+
* Returns price points throughout the trading day.
|
|
262
|
+
*
|
|
263
|
+
* @param contract - Contract symbol (e.g., "CL.1", "BZ.2")
|
|
264
|
+
* @returns Intraday price data
|
|
265
|
+
*
|
|
266
|
+
* @throws {NotFoundError} If contract not found
|
|
267
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const intraday = await client.futures.intraday('CL.1');
|
|
272
|
+
* intraday.prices.forEach(point => {
|
|
273
|
+
* console.log(`${point.time}: $${point.price}`);
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
async intraday(contract) {
|
|
278
|
+
if (!contract || typeof contract !== "string") {
|
|
279
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
280
|
+
}
|
|
281
|
+
return this.client["request"](`/v1/futures/${contract}/intraday`, {});
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get spread between two futures contracts
|
|
285
|
+
*
|
|
286
|
+
* Calculates the price difference between two contracts (contract1 - contract2).
|
|
287
|
+
*
|
|
288
|
+
* @param contract1 - First contract symbol
|
|
289
|
+
* @param contract2 - Second contract symbol
|
|
290
|
+
* @returns Spread data
|
|
291
|
+
*
|
|
292
|
+
* @throws {NotFoundError} If either contract not found
|
|
293
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* // Calculate spread between front month and second month
|
|
298
|
+
* const spread = await client.futures.spreads('CL.1', 'CL.2');
|
|
299
|
+
* console.log(`CL.1 - CL.2 spread: $${spread.spread}`);
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
async spreads(contract1, contract2) {
|
|
303
|
+
if (!contract1 || typeof contract1 !== "string") {
|
|
304
|
+
throw new errors_js_1.ValidationError("First contract symbol must be a non-empty string");
|
|
305
|
+
}
|
|
306
|
+
if (!contract2 || typeof contract2 !== "string") {
|
|
307
|
+
throw new errors_js_1.ValidationError("Second contract symbol must be a non-empty string");
|
|
308
|
+
}
|
|
309
|
+
return this.client["request"]("/v1/futures/spreads", {
|
|
310
|
+
contract1,
|
|
311
|
+
contract2,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get futures curve for a contract
|
|
316
|
+
*
|
|
317
|
+
* Returns the forward curve showing prices across different expiration dates.
|
|
318
|
+
*
|
|
319
|
+
* @param contract - Base contract symbol (e.g., "CL", "BZ")
|
|
320
|
+
* @returns Futures curve data
|
|
321
|
+
*
|
|
322
|
+
* @throws {NotFoundError} If contract not found
|
|
323
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const curve = await client.futures.curve('CL');
|
|
328
|
+
* console.log('WTI Futures Curve:');
|
|
329
|
+
* curve.curve.forEach(point => {
|
|
330
|
+
* console.log(`${point.months_out} months: $${point.price}`);
|
|
331
|
+
* });
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
async curve(contract) {
|
|
335
|
+
if (!contract || typeof contract !== "string") {
|
|
336
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
337
|
+
}
|
|
338
|
+
return this.client["request"](`/v1/futures/${contract}/curve`, {});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get continuous futures contract data
|
|
342
|
+
*
|
|
343
|
+
* Returns a continuous time series by rolling contracts before expiration.
|
|
344
|
+
*
|
|
345
|
+
* @param contract - Base contract symbol (e.g., "CL", "BZ")
|
|
346
|
+
* @param months - Number of months for continuous contract (default: 1 for front month)
|
|
347
|
+
* @returns Continuous contract data
|
|
348
|
+
*
|
|
349
|
+
* @throws {NotFoundError} If contract not found
|
|
350
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* // Get continuous front month contract
|
|
355
|
+
* const continuous = await client.futures.continuous('CL', 1);
|
|
356
|
+
* console.log(`${continuous.prices.length} data points`);
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
async continuous(contract, months) {
|
|
360
|
+
if (!contract || typeof contract !== "string") {
|
|
361
|
+
throw new errors_js_1.ValidationError("Contract symbol must be a non-empty string");
|
|
362
|
+
}
|
|
363
|
+
const params = {};
|
|
364
|
+
if (months !== undefined)
|
|
365
|
+
params.months = months.toString();
|
|
366
|
+
return this.client["request"](`/v1/futures/${contract}/continuous`, params);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get a typed helper for a specific contract family (issue #1).
|
|
370
|
+
*
|
|
371
|
+
* Provides ergonomic access to the ICE Brent / WTI / Gasoil and gas/carbon
|
|
372
|
+
* family endpoints (`/latest`, `/historical`, `/ohlc`, `/intraday`,
|
|
373
|
+
* `/spreads`, `/curve`, `/spread-history`) without remembering the URL slug.
|
|
374
|
+
*
|
|
375
|
+
* @param slug - Contract family slug (e.g., `"ice-brent"`, `"ice-gasoil"`).
|
|
376
|
+
* @returns A {@link FuturesContractFamily} bound to the slug.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const brent = client.futures.family('ice-brent');
|
|
381
|
+
* const latest = await brent.latest();
|
|
382
|
+
* const curve = await brent.curve();
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
family(slug) {
|
|
386
|
+
if (!slug || typeof slug !== "string") {
|
|
387
|
+
throw new errors_js_1.ValidationError("Contract family slug must be a non-empty string");
|
|
388
|
+
}
|
|
389
|
+
return new FuturesContractFamily(this.client, slug);
|
|
390
|
+
}
|
|
391
|
+
/** ICE Brent crude futures family helper (issue #1). */
|
|
392
|
+
brent() {
|
|
393
|
+
return this.family("ice-brent");
|
|
394
|
+
}
|
|
395
|
+
/** ICE WTI crude futures family helper. */
|
|
396
|
+
wti() {
|
|
397
|
+
return this.family("ice-wti");
|
|
398
|
+
}
|
|
399
|
+
/** ICE Gasoil futures family helper (issue #1). */
|
|
400
|
+
gasoil() {
|
|
401
|
+
return this.family("ice-gasoil");
|
|
402
|
+
}
|
|
403
|
+
/** Henry Hub natural gas futures family helper. */
|
|
404
|
+
naturalGas() {
|
|
405
|
+
return this.family("natural-gas");
|
|
406
|
+
}
|
|
407
|
+
/** TTF natural gas (Europe) futures family helper. */
|
|
408
|
+
ttfGas() {
|
|
409
|
+
return this.family("ttf-gas");
|
|
410
|
+
}
|
|
411
|
+
/** LNG JKM (Asia) futures family helper. */
|
|
412
|
+
lngJkm() {
|
|
413
|
+
return this.family("lng-jkm");
|
|
414
|
+
}
|
|
415
|
+
/** EU carbon allowance (EUA) futures family helper. */
|
|
416
|
+
euaCarbon() {
|
|
417
|
+
return this.family("eua-carbon");
|
|
418
|
+
}
|
|
419
|
+
/** UK carbon allowance (UKA) futures family helper. */
|
|
420
|
+
ukCarbon() {
|
|
421
|
+
return this.family("uk-carbon");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
exports.FuturesResource = FuturesResource;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Indicators Resource
|
|
4
|
+
*
|
|
5
|
+
* Access derived market indicators and signals: fuel-switching economics,
|
|
6
|
+
* price context, storage analytics, market annotations, CFTC positioning, and
|
|
7
|
+
* congressional energy-sector trades.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.IndicatorsResource = void 0;
|
|
11
|
+
const errors_js_1 = require("../errors.js");
|
|
12
|
+
/**
|
|
13
|
+
* Indicators Resource
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
18
|
+
*
|
|
19
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
20
|
+
*
|
|
21
|
+
* // Fuel-switching economics
|
|
22
|
+
* const fs = await client.indicators.fuelSwitching();
|
|
23
|
+
* console.log(`Switching economical: ${fs.economical}`);
|
|
24
|
+
*
|
|
25
|
+
* // CFTC positioning
|
|
26
|
+
* const cftc = await client.indicators.cftcPositioning();
|
|
27
|
+
* cftc.forEach(p => console.log(`${p.market}: net ${p.net_position}`));
|
|
28
|
+
*
|
|
29
|
+
* // Congressional trades
|
|
30
|
+
* const trades = await client.indicators.congressionalTrades();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class IndicatorsResource {
|
|
34
|
+
constructor(client) {
|
|
35
|
+
this.client = client;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get an arbitrary indicator by type.
|
|
39
|
+
*
|
|
40
|
+
* @typeParam T - Expected response type.
|
|
41
|
+
* @param type - Indicator type slug.
|
|
42
|
+
* @returns The indicator data.
|
|
43
|
+
* @throws {ValidationError} If the type is invalid.
|
|
44
|
+
*/
|
|
45
|
+
async get(type) {
|
|
46
|
+
if (!type || typeof type !== "string") {
|
|
47
|
+
throw new errors_js_1.ValidationError("Indicator type must be a non-empty string");
|
|
48
|
+
}
|
|
49
|
+
return this.client["request"](`/v1/indicators/${type}`, {});
|
|
50
|
+
}
|
|
51
|
+
/** Fuel-switching economics indicator. */
|
|
52
|
+
async fuelSwitching() {
|
|
53
|
+
return this.get("fuel-switching");
|
|
54
|
+
}
|
|
55
|
+
/** Price-context indicator. */
|
|
56
|
+
async priceContext() {
|
|
57
|
+
return this.get("price-context");
|
|
58
|
+
}
|
|
59
|
+
/** Storage-analytics indicator. */
|
|
60
|
+
async storageAnalytics() {
|
|
61
|
+
return this.get("storage-analytics");
|
|
62
|
+
}
|
|
63
|
+
/** Market annotations. */
|
|
64
|
+
async annotations() {
|
|
65
|
+
const response = await this.client["request"]("/v1/indicators/annotations", {});
|
|
66
|
+
return Array.isArray(response) ? response : response.data;
|
|
67
|
+
}
|
|
68
|
+
/** CFTC positioning (Commitment of Traders) indicators. */
|
|
69
|
+
async cftcPositioning() {
|
|
70
|
+
const response = await this.client["request"]("/v1/indicators/cftc-positioning", {});
|
|
71
|
+
return Array.isArray(response) ? response : response.data;
|
|
72
|
+
}
|
|
73
|
+
/** Congressional energy-sector trade indicators. */
|
|
74
|
+
async congressionalTrades() {
|
|
75
|
+
const response = await this.client["request"]("/v1/indicators/congressional-trades", {});
|
|
76
|
+
return Array.isArray(response) ? response : response.data;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.IndicatorsResource = IndicatorsResource;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Raw Response Resource
|
|
4
|
+
*
|
|
5
|
+
* Provides opt-in access to the underlying HTTP status code and response
|
|
6
|
+
* headers alongside the parsed data. Mirrors the most commonly used top-level
|
|
7
|
+
* client methods. This is the #1 requested enhancement (issue #7).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
12
|
+
*
|
|
13
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
14
|
+
*
|
|
15
|
+
* const { data, status, headers } = await client.raw.getLatestPrices();
|
|
16
|
+
* console.log(`HTTP ${status}`);
|
|
17
|
+
* console.log(`Rate limit remaining: ${headers.get('x-ratelimit-remaining')}`);
|
|
18
|
+
* console.log(data[0].price);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.RawResource = void 0;
|
|
23
|
+
/**
|
|
24
|
+
* Raw Response Resource
|
|
25
|
+
*
|
|
26
|
+
* Each method returns an {@link APIResponse} with `{ data, status, headers }`
|
|
27
|
+
* instead of just the parsed data, so callers can inspect HTTP metadata such
|
|
28
|
+
* as rate-limit headers, caching headers, and the exact status code.
|
|
29
|
+
*/
|
|
30
|
+
class RawResource {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Make an arbitrary GET request and return data plus HTTP status and headers.
|
|
36
|
+
*
|
|
37
|
+
* Use this for endpoints without a dedicated raw helper.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam T - Expected parsed response type.
|
|
40
|
+
* @param endpoint - API path beginning with `/` (e.g. `/v1/prices/latest`).
|
|
41
|
+
* @param params - Optional query parameters.
|
|
42
|
+
* @returns The parsed data along with the HTTP status code and headers.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const { data, status, headers } = await client.raw.get('/v1/futures/CL.1');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async get(endpoint, params) {
|
|
50
|
+
return this.client["requestRaw"](endpoint, params);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Latest prices with raw HTTP status and headers.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Optional commodity filter.
|
|
56
|
+
* @returns Prices array with HTTP status and headers.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const { data, status, headers } = await client.raw.getLatestPrices({ commodity: 'WTI_USD' });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
async getLatestPrices(options) {
|
|
64
|
+
const params = {};
|
|
65
|
+
if (options?.commodity) {
|
|
66
|
+
params.by_code = options.commodity;
|
|
67
|
+
}
|
|
68
|
+
return this.client["requestRaw"]("/v1/prices/latest", params);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Historical prices with raw HTTP status and headers.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Time period and filter options.
|
|
74
|
+
* @returns Prices array with HTTP status and headers.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const { data, status, headers } = await client.raw.getHistoricalPrices({
|
|
79
|
+
* period: 'past_week',
|
|
80
|
+
* commodity: 'BRENT_CRUDE_USD',
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async getHistoricalPrices(options) {
|
|
85
|
+
const params = {};
|
|
86
|
+
if (options?.period)
|
|
87
|
+
params.period = options.period;
|
|
88
|
+
if (options?.commodity)
|
|
89
|
+
params.by_code = options.commodity;
|
|
90
|
+
if (options?.startDate)
|
|
91
|
+
params.start_date = options.startDate;
|
|
92
|
+
if (options?.endDate)
|
|
93
|
+
params.end_date = options.endDate;
|
|
94
|
+
if (options?.interval)
|
|
95
|
+
params.interval = options.interval;
|
|
96
|
+
if (options?.perPage !== undefined)
|
|
97
|
+
params.per_page = options.perPage.toString();
|
|
98
|
+
if (options?.page !== undefined)
|
|
99
|
+
params.page = options.page.toString();
|
|
100
|
+
return this.client["requestRaw"]("/v1/prices/past_year", params);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Commodities metadata with raw HTTP status and headers.
|
|
104
|
+
*
|
|
105
|
+
* @returns Commodities response with HTTP status and headers.
|
|
106
|
+
*/
|
|
107
|
+
async getCommodities() {
|
|
108
|
+
return this.client["requestRaw"]("/v1/commodities", {});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Commodity categories with raw HTTP status and headers.
|
|
112
|
+
*
|
|
113
|
+
* @returns Categories response with HTTP status and headers.
|
|
114
|
+
*/
|
|
115
|
+
async getCommodityCategories() {
|
|
116
|
+
return this.client["requestRaw"]("/v1/commodities/categories", {});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A single commodity's metadata with raw HTTP status and headers.
|
|
120
|
+
*
|
|
121
|
+
* @param code - Commodity code (e.g., "WTI_USD").
|
|
122
|
+
* @returns Commodity with HTTP status and headers.
|
|
123
|
+
*/
|
|
124
|
+
async getCommodity(code) {
|
|
125
|
+
return this.client["requestRaw"](`/v1/commodities/${code}`, {});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.RawResource = RawResource;
|