-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasync_resources.py
More file actions
1491 lines (1302 loc) · 55.3 KB
/
Copy pathasync_resources.py
File metadata and controls
1491 lines (1302 loc) · 55.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from datetime import date, datetime
from typing import Any, Dict, List, Optional, Union
from ._subscriptions_common import (
build_attribution_headers,
build_create_body,
unwrap_data,
)
from .exceptions import ValidationError
from .models import DieselPrice, DieselStationsResponse, PriceAlert, Subscription, SubscriptionEvent
from .resource_validators import VALID_OPERATORS, format_date
from .resources._futures_slug import normalize_futures_slug
from .resources.subscriptions import SubscriptionEventsPage
class AsyncDieselResource:
def __init__(self, client):
self.client = client
async def get_price(self, state: str) -> DieselPrice:
if not isinstance(state, str):
raise ValidationError(message="State code must be a string", field="state", value=state)
if len(state) != 2:
raise ValidationError(
message="State code must be a 2-letter US state code (e.g., 'CA', 'TX')",
field="state", value=state
)
response = await self.client.request(
method="GET", path="/v1/diesel-prices", params={"state": state.upper()}
)
if "regional_average" in response:
price_data = response["regional_average"]
elif "data" in response:
price_data = response["data"]
else:
price_data = response
return DieselPrice(**price_data)
async def get_stations(self, lat: float, lng: float, radius: Optional[float] = 8047) -> DieselStationsResponse:
if not isinstance(lat, (int, float)):
raise ValidationError(message="Latitude must be a number", field="lat", value=lat)
if not isinstance(lng, (int, float)):
raise ValidationError(message="Longitude must be a number", field="lng", value=lng)
if lat < -90 or lat > 90:
raise ValidationError(message="Latitude must be between -90 and 90", field="lat", value=lat)
if lng < -180 or lng > 180:
raise ValidationError(message="Longitude must be between -180 and 180", field="lng", value=lng)
if radius is not None:
if not isinstance(radius, (int, float)):
raise ValidationError(message="Radius must be a number", field="radius", value=radius)
if radius < 0 or radius > 50000:
raise ValidationError(
message="Radius must be between 0 and 50000 meters", field="radius", value=radius
)
response = await self.client.request(
method="POST", path="/v1/diesel-prices/stations",
json_data={"lat": lat, "lng": lng, "radius": radius}
)
return DieselStationsResponse(**response)
class AsyncAlertsResource:
def __init__(self, client):
self.client = client
async def list(self) -> List[PriceAlert]:
response = await self.client.request(method="GET", path="/v1/alerts")
if isinstance(response, list):
alerts_data = response
elif "alerts" in response:
alerts_data = response["alerts"]
elif "data" in response:
alerts_data = response["data"]
else:
alerts_data = []
return [PriceAlert(**a) for a in alerts_data]
async def get(self, alert_id: str) -> PriceAlert:
if not alert_id or not isinstance(alert_id, str):
raise ValidationError(
message="Alert ID must be a non-empty string", field="alert_id", value=alert_id
)
response = await self.client.request(method="GET", path=f"/v1/alerts/{alert_id}")
if isinstance(response, dict) and "id" in response:
alert_data = response
elif "alert" in response:
alert_data = response["alert"]
elif "data" in response:
alert_data = response["data"]
else:
alert_data = response
return PriceAlert(**alert_data)
async def create(
self,
name: str,
commodity_code: str,
condition_operator: str,
condition_value: float,
webhook_url: Optional[str] = None,
enabled: bool = True,
cooldown_minutes: int = 60,
metadata: Optional[Dict[str, Any]] = None
) -> PriceAlert:
if not name or not isinstance(name, str):
raise ValidationError(
message="Alert name is required and must be a string", field="name", value=name
)
if len(name) < 1 or len(name) > 100:
raise ValidationError(message="Alert name must be 1-100 characters", field="name", value=name)
if not commodity_code or not isinstance(commodity_code, str):
raise ValidationError(
message="Commodity code is required and must be a string",
field="commodity_code", value=commodity_code
)
if not condition_operator:
raise ValidationError(
message="Condition operator is required", field="condition_operator", value=condition_operator
)
if condition_operator not in VALID_OPERATORS:
raise ValidationError(
message=f"Invalid operator. Must be one of: {', '.join(VALID_OPERATORS)}",
field="condition_operator", value=condition_operator
)
if not isinstance(condition_value, (int, float)):
raise ValidationError(
message="Condition value must be a number", field="condition_value", value=condition_value
)
if condition_value <= 0 or condition_value > 1_000_000:
raise ValidationError(
message="Condition value must be greater than 0 and less than or equal to 1,000,000",
field="condition_value", value=condition_value
)
if webhook_url is not None:
if not isinstance(webhook_url, str):
raise ValidationError(
message="Webhook URL must be a string", field="webhook_url", value=webhook_url
)
if webhook_url and not webhook_url.startswith('https://'):
raise ValidationError(
message="Webhook URL must use HTTPS protocol", field="webhook_url", value=webhook_url
)
if not isinstance(cooldown_minutes, int):
raise ValidationError(
message="Cooldown minutes must be an integer", field="cooldown_minutes", value=cooldown_minutes
)
if cooldown_minutes < 0 or cooldown_minutes > 1440:
raise ValidationError(
message="Cooldown minutes must be between 0 and 1440 (24 hours)",
field="cooldown_minutes", value=cooldown_minutes
)
response = await self.client.request(
method="POST", path="/v1/alerts",
json_data={"price_alert": {
"name": name, "commodity_code": commodity_code,
"condition_operator": condition_operator, "condition_value": condition_value,
"webhook_url": webhook_url, "enabled": enabled,
"cooldown_minutes": cooldown_minutes, "metadata": metadata
}}
)
if isinstance(response, dict) and "id" in response:
alert_data = response
elif "alert" in response:
alert_data = response["alert"]
elif "data" in response:
alert_data = response["data"]
else:
alert_data = response
return PriceAlert(**alert_data)
async def update(
self,
alert_id: str,
name: Optional[str] = None,
commodity_code: Optional[str] = None,
condition_operator: Optional[str] = None,
condition_value: Optional[float] = None,
webhook_url: Optional[str] = None,
enabled: Optional[bool] = None,
cooldown_minutes: Optional[int] = None,
metadata: Optional[Dict[str, Any]] = None
) -> PriceAlert:
if not alert_id or not isinstance(alert_id, str):
raise ValidationError(
message="Alert ID must be a non-empty string", field="alert_id", value=alert_id
)
update_data: Dict[str, Any] = {}
if name is not None:
if not isinstance(name, str) or len(name) < 1 or len(name) > 100:
raise ValidationError(
message="Alert name must be 1-100 characters", field="name", value=name
)
update_data["name"] = name
if commodity_code is not None:
update_data["commodity_code"] = commodity_code
if condition_operator is not None:
if condition_operator not in VALID_OPERATORS:
raise ValidationError(
message=f"Invalid operator. Must be one of: {', '.join(VALID_OPERATORS)}",
field="condition_operator", value=condition_operator
)
update_data["condition_operator"] = condition_operator
if condition_value is not None:
if not isinstance(condition_value, (int, float)):
raise ValidationError(
message="Condition value must be a number", field="condition_value", value=condition_value
)
if condition_value <= 0 or condition_value > 1_000_000:
raise ValidationError(
message="Condition value must be greater than 0 and less than or equal to 1,000,000",
field="condition_value", value=condition_value
)
update_data["condition_value"] = condition_value
if webhook_url is not None:
if webhook_url and (not isinstance(webhook_url, str) or not webhook_url.startswith('https://')):
raise ValidationError(
message="Webhook URL must be a valid HTTPS URL", field="webhook_url", value=webhook_url
)
update_data["webhook_url"] = webhook_url
if enabled is not None:
update_data["enabled"] = enabled
if cooldown_minutes is not None:
if not isinstance(cooldown_minutes, int) or cooldown_minutes < 0 or cooldown_minutes > 1440:
raise ValidationError(
message="Cooldown minutes must be between 0 and 1440 (24 hours)",
field="cooldown_minutes", value=cooldown_minutes
)
update_data["cooldown_minutes"] = cooldown_minutes
if metadata is not None:
update_data["metadata"] = metadata
response = await self.client.request(
method="PATCH", path=f"/v1/alerts/{alert_id}",
json_data={"price_alert": update_data}
)
if isinstance(response, dict) and "id" in response:
alert_data = response
elif "alert" in response:
alert_data = response["alert"]
elif "data" in response:
alert_data = response["data"]
else:
alert_data = response
return PriceAlert(**alert_data)
async def delete(self, alert_id: str) -> None:
if not alert_id or not isinstance(alert_id, str):
raise ValidationError(
message="Alert ID must be a non-empty string", field="alert_id", value=alert_id
)
await self.client.request(method="DELETE", path=f"/v1/alerts/{alert_id}")
async def test(self, alert_id: str) -> Dict[str, Any]:
if not alert_id or not isinstance(alert_id, str):
raise ValidationError(
message="Alert ID must be a non-empty string", field="alert_id", value=alert_id
)
response = await self.client.request(method="POST", path=f"/v1/alerts/{alert_id}/test")
if "data" in response:
return response["data"]
return response
async def triggers(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/alerts/triggers", params=params)
if isinstance(response, list):
return response
elif "triggers" in response:
return response["triggers"]
elif "data" in response:
return response["data"]
return []
async def analytics_history(self, **params) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/alerts/analytics_history", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncCommoditiesResource:
def __init__(self, client):
self.client = client
async def list(self) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/commodities")
if "data" in response:
return response["data"]
return response
async def get(self, code: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/commodities/{code}")
if "data" in response:
return response["data"]
return response
async def categories(self) -> Dict[str, List[Dict[str, Any]]]:
response = await self.client.request(method="GET", path="/v1/commodities/categories")
if "data" in response:
return response["data"]
return response
class AsyncFuturesResource:
"""Async resource for futures contract operations.
Endpoints are keyed by *slug* (e.g. ``"ice-brent"``). Methods accept either
a slug or a friendly contract code (``"BZ"``, ``"CL"``, ``"NG"``, ...),
normalized via :func:`normalize_futures_slug`.
"""
def __init__(self, client):
self.client = client
async def latest(self, contract: str) -> Dict[str, Any]:
"""Get the latest futures curve. Accepts a slug or contract code.
Example:
>>> await client.futures.latest("ice-brent") # or "BZ"
"""
slug = normalize_futures_slug(contract)
response = await self.client.request(method="GET", path=f"/v1/futures/{slug}")
if "data" in response:
return response["data"]
return response
async def historical(
self,
contract: str,
start_date: Optional[Union[str, date, datetime]] = None,
end_date: Optional[Union[str, date, datetime]] = None
) -> List[Dict[str, Any]]:
slug = normalize_futures_slug(contract)
params = {}
if start_date:
params["start_date"] = format_date(start_date)
if end_date:
params["end_date"] = format_date(end_date)
response = await self.client.request(
method="GET", path=f"/v1/futures/{slug}/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def ohlc(self, contract: str, date: Optional[str] = None) -> Dict[str, Any]:
slug = normalize_futures_slug(contract)
params = {}
if date:
params["date"] = date
response = await self.client.request(
method="GET", path=f"/v1/futures/{slug}/ohlc", params=params
)
if "data" in response:
return response["data"]
return response
async def intraday(self, contract: str) -> List[Dict[str, Any]]:
slug = normalize_futures_slug(contract)
response = await self.client.request(method="GET", path=f"/v1/futures/{slug}/intraday")
if "data" in response:
return response["data"]
return response
async def spreads(self, contract1: str, contract2: str) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/futures/spreads",
params={"contract1": contract1, "contract2": contract2}
)
if "data" in response:
return response["data"]
return response
async def curve(self, contract: str) -> List[Dict[str, Any]]:
slug = normalize_futures_slug(contract)
response = await self.client.request(method="GET", path=f"/v1/futures/{slug}/curve")
if "data" in response:
return response["data"]
return response
async def continuous(self, contract: str, months: int = 12) -> List[Dict[str, Any]]:
slug = self._continuous_slug(contract)
response = await self.client.request(
method="GET", path=f"/v1/futures/{slug}/historical", params={"months": months}
)
if "data" in response:
return response["data"]
return response
@staticmethod
def _continuous_slug(contract: str) -> str:
slug = normalize_futures_slug(contract)
if slug.startswith("continuous/"):
return slug
if slug == "ice-brent":
return "continuous/brent"
if slug == "ice-wti":
return "continuous/wti"
raise ValueError(
f"Continuous futures are only available for Brent and WTI, "
f"got {contract!r}. Use 'continuous/brent', 'continuous/wti', "
f"'BZ' or 'CL'."
)
class AsyncStorageResource:
def __init__(self, client):
self.client = client
async def all(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/storage")
if "data" in response:
return response["data"]
return response
async def cushing(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/storage/cushing")
if "data" in response:
return response["data"]
return response
async def spr(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/storage/spr")
if "data" in response:
return response["data"]
return response
async def regional(self, region: Optional[str] = None) -> Dict[str, Any]:
params = {}
if region:
params["region"] = region
response = await self.client.request(method="GET", path="/v1/storage/regional", params=params)
if "data" in response:
return response["data"]
return response
async def history(
self,
code: str,
start_date: Optional[Union[str, date, datetime]] = None,
end_date: Optional[Union[str, date, datetime]] = None
) -> List[Dict[str, Any]]:
params = {}
if start_date:
params["start_date"] = format_date(start_date)
if end_date:
params["end_date"] = format_date(end_date)
response = await self.client.request(
method="GET", path=f"/v1/storage/{code}/history", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncRigCountsResource:
def __init__(self, client):
self.client = client
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/rig-counts/latest")
if "data" in response:
return response["data"]
return response
async def current(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/rig-counts/current")
if "data" in response:
return response["data"]
return response
async def historical(
self,
start_date: Optional[Union[str, date, datetime]] = None,
end_date: Optional[Union[str, date, datetime]] = None
) -> List[Dict[str, Any]]:
params = {}
if start_date:
params["start_date"] = format_date(start_date)
if end_date:
params["end_date"] = format_date(end_date)
response = await self.client.request(
method="GET", path="/v1/rig-counts/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def trends(self, period: str = "monthly") -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/rig-counts/trends", params={"period": period}
)
if "data" in response:
return response["data"]
return response
async def summary(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/rig-counts/summary")
if "data" in response:
return response["data"]
return response
class AsyncBunkerFuelsResource:
def __init__(self, client):
self.client = client
async def all(self) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/bunker-fuels")
if "data" in response:
return response["data"]
return response
async def port(self, code: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/bunker-fuels/ports/{code}")
if "data" in response:
return response["data"]
return response
async def compare(self, ports: List[str]) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/bunker-fuels/compare", params={"ports": ",".join(ports)}
)
if "data" in response:
return response["data"]
return response
async def spreads(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/bunker-fuels/spreads")
if "data" in response:
return response["data"]
return response
async def historical(
self,
port: str,
fuel_type: str,
start_date: Optional[Union[str, date, datetime]] = None,
end_date: Optional[Union[str, date, datetime]] = None
) -> List[Dict[str, Any]]:
params: Dict[str, Any] = {"port": port, "fuel_type": fuel_type}
if start_date:
params["start_date"] = format_date(start_date)
if end_date:
params["end_date"] = format_date(end_date)
response = await self.client.request(
method="GET", path="/v1/bunker-fuels/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def export(self, format: str = "json") -> Any:
response = await self.client.request(
method="GET", path="/v1/bunker-fuels/export", params={"format": format}
)
if format != "json":
return response
if "data" in response:
return response["data"]
return response
class AsyncAnalyticsResource:
def __init__(self, client):
self.client = client
# Wire params mirror the sync AnalyticsResource: the controller reads
# code/code1/code2/period (NOT commodity/commodity1/commodity2/days).
async def performance(self, commodity: Optional[str] = None, days: int = 30) -> Dict[str, Any]:
range_value = "7d" if days <= 7 else ("90d" if days >= 90 else "30d")
params: Dict[str, Any] = {"range": range_value}
response = await self.client.request(
method="GET", path="/v1/analytics/performance", params=params
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
async def statistics(self, commodity: str, days: int = 30) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/analytics/statistics",
params={"code": commodity, "period": days}
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
async def correlation(self, commodity1: str, commodity2: str, days: int = 90) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/analytics/correlation",
params={"code1": commodity1, "code2": commodity2, "period": days}
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
async def trend(self, commodity: str, days: int = 30) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/analytics/trend",
params={"code": commodity, "period": days}
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
async def spread(self, spread: str, days: int = 30) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/analytics/spread",
params={"spread": spread, "period": days}
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
async def forecast(self, commodity: str, method: str = "ema", days: int = 90) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/analytics/forecast",
params={"code": commodity, "method": method, "period": days}
)
if isinstance(response, dict) and "data" in response:
return response["data"]
return response
class AsyncForecastsResource:
def __init__(self, client):
self.client = client
async def monthly(self, commodity: Optional[str] = None) -> Dict[str, Any]:
params = {}
if commodity:
params["commodity"] = commodity
response = await self.client.request(
method="GET", path="/v1/forecasts/monthly", params=params
)
if "data" in response:
return response["data"]
return response
async def accuracy(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/forecasts/accuracy")
if "data" in response:
return response["data"]
return response
async def archive(self, year: Optional[int] = None) -> List[Dict[str, Any]]:
params = {}
if year:
params["year"] = year
response = await self.client.request(
method="GET", path="/v1/forecasts/archive", params=params
)
if "data" in response:
return response["data"]
return response
async def get(self, period: str, commodity: Optional[str] = None) -> Dict[str, Any]:
params = {}
if commodity:
params["commodity"] = commodity
response = await self.client.request(
method="GET", path=f"/v1/forecasts/monthly/{period}", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncDataQualityResource:
def __init__(self, client):
self.client = client
async def summary(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/data-quality/summary")
if "data" in response:
return response["data"]
return response
async def reports(self) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/data-quality/reports")
if "data" in response:
return response["data"]
return response
async def report(self, code: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/data-quality/reports/{code}")
if "data" in response:
return response["data"]
return response
class AsyncDrillingIntelligenceResource:
def __init__(self, client):
self.client = client
async def list(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence", params=params
)
if "data" in response:
return response["data"]
return response
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/drilling-intelligence/latest")
if "data" in response:
return response["data"]
return response
async def summary(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/drilling-intelligence/summary")
if "data" in response:
return response["data"]
return response
async def trends(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/trends", params=params
)
if "data" in response:
return response["data"]
return response
async def frac_spreads(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/frac-spreads", params=params
)
if "data" in response:
return response["data"]
return response
async def well_permits(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/well-permits", params=params
)
if "data" in response:
return response["data"]
return response
async def duc_wells(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/duc-wells", params=params
)
if "data" in response:
return response["data"]
return response
async def completions(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/completions", params=params
)
if "data" in response:
return response["data"]
return response
async def wells_drilled(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/drilling-intelligence/wells-drilled", params=params
)
if "data" in response:
return response["data"]
return response
async def basin(self, name: str) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path=f"/v1/drilling-intelligence/basin/{name}"
)
if "data" in response:
return response["data"]
return response
# EI sub-resources
class AsyncEIRigCountsResource:
def __init__(self, client):
self.client = client
async def list(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/ei/rig_counts", params=params)
if "data" in response:
return response["data"]
return response
async def get(self, id: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/ei/rig_counts/{id}")
if "data" in response:
return response["data"]
return response
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/rig_counts/latest")
if "data" in response:
return response["data"]
return response
async def by_basin(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/rig_counts/by_basin", params=params
)
if "data" in response:
return response["data"]
return response
async def by_state(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/rig_counts/by_state", params=params
)
if "data" in response:
return response["data"]
return response
async def historical(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/rig_counts/historical", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncEIOilInventoriesResource:
def __init__(self, client):
self.client = client
async def list(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/ei/oil_inventories", params=params)
if "data" in response:
return response["data"]
return response
async def get(self, id: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/ei/oil_inventories/{id}")
if "data" in response:
return response["data"]
return response
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/oil_inventories/latest")
if "data" in response:
return response["data"]
return response
async def summary(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/oil_inventories/summary")
if "data" in response:
return response["data"]
return response
async def by_product(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/oil_inventories/by_product", params=params
)
if "data" in response:
return response["data"]
return response
async def historical(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/oil_inventories/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def cushing(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/oil_inventories/cushing")
if "data" in response:
return response["data"]
return response
class AsyncEIOpecProductionResource:
def __init__(self, client):
self.client = client
async def list(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(method="GET", path="/v1/ei/opec_productions", params=params)
if "data" in response:
return response["data"]
return response
async def get(self, id: str) -> Dict[str, Any]:
response = await self.client.request(method="GET", path=f"/v1/ei/opec_productions/{id}")
if "data" in response:
return response["data"]
return response
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/opec_productions/latest")
if "data" in response:
return response["data"]
return response
async def total(self) -> Dict[str, Any]:
response = await self.client.request(method="GET", path="/v1/ei/opec_productions/total")
if "data" in response:
return response["data"]
return response
async def by_country(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/opec_productions/by_country", params=params
)
if "data" in response:
return response["data"]
return response
async def historical(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/opec_productions/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def top_producers(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/opec_productions/top_producers", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncEIDrillingProductivityResource:
def __init__(self, client):
self.client = client
async def list(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities", params=params
)
if "data" in response:
return response["data"]
return response
async def get(self, id: str) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path=f"/v1/ei/drilling_productivities/{id}"
)
if "data" in response:
return response["data"]
return response
async def latest(self) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/latest"
)
if "data" in response:
return response["data"]
return response
async def summary(self) -> Dict[str, Any]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/summary"
)
if "data" in response:
return response["data"]
return response
async def duc_wells(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/duc_wells", params=params
)
if "data" in response:
return response["data"]
return response
async def by_basin(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/by_basin", params=params
)
if "data" in response:
return response["data"]
return response
async def historical(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/historical", params=params
)
if "data" in response:
return response["data"]
return response
async def trends(self, **params) -> List[Dict[str, Any]]:
response = await self.client.request(
method="GET", path="/v1/ei/drilling_productivities/trends", params=params
)
if "data" in response:
return response["data"]
return response
class AsyncEIForecastsResource:
def __init__(self, client):
self.client = client