Skip to main content

finance_query/adapters/polygon/stocks/
news.rs

1//! Stock news endpoints with sentiment analysis.
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::Result;
6
7use super::super::build_client;
8use super::super::models::PaginatedResponse;
9
10/// Publisher information.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13pub struct Publisher {
14    /// Publisher name.
15    pub name: Option<String>,
16    /// Homepage URL.
17    pub homepage_url: Option<String>,
18    /// Logo URL.
19    pub logo_url: Option<String>,
20    /// Favicon URL.
21    pub favicon_url: Option<String>,
22}
23
24/// Sentiment insight.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[non_exhaustive]
27pub struct Insight {
28    /// Ticker symbol.
29    pub ticker: Option<String>,
30    /// Sentiment label (e.g., `"positive"`, `"negative"`, `"neutral"`).
31    pub sentiment: Option<String>,
32    /// Sentiment reasoning.
33    pub sentiment_reasoning: Option<String>,
34}
35
36/// News article.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[non_exhaustive]
39pub struct NewsArticle {
40    /// Article ID.
41    pub id: Option<String>,
42    /// Publisher.
43    pub publisher: Option<Publisher>,
44    /// Article title.
45    pub title: Option<String>,
46    /// Author.
47    pub author: Option<String>,
48    /// Published UTC timestamp.
49    pub published_utc: Option<String>,
50    /// Article URL.
51    pub article_url: Option<String>,
52    /// Image URL.
53    pub image_url: Option<String>,
54    /// Description.
55    pub description: Option<String>,
56    /// Keywords.
57    pub keywords: Option<Vec<String>>,
58    /// Related tickers.
59    pub tickers: Option<Vec<String>>,
60    /// AMP URL.
61    pub amp_url: Option<String>,
62    /// Sentiment insights.
63    pub insights: Option<Vec<Insight>>,
64}
65
66/// Fetch news articles, optionally filtered by ticker.
67///
68/// * `params` - Query params: `ticker`, `published_utc`, `order`, `limit`, `sort`
69pub async fn stock_news(params: &[(&str, &str)]) -> Result<PaginatedResponse<NewsArticle>> {
70    let client = build_client()?;
71    client.get("/v2/reference/news", params).await
72}