Skip to main content

financial_api/fund/
corporate_actions.rs

1use crate::endpoints;
2use crate::{Client, Error, FundDividendsData, FundType, Response, Thscode};
3
4impl Client {
5    /// Fetch historical fund dividends.
6    pub async fn fund_corporate_actions_dividends(
7        &self,
8        fund_type: FundType,
9        thscode: &Thscode,
10    ) -> Result<Response<FundDividendsData>, Error> {
11        self.fund_detail(endpoints::FUND_DIVIDENDS, fund_type, thscode)
12            .await
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use crate::ApiKey;
20
21    #[tokio::test]
22    async fn dividends_keeps_fund_target_validation_on_its_call_edge() {
23        let client = Client::builder(ApiKey::new("test-api-key").unwrap())
24            .base_url("http://127.0.0.1:9")
25            .build()
26            .unwrap();
27        let exchange_fund = Thscode::new("510300.SH").unwrap();
28        let otc_fund = Thscode::new("025480.OF").unwrap();
29
30        for error in [
31            client
32                .fund_corporate_actions_dividends(FundType::Otc, &exchange_fund)
33                .await
34                .unwrap_err(),
35            client
36                .fund_corporate_actions_dividends(FundType::Exchange, &otc_fund)
37                .await
38                .unwrap_err(),
39        ] {
40            assert!(matches!(error, Error::InvalidInput(_)));
41        }
42    }
43}