From 538155ebeecc7c93acc1e93f2bc51ec8b11bc14d Mon Sep 17 00:00:00 2001 From: alexpipipi Date: Tue, 28 Jul 2026 17:55:30 +0300 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20UST=20endpoints=20have=20no=20pagina?= =?UTF-8?q?tion/date-range=20params=20=E2=80=94=20align=20SDK=20to=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eodhd/APIs/TreasuryAPI.py | 45 +++++++++++---------------------------- eodhd/apiclient.py | 16 +++++++------- tests/test_treasury.py | 10 +++++---- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/eodhd/APIs/TreasuryAPI.py b/eodhd/APIs/TreasuryAPI.py index c35dff1..7843404 100644 --- a/eodhd/APIs/TreasuryAPI.py +++ b/eodhd/APIs/TreasuryAPI.py @@ -11,27 +11,24 @@ class TreasuryAPI(BaseAPI): GET /api/ust/yield-rates GET /api/ust/long-term-rates GET /api/ust/real-yield-rates + + These endpoints do not support pagination or date-range filtering + (page[limit], page[offset], from, to are ignored by the API). The full + dataset for a given year is always returned. """ - def _get_treasury_data(self, api_token: str, rate_type: str, from_date: str = None, to_date: str = None): + def _get_treasury_data(self, api_token: str, rate_type: str): """Internal helper for treasury endpoints.""" endpoint = "ust" uri = rate_type - querystring = "" - - if from_date is not None: - querystring += f"&from={from_date}" - if to_date is not None: - querystring += f"&to={to_date}" return self._rest_get_method( api_key=api_token, endpoint=endpoint, uri=uri, - querystring=querystring, ) - def get_treasury_bill_rates(self, api_token: str, from_date: str = None, to_date: str = None): + def get_treasury_bill_rates(self, api_token: str): """ Get US Treasury bill rates. @@ -39,19 +36,15 @@ def get_treasury_bill_rates(self, api_token: str, from_date: str = None, to_date ---------- api_token : str Your EODHD API token. - from_date : str, optional - Start date in YYYY-MM-DD format. - to_date : str, optional - End date in YYYY-MM-DD format. Returns ------- list[dict] Treasury bill rate data. """ - return self._get_treasury_data(api_token, "bill-rates", from_date, to_date) + return self._get_treasury_data(api_token, "bill-rates") - def get_treasury_yield_rates(self, api_token: str, from_date: str = None, to_date: str = None): + def get_treasury_yield_rates(self, api_token: str): """ Get US Treasury yield curve rates. @@ -59,19 +52,15 @@ def get_treasury_yield_rates(self, api_token: str, from_date: str = None, to_dat ---------- api_token : str Your EODHD API token. - from_date : str, optional - Start date in YYYY-MM-DD format. - to_date : str, optional - End date in YYYY-MM-DD format. Returns ------- list[dict] Treasury yield rate data. """ - return self._get_treasury_data(api_token, "yield-rates", from_date, to_date) + return self._get_treasury_data(api_token, "yield-rates") - def get_treasury_long_term_rates(self, api_token: str, from_date: str = None, to_date: str = None): + def get_treasury_long_term_rates(self, api_token: str): """ Get US Treasury long-term rates. @@ -79,19 +68,15 @@ def get_treasury_long_term_rates(self, api_token: str, from_date: str = None, to ---------- api_token : str Your EODHD API token. - from_date : str, optional - Start date in YYYY-MM-DD format. - to_date : str, optional - End date in YYYY-MM-DD format. Returns ------- list[dict] Treasury long-term rate data. """ - return self._get_treasury_data(api_token, "long-term-rates", from_date, to_date) + return self._get_treasury_data(api_token, "long-term-rates") - def get_treasury_real_yield_rates(self, api_token: str, from_date: str = None, to_date: str = None): + def get_treasury_real_yield_rates(self, api_token: str): """ Get US Treasury real yield curve rates. @@ -99,14 +84,10 @@ def get_treasury_real_yield_rates(self, api_token: str, from_date: str = None, t ---------- api_token : str Your EODHD API token. - from_date : str, optional - Start date in YYYY-MM-DD format. - to_date : str, optional - End date in YYYY-MM-DD format. Returns ------- list[dict] Treasury real yield rate data. """ - return self._get_treasury_data(api_token, "real-yield-rates", from_date, to_date) + return self._get_treasury_data(api_token, "real-yield-rates") diff --git a/eodhd/apiclient.py b/eodhd/apiclient.py index de5c79e..c01c169 100644 --- a/eodhd/apiclient.py +++ b/eodhd/apiclient.py @@ -1558,37 +1558,37 @@ def get_bulk_fundamentals_v1_1(self, exchange, symbols=None, offset=None, limit= api_token=self._api_key, exchange=exchange, symbols=symbols, offset=offset, limit=limit, ) - def get_treasury_bill_rates(self, from_date=None, to_date=None): + def get_treasury_bill_rates(self): """ US Treasury Bill Rates Endpoint: GET /api/ust/bill-rates """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_bill_rates(api_token=self._api_key, from_date=from_date, to_date=to_date) + return api_call.get_treasury_bill_rates(api_token=self._api_key) - def get_treasury_yield_rates(self, from_date=None, to_date=None): + def get_treasury_yield_rates(self): """ US Treasury Yield Curve Rates Endpoint: GET /api/ust/yield-rates """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_yield_rates(api_token=self._api_key, from_date=from_date, to_date=to_date) + return api_call.get_treasury_yield_rates(api_token=self._api_key) - def get_treasury_long_term_rates(self, from_date=None, to_date=None): + def get_treasury_long_term_rates(self): """ US Treasury Long-Term Rates Endpoint: GET /api/ust/long-term-rates """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_long_term_rates(api_token=self._api_key, from_date=from_date, to_date=to_date) + return api_call.get_treasury_long_term_rates(api_token=self._api_key) - def get_treasury_real_yield_rates(self, from_date=None, to_date=None): + def get_treasury_real_yield_rates(self): """ US Treasury Real Yield Curve Rates Endpoint: GET /api/ust/real-yield-rates """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_real_yield_rates(api_token=self._api_key, from_date=from_date, to_date=to_date) + return api_call.get_treasury_real_yield_rates(api_token=self._api_key) # ── Phase 2: Marketplace ────────────────────────────────────── diff --git a/tests/test_treasury.py b/tests/test_treasury.py index 1e38b39..8a83503 100644 --- a/tests/test_treasury.py +++ b/tests/test_treasury.py @@ -59,11 +59,13 @@ def test_real_yield_rates(mock_session): assert "/ust/real-yield-rates" in call_url -def test_date_params(mock_session): +def test_no_pagination_or_date_params(mock_session): + """UST endpoints ignore pagination/date-range params, so the SDK must not emit them.""" _mock_response(mock_session) api = _make_api(mock_session) - api.get_treasury_bill_rates(api_token="test1234567890123456", from_date="2024-01-01", to_date="2024-06-01") + api.get_treasury_bill_rates(api_token="test1234567890123456") call_url = mock_session.get.call_args[0][0] - assert "&from=2024-01-01" in call_url - assert "&to=2024-06-01" in call_url + assert "from=" not in call_url + assert "to=" not in call_url + assert "page[" not in call_url From 552ab9aefe13ddca5dcb023c853a1267933fa5e7 Mon Sep 17 00:00:00 2001 From: alexpipipi Date: Wed, 29 Jul 2026 11:30:03 +0300 Subject: [PATCH 2/2] feat: expose filter[year] on UST methods so callers can select historical years --- eodhd/APIs/TreasuryAPI.py | 48 +++++++++++++++++++++++++++++---------- eodhd/apiclient.py | 40 +++++++++++++++++++++++++------- tests/test_treasury.py | 28 +++++++++++++++++++++++ 3 files changed, 96 insertions(+), 20 deletions(-) diff --git a/eodhd/APIs/TreasuryAPI.py b/eodhd/APIs/TreasuryAPI.py index 7843404..89acb5a 100644 --- a/eodhd/APIs/TreasuryAPI.py +++ b/eodhd/APIs/TreasuryAPI.py @@ -13,22 +13,30 @@ class TreasuryAPI(BaseAPI): GET /api/ust/real-yield-rates These endpoints do not support pagination or date-range filtering - (page[limit], page[offset], from, to are ignored by the API). The full - dataset for a given year is always returned. + (page[limit], page[offset], from, to are ignored by the API). The only + supported filter is filter[year], which selects a single calendar year; + when omitted the API returns the current year's dataset. """ - def _get_treasury_data(self, api_token: str, rate_type: str): - """Internal helper for treasury endpoints.""" + def _get_treasury_data(self, api_token: str, rate_type: str, year: int = None): + """Internal helper for treasury endpoints. + + When ``year`` is provided it is sent as filter[year]=; otherwise + no filter is emitted and the API defaults to the current year. + """ endpoint = "ust" uri = rate_type + query_string = self._filter("year", year) + return self._rest_get_method( api_key=api_token, endpoint=endpoint, uri=uri, + querystring=query_string, ) - def get_treasury_bill_rates(self, api_token: str): + def get_treasury_bill_rates(self, api_token: str, year: int = None): """ Get US Treasury bill rates. @@ -36,15 +44,19 @@ def get_treasury_bill_rates(self, api_token: str): ---------- api_token : str Your EODHD API token. + year : int, optional + Calendar year to select (sent as filter[year]). Defaults to the + current year when omitted. This is the only supported filter — the + endpoint has no pagination and no date-range parameters. Returns ------- list[dict] Treasury bill rate data. """ - return self._get_treasury_data(api_token, "bill-rates") + return self._get_treasury_data(api_token, "bill-rates", year=year) - def get_treasury_yield_rates(self, api_token: str): + def get_treasury_yield_rates(self, api_token: str, year: int = None): """ Get US Treasury yield curve rates. @@ -52,15 +64,19 @@ def get_treasury_yield_rates(self, api_token: str): ---------- api_token : str Your EODHD API token. + year : int, optional + Calendar year to select (sent as filter[year]). Defaults to the + current year when omitted. This is the only supported filter — the + endpoint has no pagination and no date-range parameters. Returns ------- list[dict] Treasury yield rate data. """ - return self._get_treasury_data(api_token, "yield-rates") + return self._get_treasury_data(api_token, "yield-rates", year=year) - def get_treasury_long_term_rates(self, api_token: str): + def get_treasury_long_term_rates(self, api_token: str, year: int = None): """ Get US Treasury long-term rates. @@ -68,15 +84,19 @@ def get_treasury_long_term_rates(self, api_token: str): ---------- api_token : str Your EODHD API token. + year : int, optional + Calendar year to select (sent as filter[year]). Defaults to the + current year when omitted. This is the only supported filter — the + endpoint has no pagination and no date-range parameters. Returns ------- list[dict] Treasury long-term rate data. """ - return self._get_treasury_data(api_token, "long-term-rates") + return self._get_treasury_data(api_token, "long-term-rates", year=year) - def get_treasury_real_yield_rates(self, api_token: str): + def get_treasury_real_yield_rates(self, api_token: str, year: int = None): """ Get US Treasury real yield curve rates. @@ -84,10 +104,14 @@ def get_treasury_real_yield_rates(self, api_token: str): ---------- api_token : str Your EODHD API token. + year : int, optional + Calendar year to select (sent as filter[year]). Defaults to the + current year when omitted. This is the only supported filter — the + endpoint has no pagination and no date-range parameters. Returns ------- list[dict] Treasury real yield rate data. """ - return self._get_treasury_data(api_token, "real-yield-rates") + return self._get_treasury_data(api_token, "real-yield-rates", year=year) diff --git a/eodhd/apiclient.py b/eodhd/apiclient.py index c01c169..0b0a3fa 100644 --- a/eodhd/apiclient.py +++ b/eodhd/apiclient.py @@ -1558,37 +1558,61 @@ def get_bulk_fundamentals_v1_1(self, exchange, symbols=None, offset=None, limit= api_token=self._api_key, exchange=exchange, symbols=symbols, offset=offset, limit=limit, ) - def get_treasury_bill_rates(self): + def get_treasury_bill_rates(self, year: int = None): """ US Treasury Bill Rates Endpoint: GET /api/ust/bill-rates + + Args: + year [OPTIONAL] - calendar year to select (sent as filter[year]). + Defaults to the current year when omitted. This is the only + supported filter: the endpoint has no pagination and no + date-range parameters. """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_bill_rates(api_token=self._api_key) + return api_call.get_treasury_bill_rates(api_token=self._api_key, year=year) - def get_treasury_yield_rates(self): + def get_treasury_yield_rates(self, year: int = None): """ US Treasury Yield Curve Rates Endpoint: GET /api/ust/yield-rates + + Args: + year [OPTIONAL] - calendar year to select (sent as filter[year]). + Defaults to the current year when omitted. This is the only + supported filter: the endpoint has no pagination and no + date-range parameters. """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_yield_rates(api_token=self._api_key) + return api_call.get_treasury_yield_rates(api_token=self._api_key, year=year) - def get_treasury_long_term_rates(self): + def get_treasury_long_term_rates(self, year: int = None): """ US Treasury Long-Term Rates Endpoint: GET /api/ust/long-term-rates + + Args: + year [OPTIONAL] - calendar year to select (sent as filter[year]). + Defaults to the current year when omitted. This is the only + supported filter: the endpoint has no pagination and no + date-range parameters. """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_long_term_rates(api_token=self._api_key) + return api_call.get_treasury_long_term_rates(api_token=self._api_key, year=year) - def get_treasury_real_yield_rates(self): + def get_treasury_real_yield_rates(self, year: int = None): """ US Treasury Real Yield Curve Rates Endpoint: GET /api/ust/real-yield-rates + + Args: + year [OPTIONAL] - calendar year to select (sent as filter[year]). + Defaults to the current year when omitted. This is the only + supported filter: the endpoint has no pagination and no + date-range parameters. """ api_call = TreasuryAPI(session=self._session, timeout=self._timeout) - return api_call.get_treasury_real_yield_rates(api_token=self._api_key) + return api_call.get_treasury_real_yield_rates(api_token=self._api_key, year=year) # ── Phase 2: Marketplace ────────────────────────────────────── diff --git a/tests/test_treasury.py b/tests/test_treasury.py index 8a83503..7bc0ea7 100644 --- a/tests/test_treasury.py +++ b/tests/test_treasury.py @@ -69,3 +69,31 @@ def test_no_pagination_or_date_params(mock_session): assert "from=" not in call_url assert "to=" not in call_url assert "page[" not in call_url + + +def test_no_year_filter_when_omitted(mock_session): + """When year is omitted, no filter[year] must be emitted (API defaults to current year).""" + _mock_response(mock_session) + api = _make_api(mock_session) + api.get_treasury_bill_rates(api_token="test1234567890123456") + + call_url = mock_session.get.call_args[0][0] + assert "filter[year]" not in call_url + assert "filter[" not in call_url + + +def test_year_filter_emitted(mock_session): + """When year is passed, filter[year]= is emitted on every UST endpoint.""" + _mock_response(mock_session) + api = _make_api(mock_session) + + for method, path in ( + (api.get_treasury_bill_rates, "/ust/bill-rates"), + (api.get_treasury_yield_rates, "/ust/yield-rates"), + (api.get_treasury_long_term_rates, "/ust/long-term-rates"), + (api.get_treasury_real_yield_rates, "/ust/real-yield-rates"), + ): + method(api_token="test1234567890123456", year=2024) + call_url = mock_session.get.call_args[0][0] + assert path in call_url + assert "filter[year]=2024" in call_url