1use crate::endpoints;
2use crate::{
3 Client, Error, FundAssetAllocationData, FundHoldingsData, FundIndustryAllocationData,
4 FundPortfolioHistoryData, FundReportDatesData, FundType, NaturalDate, ReportType, Response,
5 Thscode,
6};
7
8use super::FundTarget;
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: &Thscode,
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: &Thscode,
40 report_type: &ReportType,
41 end_date: NaturalDate,
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: &Thscode,
65 report_type: &ReportType,
66 end_date: NaturalDate,
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: &Thscode,
83 report_type: &ReportType,
84 end_date: NaturalDate,
85 ) -> Result<Response<FundPortfolioHistoryData>, Error> {
86 let mut query = FundTarget::new(fund_type, thscode)?.query();
87 query.push(("report_type", report_type.to_string()));
88 query.push(("end_date", end_date.to_string()));
89 self.get(path, &query).await
90 }
91
92 #[doc = concat!(
96 "```no_run\n",
97 include_str!("../../examples/fund_portfolio_stock_report_dates.rs"),
98 "\n```"
99 )]
100 pub async fn fund_portfolio_stock_report_dates(
101 &self,
102 fund_type: FundType,
103 thscode: &Thscode,
104 report_type: Option<&ReportType>,
105 ) -> Result<Response<FundReportDatesData>, Error> {
106 self.fund_report_dates(
107 endpoints::FUND_STOCK_REPORT_DATES,
108 fund_type,
109 thscode,
110 report_type,
111 )
112 .await
113 }
114
115 #[doc = concat!(
119 "```no_run\n",
120 include_str!("../../examples/fund_portfolio_bond_report_dates.rs"),
121 "\n```"
122 )]
123 pub async fn fund_portfolio_bond_report_dates(
124 &self,
125 fund_type: FundType,
126 thscode: &Thscode,
127 report_type: Option<&ReportType>,
128 ) -> Result<Response<FundReportDatesData>, Error> {
129 self.fund_report_dates(
130 endpoints::FUND_BOND_REPORT_DATES,
131 fund_type,
132 thscode,
133 report_type,
134 )
135 .await
136 }
137
138 async fn fund_report_dates(
139 &self,
140 path: &str,
141 fund_type: FundType,
142 thscode: &Thscode,
143 report_type: Option<&ReportType>,
144 ) -> Result<Response<FundReportDatesData>, Error> {
145 let mut query = FundTarget::new(fund_type, thscode)?.query();
146 if let Some(report_type) = report_type {
147 query.push(("report_type", report_type.to_string()));
148 }
149 self.get(path, &query).await
150 }
151
152 #[doc = concat!(
156 "```no_run\n",
157 include_str!("../../examples/fund_portfolio_asset_allocation.rs"),
158 "\n```"
159 )]
160 pub async fn fund_portfolio_asset_allocation(
161 &self,
162 fund_type: FundType,
163 thscode: &Thscode,
164 ) -> Result<Response<FundAssetAllocationData>, Error> {
165 self.fund_detail(endpoints::FUND_ASSET_ALLOCATION, fund_type, thscode)
166 .await
167 }
168
169 #[doc = concat!(
173 "```no_run\n",
174 include_str!("../../examples/fund_portfolio_industry_allocation.rs"),
175 "\n```"
176 )]
177 pub async fn fund_portfolio_industry_allocation(
178 &self,
179 fund_type: FundType,
180 thscode: &Thscode,
181 ) -> Result<Response<FundIndustryAllocationData>, Error> {
182 self.fund_detail(endpoints::FUND_INDUSTRY_ALLOCATION, fund_type, thscode)
183 .await
184 }
185}