Skip to main content

financial_api/fund/
corporate_actions.rs

1use crate::endpoints;
2use crate::{Client, Error, FundDividendsData, FundType, Response, Thscode, ValidationError};
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: impl TryInto<Thscode, Error: Into<ValidationError>>,
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        for error in [
35            client
36                .fund_corporate_actions_dividends(FundType::Otc, "510300.SH")
37                .await
38                .unwrap_err(),
39            client
40                .fund_corporate_actions_dividends(FundType::Exchange, "025480.OF")
41                .await
42                .unwrap_err(),
43        ] {
44            assert!(matches!(error, Error::InvalidInput(_)));
45        }
46    }
47}