1use crate::endpoints;
2use crate::{
3 Client, Error, FundAssetAllocationData, FundHoldingsData, FundIndustryAllocationData,
4 FundPortfolioHistoryData, FundReportDatesData, FundType, NaturalDate, OptionalInput,
5 ReportType, Response, Thscode, ValidationError,
6};
7
8use super::fund_target_query;
9
10impl Client {
11 #[doc = concat!(
15 "```no_run\n",
16 include_str!("../../examples/fund_portfolio_holdings.rs"),
17 "\n```"
18 )]
19 pub async fn fund_portfolio_holdings(
20 &self,
21 fund_type: FundType,
22 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
23 ) -> Result<Response<FundHoldingsData>, Error> {
24 self.fund_detail(endpoints::FUND_HOLDINGS, fund_type, thscode)
25 .await
26 }
27
28 #[doc = concat!(
32 "```no_run\n",
33 include_str!("../../examples/fund_portfolio_stock_history.rs"),
34 "\n```"
35 )]
36 pub async fn fund_portfolio_stock_history(
37 &self,
38 fund_type: FundType,
39 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
40 report_type: impl TryInto<ReportType, Error: Into<ValidationError>>,
41 end_date: impl TryInto<NaturalDate, Error: Into<ValidationError>>,
42 ) -> Result<Response<FundPortfolioHistoryData>, Error> {
43 self.fund_portfolio_history(
44 endpoints::FUND_STOCK_HISTORY,
45 fund_type,
46 thscode,
47 report_type,
48 end_date,
49 )
50 .await
51 }
52
53 #[doc = concat!(
57 "```no_run\n",
58 include_str!("../../examples/fund_portfolio_bond_history.rs"),
59 "\n```"
60 )]
61 pub async fn fund_portfolio_bond_history(
62 &self,
63 fund_type: FundType,
64 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
65 report_type: impl TryInto<ReportType, Error: Into<ValidationError>>,
66 end_date: impl TryInto<NaturalDate, Error: Into<ValidationError>>,
67 ) -> Result<Response<FundPortfolioHistoryData>, Error> {
68 self.fund_portfolio_history(
69 endpoints::FUND_BOND_HISTORY,
70 fund_type,
71 thscode,
72 report_type,
73 end_date,
74 )
75 .await
76 }
77
78 async fn fund_portfolio_history(
79 &self,
80 path: &str,
81 fund_type: FundType,
82 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
83 report_type: impl TryInto<ReportType, Error: Into<ValidationError>>,
84 end_date: impl TryInto<NaturalDate, Error: Into<ValidationError>>,
85 ) -> Result<Response<FundPortfolioHistoryData>, Error> {
86 let mut query = fund_target_query(fund_type, thscode)?;
87 let report_type: ReportType = report_type.try_into().map_err(Into::into)?;
88 let end_date: NaturalDate = end_date.try_into().map_err(Into::into)?;
89 query.push(("report_type", report_type.into_string()));
90 query.push(("end_date", end_date.to_string()));
91 self.get(path, &query).await
92 }
93
94 #[doc = concat!(
98 "```no_run\n",
99 include_str!("../../examples/fund_portfolio_stock_report_dates.rs"),
100 "\n```"
101 )]
102 pub async fn fund_portfolio_stock_report_dates(
103 &self,
104 fund_type: FundType,
105 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
106 report_type: impl TryInto<OptionalInput<ReportType>, Error: Into<ValidationError>>,
107 ) -> Result<Response<FundReportDatesData>, Error> {
108 self.fund_report_dates(
109 endpoints::FUND_STOCK_REPORT_DATES,
110 fund_type,
111 thscode,
112 report_type,
113 )
114 .await
115 }
116
117 #[doc = concat!(
121 "```no_run\n",
122 include_str!("../../examples/fund_portfolio_bond_report_dates.rs"),
123 "\n```"
124 )]
125 pub async fn fund_portfolio_bond_report_dates(
126 &self,
127 fund_type: FundType,
128 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
129 report_type: impl TryInto<OptionalInput<ReportType>, Error: Into<ValidationError>>,
130 ) -> Result<Response<FundReportDatesData>, Error> {
131 self.fund_report_dates(
132 endpoints::FUND_BOND_REPORT_DATES,
133 fund_type,
134 thscode,
135 report_type,
136 )
137 .await
138 }
139
140 async fn fund_report_dates(
141 &self,
142 path: &str,
143 fund_type: FundType,
144 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
145 report_type: impl TryInto<OptionalInput<ReportType>, Error: Into<ValidationError>>,
146 ) -> Result<Response<FundReportDatesData>, Error> {
147 let mut query = fund_target_query(fund_type, thscode)?;
148 let report_type: OptionalInput<ReportType> = report_type.try_into().map_err(Into::into)?;
149 if let Some(report_type) = report_type.into_inner() {
150 query.push(("report_type", report_type.into_string()));
151 }
152 self.get(path, &query).await
153 }
154
155 #[doc = concat!(
159 "```no_run\n",
160 include_str!("../../examples/fund_portfolio_asset_allocation.rs"),
161 "\n```"
162 )]
163 pub async fn fund_portfolio_asset_allocation(
164 &self,
165 fund_type: FundType,
166 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
167 ) -> Result<Response<FundAssetAllocationData>, Error> {
168 self.fund_detail(endpoints::FUND_ASSET_ALLOCATION, fund_type, thscode)
169 .await
170 }
171
172 #[doc = concat!(
176 "```no_run\n",
177 include_str!("../../examples/fund_portfolio_industry_allocation.rs"),
178 "\n```"
179 )]
180 pub async fn fund_portfolio_industry_allocation(
181 &self,
182 fund_type: FundType,
183 thscode: impl TryInto<Thscode, Error: Into<ValidationError>>,
184 ) -> Result<Response<FundIndustryAllocationData>, Error> {
185 self.fund_detail(endpoints::FUND_INDUSTRY_ALLOCATION, fund_type, thscode)
186 .await
187 }
188}