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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indicators Resource
|
|
3
|
+
*
|
|
4
|
+
* Access derived market indicators and signals: fuel-switching economics,
|
|
5
|
+
* price context, storage analytics, market annotations, CFTC positioning, and
|
|
6
|
+
* congressional energy-sector trades.
|
|
7
|
+
*/
|
|
8
|
+
import type { OilPriceAPI } from "../client.js";
|
|
9
|
+
/**
|
|
10
|
+
* Supported indicator types.
|
|
11
|
+
*/
|
|
12
|
+
export type IndicatorType = "fuel-switching" | "price-context" | "storage-analytics" | "annotations" | "cftc-positioning" | "congressional-trades";
|
|
13
|
+
/**
|
|
14
|
+
* Fuel-switching economics indicator.
|
|
15
|
+
*/
|
|
16
|
+
export interface FuelSwitchingIndicator {
|
|
17
|
+
/** Switching ratio or breakeven value */
|
|
18
|
+
value: number;
|
|
19
|
+
/** Whether switching is economical */
|
|
20
|
+
economical?: boolean;
|
|
21
|
+
/** From fuel (e.g., "gas") */
|
|
22
|
+
from_fuel?: string;
|
|
23
|
+
/** To fuel (e.g., "oil") */
|
|
24
|
+
to_fuel?: string;
|
|
25
|
+
/** Unit */
|
|
26
|
+
unit?: string;
|
|
27
|
+
/** ISO timestamp */
|
|
28
|
+
timestamp: string;
|
|
29
|
+
/** Additional metadata */
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Price-context indicator (where the current price sits historically).
|
|
34
|
+
*/
|
|
35
|
+
export interface PriceContextIndicator {
|
|
36
|
+
/** Commodity code */
|
|
37
|
+
commodity?: string;
|
|
38
|
+
/** Current price */
|
|
39
|
+
price: number;
|
|
40
|
+
/** Percentile vs trailing window */
|
|
41
|
+
percentile?: number;
|
|
42
|
+
/** 52-week high */
|
|
43
|
+
high_52w?: number;
|
|
44
|
+
/** 52-week low */
|
|
45
|
+
low_52w?: number;
|
|
46
|
+
/** ISO timestamp */
|
|
47
|
+
timestamp: string;
|
|
48
|
+
/** Additional metadata */
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Storage-analytics indicator.
|
|
53
|
+
*/
|
|
54
|
+
export interface StorageAnalyticsIndicator {
|
|
55
|
+
/** Storage level */
|
|
56
|
+
level: number;
|
|
57
|
+
/** Capacity utilization percentage */
|
|
58
|
+
capacity_percent?: number;
|
|
59
|
+
/** Days of cover */
|
|
60
|
+
days_of_cover?: number;
|
|
61
|
+
/** Z-score vs 5-year average */
|
|
62
|
+
zscore?: number;
|
|
63
|
+
/** Unit */
|
|
64
|
+
unit?: string;
|
|
65
|
+
/** ISO timestamp */
|
|
66
|
+
timestamp: string;
|
|
67
|
+
/** Additional metadata */
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Market annotation (notable event marker).
|
|
72
|
+
*/
|
|
73
|
+
export interface AnnotationIndicator {
|
|
74
|
+
/** Annotation ID */
|
|
75
|
+
id?: string;
|
|
76
|
+
/** Title */
|
|
77
|
+
title: string;
|
|
78
|
+
/** Description */
|
|
79
|
+
description?: string;
|
|
80
|
+
/** Category (e.g., "geopolitical", "supply", "demand") */
|
|
81
|
+
category?: string;
|
|
82
|
+
/** Event date */
|
|
83
|
+
date: string;
|
|
84
|
+
/** Related commodity */
|
|
85
|
+
commodity?: string;
|
|
86
|
+
/** Additional metadata */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* CFTC positioning indicator (Commitment of Traders).
|
|
91
|
+
*/
|
|
92
|
+
export interface CFTCPositioningIndicator {
|
|
93
|
+
/** Market / commodity */
|
|
94
|
+
market?: string;
|
|
95
|
+
/** Managed-money long contracts */
|
|
96
|
+
managed_money_long?: number;
|
|
97
|
+
/** Managed-money short contracts */
|
|
98
|
+
managed_money_short?: number;
|
|
99
|
+
/** Net positioning */
|
|
100
|
+
net_position?: number;
|
|
101
|
+
/** Report date */
|
|
102
|
+
report_date: string;
|
|
103
|
+
/** Additional metadata */
|
|
104
|
+
metadata?: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Congressional trade indicator (energy-sector disclosures).
|
|
108
|
+
*/
|
|
109
|
+
export interface CongressionalTradeIndicator {
|
|
110
|
+
/** Representative or senator name */
|
|
111
|
+
member?: string;
|
|
112
|
+
/** Ticker traded */
|
|
113
|
+
ticker?: string;
|
|
114
|
+
/** Transaction type ("buy" / "sell") */
|
|
115
|
+
transaction_type?: string;
|
|
116
|
+
/** Amount range */
|
|
117
|
+
amount_range?: string;
|
|
118
|
+
/** Transaction date */
|
|
119
|
+
transaction_date: string;
|
|
120
|
+
/** Disclosure date */
|
|
121
|
+
disclosure_date?: string;
|
|
122
|
+
/** Additional metadata */
|
|
123
|
+
metadata?: Record<string, unknown>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Indicators Resource
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
131
|
+
*
|
|
132
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
133
|
+
*
|
|
134
|
+
* // Fuel-switching economics
|
|
135
|
+
* const fs = await client.indicators.fuelSwitching();
|
|
136
|
+
* console.log(`Switching economical: ${fs.economical}`);
|
|
137
|
+
*
|
|
138
|
+
* // CFTC positioning
|
|
139
|
+
* const cftc = await client.indicators.cftcPositioning();
|
|
140
|
+
* cftc.forEach(p => console.log(`${p.market}: net ${p.net_position}`));
|
|
141
|
+
*
|
|
142
|
+
* // Congressional trades
|
|
143
|
+
* const trades = await client.indicators.congressionalTrades();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare class IndicatorsResource {
|
|
147
|
+
private client;
|
|
148
|
+
constructor(client: OilPriceAPI);
|
|
149
|
+
/**
|
|
150
|
+
* Get an arbitrary indicator by type.
|
|
151
|
+
*
|
|
152
|
+
* @typeParam T - Expected response type.
|
|
153
|
+
* @param type - Indicator type slug.
|
|
154
|
+
* @returns The indicator data.
|
|
155
|
+
* @throws {ValidationError} If the type is invalid.
|
|
156
|
+
*/
|
|
157
|
+
get<T = unknown>(type: IndicatorType): Promise<T>;
|
|
158
|
+
/** Fuel-switching economics indicator. */
|
|
159
|
+
fuelSwitching(): Promise<FuelSwitchingIndicator>;
|
|
160
|
+
/** Price-context indicator. */
|
|
161
|
+
priceContext(): Promise<PriceContextIndicator>;
|
|
162
|
+
/** Storage-analytics indicator. */
|
|
163
|
+
storageAnalytics(): Promise<StorageAnalyticsIndicator>;
|
|
164
|
+
/** Market annotations. */
|
|
165
|
+
annotations(): Promise<AnnotationIndicator[]>;
|
|
166
|
+
/** CFTC positioning (Commitment of Traders) indicators. */
|
|
167
|
+
cftcPositioning(): Promise<CFTCPositioningIndicator[]>;
|
|
168
|
+
/** Congressional energy-sector trade indicators. */
|
|
169
|
+
congressionalTrades(): Promise<CongressionalTradeIndicator[]>;
|
|
170
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indicators Resource
|
|
3
|
+
*
|
|
4
|
+
* Access derived market indicators and signals: fuel-switching economics,
|
|
5
|
+
* price context, storage analytics, market annotations, CFTC positioning, and
|
|
6
|
+
* congressional energy-sector trades.
|
|
7
|
+
*/
|
|
8
|
+
import { ValidationError } from "../errors.js";
|
|
9
|
+
/**
|
|
10
|
+
* Indicators Resource
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
15
|
+
*
|
|
16
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
17
|
+
*
|
|
18
|
+
* // Fuel-switching economics
|
|
19
|
+
* const fs = await client.indicators.fuelSwitching();
|
|
20
|
+
* console.log(`Switching economical: ${fs.economical}`);
|
|
21
|
+
*
|
|
22
|
+
* // CFTC positioning
|
|
23
|
+
* const cftc = await client.indicators.cftcPositioning();
|
|
24
|
+
* cftc.forEach(p => console.log(`${p.market}: net ${p.net_position}`));
|
|
25
|
+
*
|
|
26
|
+
* // Congressional trades
|
|
27
|
+
* const trades = await client.indicators.congressionalTrades();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class IndicatorsResource {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get an arbitrary indicator by type.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam T - Expected response type.
|
|
38
|
+
* @param type - Indicator type slug.
|
|
39
|
+
* @returns The indicator data.
|
|
40
|
+
* @throws {ValidationError} If the type is invalid.
|
|
41
|
+
*/
|
|
42
|
+
async get(type) {
|
|
43
|
+
if (!type || typeof type !== "string") {
|
|
44
|
+
throw new ValidationError("Indicator type must be a non-empty string");
|
|
45
|
+
}
|
|
46
|
+
return this.client["request"](`/v1/indicators/${type}`, {});
|
|
47
|
+
}
|
|
48
|
+
/** Fuel-switching economics indicator. */
|
|
49
|
+
async fuelSwitching() {
|
|
50
|
+
return this.get("fuel-switching");
|
|
51
|
+
}
|
|
52
|
+
/** Price-context indicator. */
|
|
53
|
+
async priceContext() {
|
|
54
|
+
return this.get("price-context");
|
|
55
|
+
}
|
|
56
|
+
/** Storage-analytics indicator. */
|
|
57
|
+
async storageAnalytics() {
|
|
58
|
+
return this.get("storage-analytics");
|
|
59
|
+
}
|
|
60
|
+
/** Market annotations. */
|
|
61
|
+
async annotations() {
|
|
62
|
+
const response = await this.client["request"]("/v1/indicators/annotations", {});
|
|
63
|
+
return Array.isArray(response) ? response : response.data;
|
|
64
|
+
}
|
|
65
|
+
/** CFTC positioning (Commitment of Traders) indicators. */
|
|
66
|
+
async cftcPositioning() {
|
|
67
|
+
const response = await this.client["request"]("/v1/indicators/cftc-positioning", {});
|
|
68
|
+
return Array.isArray(response) ? response : response.data;
|
|
69
|
+
}
|
|
70
|
+
/** Congressional energy-sector trade indicators. */
|
|
71
|
+
async congressionalTrades() {
|
|
72
|
+
const response = await this.client["request"]("/v1/indicators/congressional-trades", {});
|
|
73
|
+
return Array.isArray(response) ? response : response.data;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Response Resource
|
|
3
|
+
*
|
|
4
|
+
* Provides opt-in access to the underlying HTTP status code and response
|
|
5
|
+
* headers alongside the parsed data. Mirrors the most commonly used top-level
|
|
6
|
+
* client methods. This is the #1 requested enhancement (issue #7).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
11
|
+
*
|
|
12
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
13
|
+
*
|
|
14
|
+
* const { data, status, headers } = await client.raw.getLatestPrices();
|
|
15
|
+
* console.log(`HTTP ${status}`);
|
|
16
|
+
* console.log(`Rate limit remaining: ${headers.get('x-ratelimit-remaining')}`);
|
|
17
|
+
* console.log(data[0].price);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { OilPriceAPI, APIResponse } from "../client.js";
|
|
21
|
+
import type { Price, LatestPricesOptions, HistoricalPricesOptions, Commodity, CommoditiesResponse, CategoriesResponse } from "../types.js";
|
|
22
|
+
/**
|
|
23
|
+
* Raw Response Resource
|
|
24
|
+
*
|
|
25
|
+
* Each method returns an {@link APIResponse} with `{ data, status, headers }`
|
|
26
|
+
* instead of just the parsed data, so callers can inspect HTTP metadata such
|
|
27
|
+
* as rate-limit headers, caching headers, and the exact status code.
|
|
28
|
+
*/
|
|
29
|
+
export declare class RawResource {
|
|
30
|
+
private client;
|
|
31
|
+
constructor(client: OilPriceAPI);
|
|
32
|
+
/**
|
|
33
|
+
* Make an arbitrary GET request and return data plus HTTP status and headers.
|
|
34
|
+
*
|
|
35
|
+
* Use this for endpoints without a dedicated raw helper.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam T - Expected parsed response type.
|
|
38
|
+
* @param endpoint - API path beginning with `/` (e.g. `/v1/prices/latest`).
|
|
39
|
+
* @param params - Optional query parameters.
|
|
40
|
+
* @returns The parsed data along with the HTTP status code and headers.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const { data, status, headers } = await client.raw.get('/v1/futures/CL.1');
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
get<T = unknown>(endpoint: string, params?: Record<string, string>): Promise<APIResponse<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Latest prices with raw HTTP status and headers.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Optional commodity filter.
|
|
52
|
+
* @returns Prices array with HTTP status and headers.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const { data, status, headers } = await client.raw.getLatestPrices({ commodity: 'WTI_USD' });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
getLatestPrices(options?: LatestPricesOptions): Promise<APIResponse<Price[]>>;
|
|
60
|
+
/**
|
|
61
|
+
* Historical prices with raw HTTP status and headers.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Time period and filter options.
|
|
64
|
+
* @returns Prices array with HTTP status and headers.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const { data, status, headers } = await client.raw.getHistoricalPrices({
|
|
69
|
+
* period: 'past_week',
|
|
70
|
+
* commodity: 'BRENT_CRUDE_USD',
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
getHistoricalPrices(options?: HistoricalPricesOptions): Promise<APIResponse<Price[]>>;
|
|
75
|
+
/**
|
|
76
|
+
* Commodities metadata with raw HTTP status and headers.
|
|
77
|
+
*
|
|
78
|
+
* @returns Commodities response with HTTP status and headers.
|
|
79
|
+
*/
|
|
80
|
+
getCommodities(): Promise<APIResponse<CommoditiesResponse>>;
|
|
81
|
+
/**
|
|
82
|
+
* Commodity categories with raw HTTP status and headers.
|
|
83
|
+
*
|
|
84
|
+
* @returns Categories response with HTTP status and headers.
|
|
85
|
+
*/
|
|
86
|
+
getCommodityCategories(): Promise<APIResponse<CategoriesResponse>>;
|
|
87
|
+
/**
|
|
88
|
+
* A single commodity's metadata with raw HTTP status and headers.
|
|
89
|
+
*
|
|
90
|
+
* @param code - Commodity code (e.g., "WTI_USD").
|
|
91
|
+
* @returns Commodity with HTTP status and headers.
|
|
92
|
+
*/
|
|
93
|
+
getCommodity(code: string): Promise<APIResponse<Commodity>>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Response Resource
|
|
3
|
+
*
|
|
4
|
+
* Provides opt-in access to the underlying HTTP status code and response
|
|
5
|
+
* headers alongside the parsed data. Mirrors the most commonly used top-level
|
|
6
|
+
* client methods. This is the #1 requested enhancement (issue #7).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
11
|
+
*
|
|
12
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
13
|
+
*
|
|
14
|
+
* const { data, status, headers } = await client.raw.getLatestPrices();
|
|
15
|
+
* console.log(`HTTP ${status}`);
|
|
16
|
+
* console.log(`Rate limit remaining: ${headers.get('x-ratelimit-remaining')}`);
|
|
17
|
+
* console.log(data[0].price);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Raw Response Resource
|
|
22
|
+
*
|
|
23
|
+
* Each method returns an {@link APIResponse} with `{ data, status, headers }`
|
|
24
|
+
* instead of just the parsed data, so callers can inspect HTTP metadata such
|
|
25
|
+
* as rate-limit headers, caching headers, and the exact status code.
|
|
26
|
+
*/
|
|
27
|
+
export class RawResource {
|
|
28
|
+
constructor(client) {
|
|
29
|
+
this.client = client;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Make an arbitrary GET request and return data plus HTTP status and headers.
|
|
33
|
+
*
|
|
34
|
+
* Use this for endpoints without a dedicated raw helper.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - Expected parsed response type.
|
|
37
|
+
* @param endpoint - API path beginning with `/` (e.g. `/v1/prices/latest`).
|
|
38
|
+
* @param params - Optional query parameters.
|
|
39
|
+
* @returns The parsed data along with the HTTP status code and headers.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const { data, status, headers } = await client.raw.get('/v1/futures/CL.1');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
async get(endpoint, params) {
|
|
47
|
+
return this.client["requestRaw"](endpoint, params);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Latest prices with raw HTTP status and headers.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Optional commodity filter.
|
|
53
|
+
* @returns Prices array with HTTP status and headers.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const { data, status, headers } = await client.raw.getLatestPrices({ commodity: 'WTI_USD' });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async getLatestPrices(options) {
|
|
61
|
+
const params = {};
|
|
62
|
+
if (options?.commodity) {
|
|
63
|
+
params.by_code = options.commodity;
|
|
64
|
+
}
|
|
65
|
+
return this.client["requestRaw"]("/v1/prices/latest", params);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Historical prices with raw HTTP status and headers.
|
|
69
|
+
*
|
|
70
|
+
* @param options - Time period and filter options.
|
|
71
|
+
* @returns Prices array with HTTP status and headers.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const { data, status, headers } = await client.raw.getHistoricalPrices({
|
|
76
|
+
* period: 'past_week',
|
|
77
|
+
* commodity: 'BRENT_CRUDE_USD',
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
async getHistoricalPrices(options) {
|
|
82
|
+
const params = {};
|
|
83
|
+
if (options?.period)
|
|
84
|
+
params.period = options.period;
|
|
85
|
+
if (options?.commodity)
|
|
86
|
+
params.by_code = options.commodity;
|
|
87
|
+
if (options?.startDate)
|
|
88
|
+
params.start_date = options.startDate;
|
|
89
|
+
if (options?.endDate)
|
|
90
|
+
params.end_date = options.endDate;
|
|
91
|
+
if (options?.interval)
|
|
92
|
+
params.interval = options.interval;
|
|
93
|
+
if (options?.perPage !== undefined)
|
|
94
|
+
params.per_page = options.perPage.toString();
|
|
95
|
+
if (options?.page !== undefined)
|
|
96
|
+
params.page = options.page.toString();
|
|
97
|
+
return this.client["requestRaw"]("/v1/prices/past_year", params);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Commodities metadata with raw HTTP status and headers.
|
|
101
|
+
*
|
|
102
|
+
* @returns Commodities response with HTTP status and headers.
|
|
103
|
+
*/
|
|
104
|
+
async getCommodities() {
|
|
105
|
+
return this.client["requestRaw"]("/v1/commodities", {});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Commodity categories with raw HTTP status and headers.
|
|
109
|
+
*
|
|
110
|
+
* @returns Categories response with HTTP status and headers.
|
|
111
|
+
*/
|
|
112
|
+
async getCommodityCategories() {
|
|
113
|
+
return this.client["requestRaw"]("/v1/commodities/categories", {});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A single commodity's metadata with raw HTTP status and headers.
|
|
117
|
+
*
|
|
118
|
+
* @param code - Commodity code (e.g., "WTI_USD").
|
|
119
|
+
* @returns Commodity with HTTP status and headers.
|
|
120
|
+
*/
|
|
121
|
+
async getCommodity(code) {
|
|
122
|
+
return this.client["requestRaw"](`/v1/commodities/${code}`, {});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -96,11 +96,14 @@ export class RigCountsResource {
|
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
async historical(options) {
|
|
99
|
+
// The controller filters via `has_scope :by_period, using: %i[from to], type: :hash`,
|
|
100
|
+
// i.e. it reads nested `by_period[from]` / `by_period[to]` query params — NOT
|
|
101
|
+
// flat `start_date` / `end_date` (which were silently ignored by earlier SDKs).
|
|
99
102
|
const params = {};
|
|
100
103
|
if (options?.startDate)
|
|
101
|
-
params
|
|
104
|
+
params["by_period[from]"] = options.startDate;
|
|
102
105
|
if (options?.endDate)
|
|
103
|
-
params
|
|
106
|
+
params["by_period[to]"] = options.endDate;
|
|
104
107
|
const response = await this.client["request"]("/v1/rig-counts/historical", params);
|
|
105
108
|
return Array.isArray(response) ? response : response.data;
|
|
106
109
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spreads Resource
|
|
3
|
+
*
|
|
4
|
+
* Access oil & product spread analytics: crack spreads, basis spreads,
|
|
5
|
+
* curve-structure (contango/backwardation), refining margins, and physical
|
|
6
|
+
* premiums. Each spread type supports the latest value, full history, and an
|
|
7
|
+
* `all` listing.
|
|
8
|
+
*/
|
|
9
|
+
import type { OilPriceAPI } from "../client.js";
|
|
10
|
+
/**
|
|
11
|
+
* Supported spread types.
|
|
12
|
+
*
|
|
13
|
+
* - `crack` — refining crack spread (e.g., 3:2:1)
|
|
14
|
+
* - `basis` — regional basis differential vs benchmark
|
|
15
|
+
* - `curve-structure` — contango / backwardation structure
|
|
16
|
+
* - `margin` — refining margin
|
|
17
|
+
* - `physical-premium` — physical-vs-paper premium
|
|
18
|
+
*/
|
|
19
|
+
export type SpreadType = "crack" | "basis" | "curve-structure" | "margin" | "physical-premium";
|
|
20
|
+
/**
|
|
21
|
+
* A single spread data point.
|
|
22
|
+
*/
|
|
23
|
+
export interface SpreadValue {
|
|
24
|
+
/** Spread type slug */
|
|
25
|
+
type: string;
|
|
26
|
+
/** Spread name / label */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Spread value */
|
|
29
|
+
value: number;
|
|
30
|
+
/** Unit (e.g., "USD/bbl") */
|
|
31
|
+
unit?: string;
|
|
32
|
+
/** Region or market */
|
|
33
|
+
region?: string;
|
|
34
|
+
/** Benchmark or components */
|
|
35
|
+
components?: string[];
|
|
36
|
+
/** ISO timestamp */
|
|
37
|
+
timestamp: string;
|
|
38
|
+
/** Additional metadata */
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Historical spread data point.
|
|
43
|
+
*/
|
|
44
|
+
export interface HistoricalSpreadValue {
|
|
45
|
+
/** ISO date */
|
|
46
|
+
date: string;
|
|
47
|
+
/** Spread value */
|
|
48
|
+
value: number;
|
|
49
|
+
/** Unit */
|
|
50
|
+
unit?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for a historical spread query.
|
|
54
|
+
*/
|
|
55
|
+
export interface HistoricalSpreadOptions {
|
|
56
|
+
/** Start date (YYYY-MM-DD) */
|
|
57
|
+
startDate?: string;
|
|
58
|
+
/** End date (YYYY-MM-DD) */
|
|
59
|
+
endDate?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Spreads Resource
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
67
|
+
*
|
|
68
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
69
|
+
*
|
|
70
|
+
* // Latest crack spread
|
|
71
|
+
* const crack = await client.spreads.crack();
|
|
72
|
+
* console.log(`Crack spread: ${crack.value} ${crack.unit}`);
|
|
73
|
+
*
|
|
74
|
+
* // Historical basis spreads
|
|
75
|
+
* const history = await client.spreads.historical('basis', {
|
|
76
|
+
* startDate: '2024-01-01',
|
|
77
|
+
* endDate: '2024-12-31',
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // All margin spreads
|
|
81
|
+
* const all = await client.spreads.all('margin');
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare class SpreadsResource {
|
|
85
|
+
private client;
|
|
86
|
+
constructor(client: OilPriceAPI);
|
|
87
|
+
/**
|
|
88
|
+
* Get the latest value for a spread type.
|
|
89
|
+
*
|
|
90
|
+
* @param type - Spread type slug.
|
|
91
|
+
* @returns Latest spread value.
|
|
92
|
+
* @throws {ValidationError} If the type is invalid.
|
|
93
|
+
*/
|
|
94
|
+
get(type: SpreadType): Promise<SpreadValue>;
|
|
95
|
+
/**
|
|
96
|
+
* Get historical data for a spread type.
|
|
97
|
+
*
|
|
98
|
+
* @param type - Spread type slug.
|
|
99
|
+
* @param options - Optional date range filters.
|
|
100
|
+
* @returns Array of historical spread values.
|
|
101
|
+
*/
|
|
102
|
+
historical(type: SpreadType, options?: HistoricalSpreadOptions): Promise<HistoricalSpreadValue[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Get all spread values for a spread type.
|
|
105
|
+
*
|
|
106
|
+
* @param type - Spread type slug.
|
|
107
|
+
* @returns Array of spread values.
|
|
108
|
+
*/
|
|
109
|
+
all(type: SpreadType): Promise<SpreadValue[]>;
|
|
110
|
+
/** Latest crack spread. */
|
|
111
|
+
crack(): Promise<SpreadValue>;
|
|
112
|
+
/** Latest basis spread. */
|
|
113
|
+
basis(): Promise<SpreadValue>;
|
|
114
|
+
/** Latest curve-structure (contango / backwardation). */
|
|
115
|
+
curveStructure(): Promise<SpreadValue>;
|
|
116
|
+
/** Latest refining margin. */
|
|
117
|
+
margin(): Promise<SpreadValue>;
|
|
118
|
+
/** Latest physical premium. */
|
|
119
|
+
physicalPremium(): Promise<SpreadValue>;
|
|
120
|
+
private validateType;
|
|
121
|
+
}
|