News
Retrieve news articles for a stock symbol.
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 Format | Return Type | Description |
|---|---|---|
| JSON | News | Returns a News object containing news articles (default). |
| CSV | News | Returns a News object with CSV data accessible via getCsv(). |
| HTML | News | Returns a News object with HTML data accessible via getHtml(). |
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 offrom. -
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
-
NewsA News response object containing an array of Article objects.
- Example (Quick Display)
- Example (Recent News)
- Example (Date Range)
- Example (Specific Date)
- Example (CSV)
<?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...
<?php
use MarketDataApp\Client;
$client = new Client();
// Get recent news for AAPL
$news = $client->stocks->news('AAPL');
foreach ($news->articles as $article) {
echo "Symbol: " . $article->symbol . "\n";
echo "Title: " . $article->headline . "\n";
echo "Source: " . $article->source . "\n";
echo "Published: " . $article->publication_date->format('Y-m-d H:i') . "\n";
echo "Content: " . substr($article->content, 0, 100) . "...\n\n";
}
Output
Symbol: AAPL
Title: Apple Reports Record Q1 Earnings
Source: https://www.reuters.com/technology/...
Published: 2024-01-25 16:30
Content: Apple Inc reported record quarterly earnings on Thursday...
<?php
use MarketDataApp\Client;
$client = new Client();
// Get news for a specific date range
$news = $client->stocks->news(
symbol: 'AAPL',
from: '2024-01-01',
to: '2024-01-31'
);
if ($news->status === 'ok') {
echo "Found " . count($news->articles) . " articles:\n\n";
foreach ($news->articles as $article) {
echo "- " . $article->headline . "\n";
echo " Published: " . $article->publication_date->format('Y-m-d H:i') . "\n\n";
}
}
<?php
use MarketDataApp\Client;
$client = new Client();
// Get news for a specific date
$news = $client->stocks->news(
symbol: 'AAPL',
date: '2024-01-25'
);
echo "News for January 25, 2024:\n";
echo "==========================\n\n";
foreach ($news->articles as $article) {
echo "* " . $article->headline . "\n";
echo " " . $article->source . " | " . $article->publication_date->format('H:i') . "\n\n";
}
<?php
use MarketDataApp\Client;
use MarketDataApp\Endpoints\Requests\Parameters;
use MarketDataApp\Enums\Format;
$client = new Client();
// Get news as CSV
$news = $client->stocks->news(
symbol: 'AAPL',
from: '2024-01-01',
parameters: new Parameters(format: Format::CSV)
);
echo $news->getCsv();
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 usingFormat::CSV).getHtml(): Returns the raw HTML data (when usingFormat::HTML).isJson(): Returnstrueif 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.