1010)
1111from .exceptions import ValidationError
1212from .models import DieselPrice , DieselStationsResponse , PriceAlert , Subscription , SubscriptionEvent
13- from .resource_validators import VALID_OPERATORS , format_date , normalize_api_number
13+ from .resource_validators import (
14+ VALID_OPERATORS ,
15+ extract_commodity_catalog ,
16+ format_date ,
17+ normalize_api_number ,
18+ search_commodity_catalog ,
19+ )
1420from .resources ._futures_slug import normalize_futures_slug
1521from .resources .subscriptions import SubscriptionEventsPage
1622
@@ -286,16 +292,19 @@ def __init__(self, client):
286292
287293 async def list (self ) -> List [Dict [str , Any ]]:
288294 response = await self .client .request (method = "GET" , path = "/v1/commodities" )
289- if "data" in response :
290- return response ["data" ]
291- return response
295+ return extract_commodity_catalog (response )
292296
293297 async def get (self , code : str ) -> Dict [str , Any ]:
294298 response = await self .client .request (method = "GET" , path = f"/v1/commodities/{ code } " )
295299 if "data" in response :
296300 return response ["data" ]
297301 return response
298302
303+ async def search (self , query : str , limit : int = 10 ) -> List [Dict [str , Any ]]:
304+ """Search the API's current catalog without a bundled code list."""
305+ catalog = await self .list ()
306+ return search_commodity_catalog (catalog , query = query , limit = limit )
307+
299308 async def categories (self ) -> Dict [str , List [Dict [str , Any ]]]:
300309 response = await self .client .request (method = "GET" , path = "/v1/commodities/categories" )
301310 if "data" in response :
@@ -334,9 +343,9 @@ async def historical(
334343 ) -> List [Dict [str , Any ]]:
335344 slug = normalize_futures_slug (contract )
336345 params = {}
337- if start_date :
346+ if start_date is not None :
338347 params ["start_date" ] = format_date (start_date )
339- if end_date :
348+ if end_date is not None :
340349 params ["end_date" ] = format_date (end_date )
341350 response = await self .client .request (
342351 method = "GET" , path = f"/v1/futures/{ slug } /historical" , params = params
@@ -348,8 +357,8 @@ async def historical(
348357 async def ohlc (self , contract : str , date : Optional [str ] = None ) -> Dict [str , Any ]:
349358 slug = normalize_futures_slug (contract )
350359 params = {}
351- if date :
352- params ["date" ] = date
360+ if date is not None :
361+ params ["date" ] = format_date ( date )
353362 response = await self .client .request (
354363 method = "GET" , path = f"/v1/futures/{ slug } /ohlc" , params = params
355364 )
@@ -442,9 +451,9 @@ async def history(
442451 end_date : Optional [Union [str , date , datetime ]] = None
443452 ) -> List [Dict [str , Any ]]:
444453 params = {}
445- if start_date :
454+ if start_date is not None :
446455 params ["start_date" ] = format_date (start_date )
447- if end_date :
456+ if end_date is not None :
448457 params ["end_date" ] = format_date (end_date )
449458 response = await self .client .request (
450459 method = "GET" , path = f"/v1/storage/{ code } /history" , params = params
@@ -476,9 +485,9 @@ async def historical(
476485 end_date : Optional [Union [str , date , datetime ]] = None
477486 ) -> List [Dict [str , Any ]]:
478487 params = {}
479- if start_date :
488+ if start_date is not None :
480489 params ["start_date" ] = format_date (start_date )
481- if end_date :
490+ if end_date is not None :
482491 params ["end_date" ] = format_date (end_date )
483492 response = await self .client .request (
484493 method = "GET" , path = "/v1/rig-counts/historical" , params = params
@@ -541,9 +550,9 @@ async def historical(
541550 end_date : Optional [Union [str , date , datetime ]] = None
542551 ) -> List [Dict [str , Any ]]:
543552 params : Dict [str , Any ] = {"port" : port , "fuel_type" : fuel_type }
544- if start_date :
553+ if start_date is not None :
545554 params ["start_date" ] = format_date (start_date )
546- if end_date :
555+ if end_date is not None :
547556 params ["end_date" ] = format_date (end_date )
548557 response = await self .client .request (
549558 method = "GET" , path = "/v1/bunker-fuels/historical" , params = params
@@ -806,9 +815,9 @@ async def state(
806815 ** params ,
807816 ) -> Dict [str , Any ]:
808817 if start_date is not None :
809- params ["start_date" ] = start_date
818+ params ["start_date" ] = format_date ( start_date )
810819 if end_date is not None :
811- params ["end_date" ] = end_date
820+ params ["end_date" ] = format_date ( end_date )
812821 response = await self .client .request (
813822 method = "GET" , path = f"/v1/well-production/states/{ code } " , params = params
814823 )
@@ -857,8 +866,8 @@ async def cycle_time(
857866 ) -> Dict [str , Any ]:
858867 filters = {
859868 "state" : state ,
860- "start_date" : start_date ,
861- "end_date" : end_date ,
869+ "start_date" : format_date ( start_date ) if start_date is not None else None ,
870+ "end_date" : format_date ( end_date ) if end_date is not None else None ,
862871 "operator" : operator ,
863872 "formation" : formation ,
864873 "lat" : lat ,
@@ -886,8 +895,8 @@ async def cycle_time_cohorts(
886895 ) -> Dict [str , Any ]:
887896 filters = {
888897 "state" : state ,
889- "start_date" : start_date ,
890- "end_date" : end_date ,
898+ "start_date" : format_date ( start_date ) if start_date is not None else None ,
899+ "end_date" : format_date ( end_date ) if end_date is not None else None ,
891900 "lat" : lat ,
892901 "lng" : lng ,
893902 "radius_miles" : radius_miles ,
0 commit comments