Skip to main content

News (PHP SDK)

  • Last updated
  • View as Markdown

Retrieve news articles for a stock symbol.

Beta Endpoint

The news endpoint is currently in beta. Features and response formats may change.

Making Requests​

Use the news() method on the stocks resource to fetch news articles:

Output FormatReturn TypeDescription
JSONNewsReturns a News object containing news articles (default).
CSVNewsReturns a News object with CSV data accessible via getCsv().
HTMLNewsReturns a News object with HTML data accessible via getHtml().
HTML Not Yet Available

Format::HTML is included for forward compatibility, but HTML responses are not currently implemented by the Market Data API.

news​

public function news(
string $symbol,
?string $from = null,
?string $to = null,
?int $countback = null,
?string $date = null,
?Parameters $parameters = null
): News

Retrieve news articles for a given stock symbol.

Parameters​

  • symbol (string)

    The stock ticker symbol (e.g., "AAPL").

  • from (string, optional)

    The earliest news to include. If omitted without countback, returns recent news. Accepted formats: ISO 8601, Unix timestamp.

  • to (string, optional)

    The latest news to include. Accepted formats: ISO 8601, Unix timestamp.

  • countback (int, optional)

    Number of news articles to return before to. Use instead of from.

  • date (string, optional)

    Retrieve news for a specific day. Accepted formats: ISO 8601, Unix timestamp.

  • parameters (Parameters, optional)

    Universal parameters for customizing the output format. See Parameters for details.

Returns​

  • News

    A News response object containing an array of Article objects.

<?php

use MarketDataApp\Client;

$client = new Client();

// Get news and display with a single line
$news = $client->stocks->news('AAPL', from: '2024-01-01');
echo $news;

// Or display individual articles
foreach ($news->articles as $article) {
echo $article . "\n\n";
}

Output

News: 3 articles (status: ok)
AAPL: Apple Reports Record Q1 Earnings
Published: Jan 25, 2024 4:30 PM Source: https://www.reuters.com/...
Content: Apple Inc reported record quarterly earnings on Thursday...

AAPL: Apple Reports Record Q1 Earnings
Published: Jan 25, 2024 4:30 PM Source: https://www.reuters.com/...
Content: Apple Inc reported record quarterly earnings on Thursday...

News​

class News extends ResponseBase
{
public string $status;
/** @var Article[] */
public array $articles;
}

Represents news articles for a stock. Contains an array of Article objects, each representing a single news article.

Properties​

  • status (string): Response status ("ok" or "no_data").
  • articles (Article[]): Array of Article objects containing individual news article data.

Methods​

  • getCsv(): Returns the raw CSV data (when using Format::CSV).
  • getHtml(): Returns the raw HTML data (when using Format::HTML).
  • isJson(): Returns true if the response contains JSON data.

Article​

class Article
{
public string $symbol;
public string $headline;
public string $content;
public string $source;
public Carbon $publication_date;
}

Represents a single news article.

Properties​

  • symbol (string): The stock ticker symbol this article relates to.
  • headline (string): The article headline/title.
  • content (string): The content of the article, if available. May include captions, copyright notices, and other elements that may need filtering.
  • source (string): The source URL where the news appeared.
  • publication_date (Carbon): The date the news was published on the source website.