Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ All notable changes to this package are documented here. The format follows

## [Unreleased]

### Added

- **News API: `direction` parameter** on `financial_news` (`APIClient` and `FinancialNewsAPI`).
`0` (default) is newest first; `1` returns articles in the order they entered the
database, so a client can page forward with `offset` without duplicates. With
`direction=1`, `from_date` and `to_date` are required and the window must not exceed
31 days (both ends counted); the API answers 422 otherwise.

### Changed

- **News API: `offset` cap raised** to 10000 (was 9000); `offset + limit` must not exceed 10000.

## [1.4.0] — 2026-08-28

The first release since **1.0.32 (2024-12-18)**. Twenty months of work reached `main`
Expand Down
14 changes: 12 additions & 2 deletions eodhd/APIs/FinancialNewsAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def financial_news(
to_date: str | None = None,
limit: int | None = None,
offset: int | None = None,
direction: int | None = None,
):
"""
GET /api/news
Expand All @@ -32,8 +33,15 @@ def financial_news(
If both s and t are provided, this method keeps backward-compatible behavior and
prefers `s` (same as the old implementation).

`offset` maximum is 9000. To reach older articles, narrow the period with
from_date / to_date.
`offset` maximum is 10000, and offset + limit must not exceed 10000. To reach
older articles, narrow the period with from_date / to_date.

direction (optional, 0 or 1; API default 0):
- 0: newest first.
- 1: articles in the order they entered the database, so you can page forward
with `offset` without duplicates. Requires from_date and to_date, and the
window between them must not exceed 31 days (both ends counted); otherwise
the API answers 422.
"""
endpoint = "news"
query_string = ""
Expand All @@ -55,6 +63,8 @@ def financial_news(
query_string += "&from=" + str(from_date)
if to_date is not None:
query_string += "&to=" + str(to_date)
if direction is not None:
query_string += "&direction=" + str(direction)

return self._rest_get_method(api_key=api_token, endpoint=endpoint, querystring=query_string)

Expand Down
8 changes: 6 additions & 2 deletions eodhd/apiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,15 +1145,18 @@ def get_stock_market_tick_data(
limit=limit
)

def financial_news(self, s=None, t=None, from_date=None, to_date=None, limit=None, offset=None):
def financial_news(self, s=None, t=None, from_date=None, to_date=None, limit=None, offset=None, direction=None):
"""
Available args:
s (required if t empty) - The ticker code to get news for, e.g. AAPL.US
t (required if s empty) - Topic tag to get news for (tags are dynamic / AI-detected)
from_date (not required) - Start date (YYYY-MM-DD)
to_date (not required) - End date (YYYY-MM-DD)
limit (not required) - Number of results (default: 50, min: 1, max: 1000)
offset (not required) - Offset for pagination (default: 0)
offset (not required) - Offset for pagination (default: 0, max: 10000; offset + limit must not exceed 10000)
direction (not required) - 0 = newest first (default); 1 = in the order articles entered the
database, for paging forward with offset without duplicates. With 1, from_date and to_date
are required and the window must not exceed 31 days (both ends counted), else the API answers 422
"""
api_call = FinancialNewsAPI(session=self._session, timeout=self._timeout)
return api_call.financial_news(
Expand All @@ -1164,6 +1167,7 @@ def financial_news(self, s=None, t=None, from_date=None, to_date=None, limit=Non
to_date=to_date,
limit=limit,
offset=offset,
direction=direction,
)

def get_sentiment(self, s, from_date=None, to_date=None):
Expand Down
56 changes: 56 additions & 0 deletions tests/test_financial_news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests for the News API `direction` parameter (GET /api/news)."""

from urllib.parse import parse_qs, urlsplit

import pytest
from unittest.mock import MagicMock

from eodhd import APIClient


@pytest.fixture
def client():
api = APIClient(api_key="test1234567890123456")
session = MagicMock()
resp = MagicMock()
resp.status_code = 200
resp.json.return_value = []
session.get.return_value = resp
api._session = session
return api


def _split(session):
url = session.get.call_args[0][0]
parts = urlsplit(url)
return parts.path, parse_qs(parts.query, keep_blank_values=True)


def test_financial_news_direction_forwarded(client):
client.financial_news(s="AAPL.US", from_date="2026-10-01", to_date="2026-10-15",
limit=100, offset=9900, direction=1)
path, qs = _split(client._session)
assert path.rstrip("/").endswith("/news")
assert qs["direction"] == ["1"]
assert qs["s"] == ["AAPL.US"]
assert qs["from"] == ["2026-10-01"]
assert qs["to"] == ["2026-10-15"]
assert qs["limit"] == ["100"]
assert qs["offset"] == ["9900"]


def test_financial_news_direction_zero_forwarded(client):
client.financial_news(s="AAPL.US", direction=0)
_, qs = _split(client._session)
assert qs["direction"] == ["0"]


def test_financial_news_direction_absent_when_none(client):
client.financial_news(s="AAPL.US", limit=10)
_, qs = _split(client._session)
assert "direction" not in qs


def test_financial_news_requires_s_or_t(client):
with pytest.raises(ValueError):
client.financial_news(direction=1)