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    /// 获取基金历史分红记录。
6    ///
7    /// # 示例
8    #[doc = concat!(
9        "```no_run\n",
10        include_str!("../../examples/fund_corporate_actions_dividends.rs"),
11        "\n```"
12    )]
13    pub async fn fund_corporate_actions_dividends(
14        &self,
15        fund_type: FundType,
16        thscode: &Thscode,
17    ) -> Result<Response<FundDividendsData>, Error> {
18        self.fund_detail(endpoints::FUND_DIVIDENDS, fund_type, thscode)
19            .await
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use crate::ApiKey;
27
28    #[tokio::test]
29    async fn dividends_keeps_fund_target_validation_on_its_call_edge() {
30        let client = Client::builder(ApiKey::new("test-api-key").unwrap())
31            .base_url("http://127.0.0.1:9")
32            .build()
33            .unwrap();
34        let exchange_fund = Thscode::new("510300.SH").unwrap();
35        let otc_fund = Thscode::new("025480.OF").unwrap();
36
37        for error in [
38            client
39                .fund_corporate_actions_dividends(FundType::Otc, &exchange_fund)
40                .await
41                .unwrap_err(),
42            client
43                .fund_corporate_actions_dividends(FundType::Exchange, &otc_fund)
44                .await
45                .unwrap_err(),
46        ] {
47            assert!(matches!(error, Error::InvalidInput(_)));
48        }
49    }
50}