financial_api/a_share/
valuations.rs1use crate::endpoints;
2use crate::endpoints::join_a_share_codes;
3use crate::{AShareCode, Client, Error, Response, ValidationError, ValuationsData};
4
5impl Client {
6 #[doc = concat!(
10 "```no_run\n",
11 include_str!("../../examples/a_share_valuations_snapshot.rs"),
12 "\n```"
13 )]
14 pub async fn a_share_valuations_snapshot(
15 &self,
16 thscodes: impl IntoIterator<Item = impl TryInto<AShareCode, Error: Into<ValidationError>>>,
17 ) -> Result<Response<ValuationsData>, Error> {
18 let query = [("thscodes", join_a_share_codes(thscodes, Some(100))?)];
19 self.get(endpoints::VALUATIONS_SNAPSHOT, &query).await
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26 use crate::{AShareCode, ApiKey};
27
28 #[tokio::test]
29 async fn snapshot_rejects_more_than_one_hundred_targets_before_transport() {
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 stock = AShareCode::new("600519.SH").unwrap();
35
36 let error = client
37 .a_share_valuations_snapshot(&vec![stock; 101])
38 .await
39 .unwrap_err();
40
41 assert!(matches!(error, Error::InvalidInput(_)));
42 }
43}