Skip to main content

finance_query/models/corporate/recommendation/
data.rs

1use super::SimilarSymbol;
2/// Recommendation aggregate module
3///
4/// Contains the fully typed Recommendation structure for similar/recommended symbols.
5use serde::{Deserialize, Serialize};
6
7/// Fully typed recommendation data
8///
9/// Aggregates the queried symbol and its recommendations into a single
10/// convenient structure. This is the recommended type for serialization
11/// and API responses.
12///
13/// Note: This struct cannot be manually constructed - use `Ticker::recommendations()` to obtain recommendations.
14#[non_exhaustive]
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Recommendation {
17    /// Symbol that was queried
18    pub symbol: String,
19
20    /// Recommended/similar symbols with scores
21    pub recommendations: Vec<SimilarSymbol>,
22
23    /// Which provider supplied this data (None = Yahoo Finance default)
24    pub provider_id: Option<crate::providers::Provider>,
25}
26
27impl Recommendation {
28    /// Get just the symbol strings
29    pub fn symbols(&self) -> Vec<&str> {
30        self.recommendations
31            .iter()
32            .map(|s| s.symbol.as_str())
33            .collect()
34    }
35
36    /// Get the number of recommendations
37    pub fn count(&self) -> usize {
38        self.recommendations.len()
39    }
40}
41
42#[cfg(feature = "dataframe")]
43impl Recommendation {
44    /// Converts the recommendations to a polars DataFrame.
45    pub fn to_dataframe(&self) -> ::polars::prelude::PolarsResult<::polars::prelude::DataFrame> {
46        SimilarSymbol::vec_to_dataframe(&self.recommendations)
47    }
48}