Skip to main content

News (Python SDK)

  • Last updated
  • View as Markdown

Retrieve news articles for any supported stock symbol.

Making Requests​

Use the news() method on the stocks resource to fetch news articles. The method supports multiple output formats:

Output FormatReturn TypeDescription
DATAFRAMEpandas.DataFrame or polars.DataFrameReturns a DataFrame with news articles indexed by symbol (default).
INTERNALlist[StockNews] or list[StockNewsHumanReadable]Returns a list of StockNews objects. When use_human_readable=True, returns a list of StockNewsHumanReadable objects with capitalized field names.
JSONdictReturns the raw JSON response as a dictionary.
CSVstrWrites CSV data to file and returns the filename string.

news​

def news(
symbol: str,
*,
date: str | datetime.datetime = None,
from_date: str | datetime.datetime = None,
to_date: str | datetime.datetime = None,
countback: int = None,
output_format: OutputFormat = OutputFormat.DATAFRAME,
date_format: DateFormat = None,
columns: list[str] = None,
add_headers: bool = None,
use_human_readable: bool = False,
mode: Mode = None,
filename: str | Path = None,
) -> list[StockNews] | list[StockNewsHumanReadable] | dict | str | MarketDataClientErrorResult

Fetches news articles for a stock symbol. The symbol parameter can be passed as the first positional argument or as a keyword argument. All other parameters must be keyword-only.

Parameters​

  • symbol (str)

    The stock symbol for which to fetch news articles.

  • date (str | datetime.datetime, optional)

    Specific date for the news articles.

  • from_date (str | datetime.datetime, optional)

    Start date for the date range.

  • to_date (str | datetime.datetime, optional)

    End date for the date range.

  • countback (int, optional)

    Number of news articles to return, counting backwards from the to_date.

  • output_format (OutputFormat, optional)

    The format of the returned data. Defaults to OutputFormat.DATAFRAME. See Settings for details.

  • date_format (DateFormat, optional)

    The date format to use in the response. Defaults to DateFormat.UNIX. See Settings for details.

  • columns (optional)

    Specify which columns to include in the response. See Settings for details.

  • add_headers (optional)

    Whether to include headers in the response. See Settings for details.

  • use_human_readable (optional)

    Whether to use human-readable format for values. Only applies when output_format=OutputFormat.INTERNAL. See Settings for details.

  • mode (Mode, optional)

    The data mode to use. See Settings for details.

  • filename (str | Path, optional)

    File path for CSV output (only used with output_format=OutputFormat.CSV).

Returns​

  • list[StockNews] | list[StockNewsHumanReadable] | dict | str | MarketDataClientErrorResult

    The news articles in the requested format, or a MarketDataClientErrorResult if an error occurred.

from marketdata import MarketDataClient

client = MarketDataClient()

# Get stock news as DataFrame (default)
# symbol can be passed positionally or as keyword
df = client.stocks.news("AAPL")
# or
df = client.stocks.news(symbol="AAPL")

print(df)

StockNews​

@dataclass
class StockNews:
symbol: str
headline: str
content: str
source: str
publicationDate: datetime.datetime
updated: datetime.datetime

StockNews represents a single news article for a stock, encapsulating headline, content, source, and publication information.

Properties​

  • symbol (str): The stock symbol.
  • headline (str): The news headline.
  • content (str): The news article content.
  • source (str): The news source.
  • publicationDate (datetime.datetime): The publication date (automatically converted from timestamp).
  • updated (datetime.datetime): The time when the news was last updated (automatically converted from timestamp).

Notes​

  • The publicationDate and updated fields are automatically converted to datetime.datetime objects from Unix timestamps.

StockNewsHumanReadable​

@dataclass
class StockNewsHumanReadable:
Symbol: str
headline: str
content: str
source: str
publicationDate: datetime.datetime
Date: datetime.datetime

StockNewsHumanReadable represents a news article in human-readable format with capitalized field names and formatted values.

Properties​

  • Symbol (str): The stock symbol.
  • headline (str): The news headline.
  • content (str): The news article content.
  • source (str): The news source.
  • publicationDate (datetime.datetime): The publication date (automatically converted from timestamp).
  • Date (datetime.datetime): The time when the news was last updated (automatically converted from timestamp).

Notes​

  • The publicationDate and Date fields are automatically converted to datetime.datetime objects from Unix timestamps.
  • Field names use capitalized format with underscores where applicable (e.g., Symbol instead of symbol, Date instead of updated).