Skip to main content

financial_api/a_share/
valuations.rs

1use crate::endpoints;
2use crate::endpoints::join_values;
3use crate::{AShareCode, Client, Error, Response, ValuationsData};
4
5impl Client {
6    /// Fetch latest valuation metrics for up to 100 A-share targets.
7    pub async fn a_share_valuations_snapshot(
8        &self,
9        thscodes: &[AShareCode],
10    ) -> Result<Response<ValuationsData>, Error> {
11        let query = [("thscodes", join_values("thscodes", thscodes, Some(100))?)];
12        self.get(endpoints::VALUATIONS_SNAPSHOT, &query).await
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use crate::ApiKey;
20
21    #[tokio::test]
22    async fn snapshot_rejects_more_than_one_hundred_targets_before_transport() {
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 stock = AShareCode::new("600519.SH").unwrap();
28
29        let error = client
30            .a_share_valuations_snapshot(&vec![stock; 101])
31            .await
32            .unwrap_err();
33
34        assert!(matches!(error, Error::InvalidInput(_)));
35    }
36}