oilpriceapi 0.6.0 → 0.7.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 +376 -113
- package/dist/client.d.ts +83 -3
- package/dist/client.js +104 -38
- package/dist/index.d.ts +31 -6
- package/dist/index.js +17 -3
- package/dist/resources/alerts.d.ts +52 -15
- package/dist/resources/alerts.js +143 -85
- package/dist/resources/analytics.d.ts +325 -0
- package/dist/resources/analytics.js +221 -0
- package/dist/resources/bunker-fuels.d.ts +270 -0
- package/dist/resources/bunker-fuels.js +191 -0
- package/dist/resources/commodities.d.ts +148 -0
- package/dist/resources/commodities.js +110 -0
- package/dist/resources/data-quality.d.ts +229 -0
- package/dist/resources/data-quality.js +139 -0
- package/dist/resources/data-sources.d.ts +365 -0
- package/dist/resources/data-sources.js +349 -0
- package/dist/resources/drilling.d.ts +403 -0
- package/dist/resources/drilling.js +264 -0
- package/dist/resources/ei/drilling-productivity.d.ts +173 -0
- package/dist/resources/ei/drilling-productivity.js +103 -0
- package/dist/resources/ei/forecasts.d.ts +177 -0
- package/dist/resources/ei/forecasts.js +101 -0
- package/dist/resources/ei/frac-focus.d.ts +212 -0
- package/dist/resources/ei/frac-focus.js +150 -0
- package/dist/resources/ei/index.d.ts +140 -0
- package/dist/resources/ei/index.js +87 -0
- package/dist/resources/ei/oil-inventories.d.ts +155 -0
- package/dist/resources/ei/oil-inventories.js +92 -0
- package/dist/resources/ei/opec-production.d.ts +146 -0
- package/dist/resources/ei/opec-production.js +92 -0
- package/dist/resources/ei/rig-counts.d.ts +131 -0
- package/dist/resources/ei/rig-counts.js +88 -0
- package/dist/resources/ei/well-permits.d.ts +178 -0
- package/dist/resources/ei/well-permits.js +119 -0
- package/dist/resources/forecasts.d.ts +200 -0
- package/dist/resources/forecasts.js +157 -0
- package/dist/resources/futures.d.ts +322 -0
- package/dist/resources/futures.js +228 -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 +161 -0
- package/dist/resources/webhooks.d.ts +290 -0
- package/dist/resources/webhooks.js +297 -0
- package/dist/types.d.ts +77 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Energy Intelligence - Well Permits Resource
|
|
3
|
+
*
|
|
4
|
+
* Access oil and gas well permit data by state, operator, and formation.
|
|
5
|
+
*/
|
|
6
|
+
import type { OilPriceAPI } from "../../client.js";
|
|
7
|
+
/**
|
|
8
|
+
* Well permit record
|
|
9
|
+
*/
|
|
10
|
+
export interface WellPermitRecord {
|
|
11
|
+
/** Record ID */
|
|
12
|
+
id: string;
|
|
13
|
+
/** Permit number */
|
|
14
|
+
permit_number?: string;
|
|
15
|
+
/** State */
|
|
16
|
+
state: string;
|
|
17
|
+
/** County */
|
|
18
|
+
county?: string;
|
|
19
|
+
/** Operator name */
|
|
20
|
+
operator?: string;
|
|
21
|
+
/** Well name */
|
|
22
|
+
well_name?: string;
|
|
23
|
+
/** Formation/target */
|
|
24
|
+
formation?: string;
|
|
25
|
+
/** Well type (e.g., "oil", "gas", "injection") */
|
|
26
|
+
well_type?: string;
|
|
27
|
+
/** Permit issue date */
|
|
28
|
+
issue_date: string;
|
|
29
|
+
/** ISO timestamp */
|
|
30
|
+
timestamp: string;
|
|
31
|
+
/** Additional metadata */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Well permit summary
|
|
36
|
+
*/
|
|
37
|
+
export interface WellPermitSummary {
|
|
38
|
+
/** Total permits */
|
|
39
|
+
total_permits: number;
|
|
40
|
+
/** Permits by state */
|
|
41
|
+
by_state?: Record<string, number>;
|
|
42
|
+
/** Permits by operator */
|
|
43
|
+
by_operator?: Record<string, number>;
|
|
44
|
+
/** As of date */
|
|
45
|
+
as_of_date: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Permits by state
|
|
49
|
+
*/
|
|
50
|
+
export interface PermitsByState {
|
|
51
|
+
/** State name */
|
|
52
|
+
state: string;
|
|
53
|
+
/** Permit count */
|
|
54
|
+
permit_count: number;
|
|
55
|
+
/** Change from previous period */
|
|
56
|
+
change?: number;
|
|
57
|
+
/** Date */
|
|
58
|
+
date: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Permits by operator
|
|
62
|
+
*/
|
|
63
|
+
export interface PermitsByOperator {
|
|
64
|
+
/** Operator name */
|
|
65
|
+
operator: string;
|
|
66
|
+
/** Permit count */
|
|
67
|
+
permit_count: number;
|
|
68
|
+
/** Percentage of total */
|
|
69
|
+
percentage?: number;
|
|
70
|
+
/** Date */
|
|
71
|
+
date: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Permits by formation
|
|
75
|
+
*/
|
|
76
|
+
export interface PermitsByFormation {
|
|
77
|
+
/** Formation name */
|
|
78
|
+
formation: string;
|
|
79
|
+
/** Permit count */
|
|
80
|
+
permit_count: number;
|
|
81
|
+
/** Percentage of total */
|
|
82
|
+
percentage?: number;
|
|
83
|
+
/** Date */
|
|
84
|
+
date: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Well permit search query
|
|
88
|
+
*/
|
|
89
|
+
export interface WellPermitSearchQuery {
|
|
90
|
+
/** State filter */
|
|
91
|
+
state?: string;
|
|
92
|
+
/** Operator filter */
|
|
93
|
+
operator?: string;
|
|
94
|
+
/** Formation filter */
|
|
95
|
+
formation?: string;
|
|
96
|
+
/** Start date */
|
|
97
|
+
start_date?: string;
|
|
98
|
+
/** End date */
|
|
99
|
+
end_date?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* EI Well Permits Resource
|
|
103
|
+
*
|
|
104
|
+
* Access oil and gas well permit data with detailed breakdowns.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
109
|
+
*
|
|
110
|
+
* // Get latest permits
|
|
111
|
+
* const latest = await client.ei.wellPermits.latest();
|
|
112
|
+
* console.log(`Permit: ${latest.permit_number} - ${latest.operator}`);
|
|
113
|
+
*
|
|
114
|
+
* // Get permits by state
|
|
115
|
+
* const states = await client.ei.wellPermits.byState();
|
|
116
|
+
* states.forEach(s => console.log(`${s.state}: ${s.permit_count} permits`));
|
|
117
|
+
*
|
|
118
|
+
* // Search permits
|
|
119
|
+
* const results = await client.ei.wellPermits.search({
|
|
120
|
+
* state: 'Texas',
|
|
121
|
+
* operator: 'ConocoPhillips'
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare class EIWellPermitsResource {
|
|
126
|
+
private client;
|
|
127
|
+
constructor(client: OilPriceAPI);
|
|
128
|
+
/**
|
|
129
|
+
* List all well permit records
|
|
130
|
+
*
|
|
131
|
+
* @returns Array of well permit records
|
|
132
|
+
*/
|
|
133
|
+
list(): Promise<WellPermitRecord[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Get a specific well permit record
|
|
136
|
+
*
|
|
137
|
+
* @param id - Record ID
|
|
138
|
+
* @returns Well permit record
|
|
139
|
+
*/
|
|
140
|
+
get(id: string): Promise<WellPermitRecord>;
|
|
141
|
+
/**
|
|
142
|
+
* Get latest well permit
|
|
143
|
+
*
|
|
144
|
+
* @returns Latest well permit record
|
|
145
|
+
*/
|
|
146
|
+
latest(): Promise<WellPermitRecord>;
|
|
147
|
+
/**
|
|
148
|
+
* Get well permit summary
|
|
149
|
+
*
|
|
150
|
+
* @returns Well permit summary statistics
|
|
151
|
+
*/
|
|
152
|
+
summary(): Promise<WellPermitSummary>;
|
|
153
|
+
/**
|
|
154
|
+
* Get permits by state
|
|
155
|
+
*
|
|
156
|
+
* @returns Array of permits grouped by state
|
|
157
|
+
*/
|
|
158
|
+
byState(): Promise<PermitsByState[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get permits by operator
|
|
161
|
+
*
|
|
162
|
+
* @returns Array of permits grouped by operator
|
|
163
|
+
*/
|
|
164
|
+
byOperator(): Promise<PermitsByOperator[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Get permits by formation
|
|
167
|
+
*
|
|
168
|
+
* @returns Array of permits grouped by formation
|
|
169
|
+
*/
|
|
170
|
+
byFormation(): Promise<PermitsByFormation[]>;
|
|
171
|
+
/**
|
|
172
|
+
* Search well permits
|
|
173
|
+
*
|
|
174
|
+
* @param query - Search query parameters
|
|
175
|
+
* @returns Array of matching well permit records
|
|
176
|
+
*/
|
|
177
|
+
search(query: WellPermitSearchQuery): Promise<WellPermitRecord[]>;
|
|
178
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Energy Intelligence - Well Permits Resource
|
|
3
|
+
*
|
|
4
|
+
* Access oil and gas well permit data by state, operator, and formation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* EI Well Permits Resource
|
|
8
|
+
*
|
|
9
|
+
* Access oil and gas well permit data with detailed breakdowns.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
14
|
+
*
|
|
15
|
+
* // Get latest permits
|
|
16
|
+
* const latest = await client.ei.wellPermits.latest();
|
|
17
|
+
* console.log(`Permit: ${latest.permit_number} - ${latest.operator}`);
|
|
18
|
+
*
|
|
19
|
+
* // Get permits by state
|
|
20
|
+
* const states = await client.ei.wellPermits.byState();
|
|
21
|
+
* states.forEach(s => console.log(`${s.state}: ${s.permit_count} permits`));
|
|
22
|
+
*
|
|
23
|
+
* // Search permits
|
|
24
|
+
* const results = await client.ei.wellPermits.search({
|
|
25
|
+
* state: 'Texas',
|
|
26
|
+
* operator: 'ConocoPhillips'
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class EIWellPermitsResource {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* List all well permit records
|
|
36
|
+
*
|
|
37
|
+
* @returns Array of well permit records
|
|
38
|
+
*/
|
|
39
|
+
async list() {
|
|
40
|
+
const response = await this.client["request"]("/v1/ei/well-permits", {});
|
|
41
|
+
return Array.isArray(response) ? response : response.data;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a specific well permit record
|
|
45
|
+
*
|
|
46
|
+
* @param id - Record ID
|
|
47
|
+
* @returns Well permit record
|
|
48
|
+
*/
|
|
49
|
+
async get(id) {
|
|
50
|
+
if (!id || typeof id !== "string") {
|
|
51
|
+
throw new Error("Record ID must be a non-empty string");
|
|
52
|
+
}
|
|
53
|
+
return this.client["request"](`/v1/ei/well-permits/${id}`, {});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get latest well permit
|
|
57
|
+
*
|
|
58
|
+
* @returns Latest well permit record
|
|
59
|
+
*/
|
|
60
|
+
async latest() {
|
|
61
|
+
return this.client["request"]("/v1/ei/well-permits/latest", {});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get well permit summary
|
|
65
|
+
*
|
|
66
|
+
* @returns Well permit summary statistics
|
|
67
|
+
*/
|
|
68
|
+
async summary() {
|
|
69
|
+
return this.client["request"]("/v1/ei/well-permits/summary", {});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get permits by state
|
|
73
|
+
*
|
|
74
|
+
* @returns Array of permits grouped by state
|
|
75
|
+
*/
|
|
76
|
+
async byState() {
|
|
77
|
+
const response = await this.client["request"]("/v1/ei/well-permits/by-state", {});
|
|
78
|
+
return Array.isArray(response) ? response : response.data;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get permits by operator
|
|
82
|
+
*
|
|
83
|
+
* @returns Array of permits grouped by operator
|
|
84
|
+
*/
|
|
85
|
+
async byOperator() {
|
|
86
|
+
const response = await this.client["request"]("/v1/ei/well-permits/by-operator", {});
|
|
87
|
+
return Array.isArray(response) ? response : response.data;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get permits by formation
|
|
91
|
+
*
|
|
92
|
+
* @returns Array of permits grouped by formation
|
|
93
|
+
*/
|
|
94
|
+
async byFormation() {
|
|
95
|
+
const response = await this.client["request"]("/v1/ei/well-permits/by-formation", {});
|
|
96
|
+
return Array.isArray(response) ? response : response.data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Search well permits
|
|
100
|
+
*
|
|
101
|
+
* @param query - Search query parameters
|
|
102
|
+
* @returns Array of matching well permit records
|
|
103
|
+
*/
|
|
104
|
+
async search(query) {
|
|
105
|
+
const params = {};
|
|
106
|
+
if (query.state)
|
|
107
|
+
params.state = query.state;
|
|
108
|
+
if (query.operator)
|
|
109
|
+
params.operator = query.operator;
|
|
110
|
+
if (query.formation)
|
|
111
|
+
params.formation = query.formation;
|
|
112
|
+
if (query.start_date)
|
|
113
|
+
params.start_date = query.start_date;
|
|
114
|
+
if (query.end_date)
|
|
115
|
+
params.end_date = query.end_date;
|
|
116
|
+
const response = await this.client["request"]("/v1/ei/well-permits/search", params);
|
|
117
|
+
return Array.isArray(response) ? response : response.data;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forecasts Resource
|
|
3
|
+
*
|
|
4
|
+
* Access official price forecasts from EIA, IEA, and other agencies including
|
|
5
|
+
* monthly outlooks, accuracy metrics, and historical archives.
|
|
6
|
+
*/
|
|
7
|
+
import type { OilPriceAPI } from "../client.js";
|
|
8
|
+
/**
|
|
9
|
+
* Monthly forecast data
|
|
10
|
+
*/
|
|
11
|
+
export interface MonthlyForecast {
|
|
12
|
+
/** Forecast period (e.g., "2024-03", "2024-Q2") */
|
|
13
|
+
period: string;
|
|
14
|
+
/** Commodity code */
|
|
15
|
+
commodity: string;
|
|
16
|
+
/** Forecasted price */
|
|
17
|
+
forecast_price: number;
|
|
18
|
+
/** Lower bound of forecast range */
|
|
19
|
+
lower_bound?: number;
|
|
20
|
+
/** Upper bound of forecast range */
|
|
21
|
+
upper_bound?: number;
|
|
22
|
+
/** Forecast source (e.g., "EIA", "IEA") */
|
|
23
|
+
source: string;
|
|
24
|
+
/** ISO timestamp when forecast was published */
|
|
25
|
+
published_at: string;
|
|
26
|
+
/** Additional metadata */
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Forecast accuracy metrics
|
|
31
|
+
*/
|
|
32
|
+
export interface ForecastAccuracy {
|
|
33
|
+
/** Commodity code */
|
|
34
|
+
commodity?: string;
|
|
35
|
+
/** Forecast source */
|
|
36
|
+
source: string;
|
|
37
|
+
/** Mean Absolute Percentage Error */
|
|
38
|
+
mape: number;
|
|
39
|
+
/** Root Mean Squared Error */
|
|
40
|
+
rmse: number;
|
|
41
|
+
/** Mean Error (bias) */
|
|
42
|
+
mean_error?: number;
|
|
43
|
+
/** Number of forecasts evaluated */
|
|
44
|
+
sample_size: number;
|
|
45
|
+
/** Time period evaluated */
|
|
46
|
+
period_evaluated: string;
|
|
47
|
+
/** ISO timestamp */
|
|
48
|
+
timestamp: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Archived forecast data
|
|
52
|
+
*/
|
|
53
|
+
export interface ArchivedForecast {
|
|
54
|
+
/** Year of forecast */
|
|
55
|
+
year: number;
|
|
56
|
+
/** Month of forecast (1-12) */
|
|
57
|
+
month?: number;
|
|
58
|
+
/** Quarter of forecast (1-4) */
|
|
59
|
+
quarter?: number;
|
|
60
|
+
/** Commodity code */
|
|
61
|
+
commodity: string;
|
|
62
|
+
/** Forecasted price */
|
|
63
|
+
forecast_price: number;
|
|
64
|
+
/** Actual price (if available) */
|
|
65
|
+
actual_price?: number;
|
|
66
|
+
/** Forecast error */
|
|
67
|
+
error?: number;
|
|
68
|
+
/** Forecast source */
|
|
69
|
+
source: string;
|
|
70
|
+
/** ISO timestamp when forecast was published */
|
|
71
|
+
published_at: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Forecasts Resource
|
|
75
|
+
*
|
|
76
|
+
* Access official price forecasts from government agencies and research
|
|
77
|
+
* organizations including EIA, IEA, and others.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
82
|
+
*
|
|
83
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
84
|
+
*
|
|
85
|
+
* // Get monthly forecasts
|
|
86
|
+
* const forecasts = await client.forecasts.monthly();
|
|
87
|
+
* forecasts.forEach(f => {
|
|
88
|
+
* console.log(`${f.period}: $${f.forecast_price} (${f.source})`);
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* // Check forecast accuracy
|
|
92
|
+
* const accuracy = await client.forecasts.accuracy();
|
|
93
|
+
* console.log(`EIA MAPE: ${accuracy.mape}%`);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare class ForecastsResource {
|
|
97
|
+
private client;
|
|
98
|
+
constructor(client: OilPriceAPI);
|
|
99
|
+
/**
|
|
100
|
+
* Get monthly price forecasts
|
|
101
|
+
*
|
|
102
|
+
* Returns official monthly forecasts from EIA, IEA, and other agencies.
|
|
103
|
+
*
|
|
104
|
+
* @param commodity - Optional commodity code filter
|
|
105
|
+
* @returns Array of monthly forecasts
|
|
106
|
+
*
|
|
107
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
108
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // Get all forecasts
|
|
113
|
+
* const allForecasts = await client.forecasts.monthly();
|
|
114
|
+
*
|
|
115
|
+
* // Get WTI forecasts only
|
|
116
|
+
* const wtiForecasts = await client.forecasts.monthly('WTI_USD');
|
|
117
|
+
*
|
|
118
|
+
* wtiForecasts.forEach(forecast => {
|
|
119
|
+
* console.log(`${forecast.period}: $${forecast.forecast_price}`);
|
|
120
|
+
* console.log(` Range: $${forecast.lower_bound} - $${forecast.upper_bound}`);
|
|
121
|
+
* console.log(` Source: ${forecast.source}`);
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
monthly(commodity?: string): Promise<MonthlyForecast[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Get forecast accuracy metrics
|
|
128
|
+
*
|
|
129
|
+
* Returns historical accuracy measurements for forecast sources.
|
|
130
|
+
*
|
|
131
|
+
* @returns Forecast accuracy data
|
|
132
|
+
*
|
|
133
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
134
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const accuracy = await client.forecasts.accuracy();
|
|
139
|
+
* console.log(`Source: ${accuracy.source}`);
|
|
140
|
+
* console.log(`MAPE: ${accuracy.mape}%`);
|
|
141
|
+
* console.log(`RMSE: ${accuracy.rmse}`);
|
|
142
|
+
* console.log(`Sample size: ${accuracy.sample_size} forecasts`);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
accuracy(): Promise<ForecastAccuracy>;
|
|
146
|
+
/**
|
|
147
|
+
* Get archived forecasts
|
|
148
|
+
*
|
|
149
|
+
* Returns historical forecasts with actual outcomes for accuracy analysis.
|
|
150
|
+
*
|
|
151
|
+
* @param year - Optional year filter
|
|
152
|
+
* @returns Array of archived forecasts
|
|
153
|
+
*
|
|
154
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
155
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* // Get all archived forecasts
|
|
160
|
+
* const archive = await client.forecasts.archive();
|
|
161
|
+
*
|
|
162
|
+
* // Get forecasts from specific year
|
|
163
|
+
* const archive2024 = await client.forecasts.archive(2024);
|
|
164
|
+
*
|
|
165
|
+
* archive2024.forEach(forecast => {
|
|
166
|
+
* if (forecast.actual_price) {
|
|
167
|
+
* console.log(`${forecast.year}-${forecast.month}:`);
|
|
168
|
+
* console.log(` Forecast: $${forecast.forecast_price}`);
|
|
169
|
+
* console.log(` Actual: $${forecast.actual_price}`);
|
|
170
|
+
* console.log(` Error: ${forecast.error}%`);
|
|
171
|
+
* }
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
archive(year?: number): Promise<ArchivedForecast[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Get forecast for a specific period
|
|
178
|
+
*
|
|
179
|
+
* @param period - Period identifier (e.g., "2024-03", "2024-Q2")
|
|
180
|
+
* @param commodity - Optional commodity code filter
|
|
181
|
+
* @returns Monthly forecast data
|
|
182
|
+
*
|
|
183
|
+
* @throws {NotFoundError} If period not found
|
|
184
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Get March 2024 forecast
|
|
189
|
+
* const march2024 = await client.forecasts.get('2024-03');
|
|
190
|
+
*
|
|
191
|
+
* // Get Q2 2024 WTI forecast
|
|
192
|
+
* const q2Wti = await client.forecasts.get('2024-Q2', 'WTI_USD');
|
|
193
|
+
*
|
|
194
|
+
* console.log(`Period: ${march2024.period}`);
|
|
195
|
+
* console.log(`Forecast: $${march2024.forecast_price}`);
|
|
196
|
+
* console.log(`Published: ${march2024.published_at}`);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
get(period: string, commodity?: string): Promise<MonthlyForecast>;
|
|
200
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forecasts Resource
|
|
3
|
+
*
|
|
4
|
+
* Access official price forecasts from EIA, IEA, and other agencies including
|
|
5
|
+
* monthly outlooks, accuracy metrics, and historical archives.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Forecasts Resource
|
|
9
|
+
*
|
|
10
|
+
* Access official price forecasts from government agencies and research
|
|
11
|
+
* organizations including EIA, IEA, and others.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { OilPriceAPI } from 'oilpriceapi';
|
|
16
|
+
*
|
|
17
|
+
* const client = new OilPriceAPI({ apiKey: 'your_key' });
|
|
18
|
+
*
|
|
19
|
+
* // Get monthly forecasts
|
|
20
|
+
* const forecasts = await client.forecasts.monthly();
|
|
21
|
+
* forecasts.forEach(f => {
|
|
22
|
+
* console.log(`${f.period}: $${f.forecast_price} (${f.source})`);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Check forecast accuracy
|
|
26
|
+
* const accuracy = await client.forecasts.accuracy();
|
|
27
|
+
* console.log(`EIA MAPE: ${accuracy.mape}%`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class ForecastsResource {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get monthly price forecasts
|
|
36
|
+
*
|
|
37
|
+
* Returns official monthly forecasts from EIA, IEA, and other agencies.
|
|
38
|
+
*
|
|
39
|
+
* @param commodity - Optional commodity code filter
|
|
40
|
+
* @returns Array of monthly forecasts
|
|
41
|
+
*
|
|
42
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
43
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Get all forecasts
|
|
48
|
+
* const allForecasts = await client.forecasts.monthly();
|
|
49
|
+
*
|
|
50
|
+
* // Get WTI forecasts only
|
|
51
|
+
* const wtiForecasts = await client.forecasts.monthly('WTI_USD');
|
|
52
|
+
*
|
|
53
|
+
* wtiForecasts.forEach(forecast => {
|
|
54
|
+
* console.log(`${forecast.period}: $${forecast.forecast_price}`);
|
|
55
|
+
* console.log(` Range: $${forecast.lower_bound} - $${forecast.upper_bound}`);
|
|
56
|
+
* console.log(` Source: ${forecast.source}`);
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async monthly(commodity) {
|
|
61
|
+
const params = {};
|
|
62
|
+
if (commodity)
|
|
63
|
+
params.commodity = commodity;
|
|
64
|
+
const response = await this.client["request"]("/v1/forecasts/monthly", params);
|
|
65
|
+
return Array.isArray(response) ? response : response.forecasts;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get forecast accuracy metrics
|
|
69
|
+
*
|
|
70
|
+
* Returns historical accuracy measurements for forecast sources.
|
|
71
|
+
*
|
|
72
|
+
* @returns Forecast accuracy data
|
|
73
|
+
*
|
|
74
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
75
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const accuracy = await client.forecasts.accuracy();
|
|
80
|
+
* console.log(`Source: ${accuracy.source}`);
|
|
81
|
+
* console.log(`MAPE: ${accuracy.mape}%`);
|
|
82
|
+
* console.log(`RMSE: ${accuracy.rmse}`);
|
|
83
|
+
* console.log(`Sample size: ${accuracy.sample_size} forecasts`);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async accuracy() {
|
|
87
|
+
return this.client["request"]("/v1/forecasts/accuracy", {});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get archived forecasts
|
|
91
|
+
*
|
|
92
|
+
* Returns historical forecasts with actual outcomes for accuracy analysis.
|
|
93
|
+
*
|
|
94
|
+
* @param year - Optional year filter
|
|
95
|
+
* @returns Array of archived forecasts
|
|
96
|
+
*
|
|
97
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
98
|
+
* @throws {AuthenticationError} If API key is invalid
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Get all archived forecasts
|
|
103
|
+
* const archive = await client.forecasts.archive();
|
|
104
|
+
*
|
|
105
|
+
* // Get forecasts from specific year
|
|
106
|
+
* const archive2024 = await client.forecasts.archive(2024);
|
|
107
|
+
*
|
|
108
|
+
* archive2024.forEach(forecast => {
|
|
109
|
+
* if (forecast.actual_price) {
|
|
110
|
+
* console.log(`${forecast.year}-${forecast.month}:`);
|
|
111
|
+
* console.log(` Forecast: $${forecast.forecast_price}`);
|
|
112
|
+
* console.log(` Actual: $${forecast.actual_price}`);
|
|
113
|
+
* console.log(` Error: ${forecast.error}%`);
|
|
114
|
+
* }
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async archive(year) {
|
|
119
|
+
const params = {};
|
|
120
|
+
if (year)
|
|
121
|
+
params.year = year.toString();
|
|
122
|
+
const response = await this.client["request"]("/v1/forecasts/archive", params);
|
|
123
|
+
return Array.isArray(response) ? response : response.forecasts;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get forecast for a specific period
|
|
127
|
+
*
|
|
128
|
+
* @param period - Period identifier (e.g., "2024-03", "2024-Q2")
|
|
129
|
+
* @param commodity - Optional commodity code filter
|
|
130
|
+
* @returns Monthly forecast data
|
|
131
|
+
*
|
|
132
|
+
* @throws {NotFoundError} If period not found
|
|
133
|
+
* @throws {OilPriceAPIError} If API request fails
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Get March 2024 forecast
|
|
138
|
+
* const march2024 = await client.forecasts.get('2024-03');
|
|
139
|
+
*
|
|
140
|
+
* // Get Q2 2024 WTI forecast
|
|
141
|
+
* const q2Wti = await client.forecasts.get('2024-Q2', 'WTI_USD');
|
|
142
|
+
*
|
|
143
|
+
* console.log(`Period: ${march2024.period}`);
|
|
144
|
+
* console.log(`Forecast: $${march2024.forecast_price}`);
|
|
145
|
+
* console.log(`Published: ${march2024.published_at}`);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
async get(period, commodity) {
|
|
149
|
+
if (!period || typeof period !== "string") {
|
|
150
|
+
throw new Error("Period must be a non-empty string");
|
|
151
|
+
}
|
|
152
|
+
const params = {};
|
|
153
|
+
if (commodity)
|
|
154
|
+
params.commodity = commodity;
|
|
155
|
+
return this.client["request"](`/v1/forecasts/monthly/${period}`, params);
|
|
156
|
+
}
|
|
157
|
+
}
|