1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::period::FMPPeriod;
use crate::{request, Client, StatusCode};
use serde::{Deserialize, Serialize};

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FMPAnalystEstimates {
    pub symbol: String,
    pub date: String,
    pub estimated_revenue_low: f64,
    pub estimated_revenue_high: f64,
    pub estimated_revenue_avg: f64,
    pub estimated_ebitda_low: f64,
    pub estimated_ebitda_high: f64,
    pub estimated_ebitda_avg: f64,
    pub estimated_ebit_low: f64,
    pub estimated_ebit_high: f64,
    pub estimated_ebit_avg: f64,
    pub estimated_net_income_low: f64,
    pub estimated_net_income_high: f64,
    pub estimated_net_income_avg: f64,
    pub estimated_sga_expense_low: f64,
    pub estimated_sga_expense_high: f64,
    pub estimated_sga_expense_avg: f64,
    pub estimated_eps_avg: f64,
    pub estimated_eps_high: f64,
    pub estimated_eps_low: f64,
    pub number_analyst_estimated_revenue: f64,
    pub number_analysts_estimated_eps: f64,
}

impl Client {
    pub async fn analyst_estimates(
        &self,
        ticker: &str,
        period: FMPPeriod,
    ) -> Result<Vec<FMPAnalystEstimates>, StatusCode> {
        request(format!(
            "{}/v3/analyst-estimates/{}?period={}&apikey={}",
            self.base,
            ticker,
            period.value(),
            self.api_key,
        ))
        .await
    }
}