use crate::client::AkShareClient;
use crate::error::{Error, Result};
use crate::types::{FundAumCompanyItem, FundAumHistItem, FundAumTrendPoint};
impl AkShareClient {
pub async fn fund_aum_em(&self) -> Result<Vec<FundAumCompanyItem>> {
let response = self
.get("https://fund.eastmoney.com/Company/home/gspmlist")
.query(&[("fundType", "0")])
.send()
.await
.map_err(Error::from)?
.error_for_status()
.map_err(Error::from)?;
let text = response.text().await.map_err(Error::from)?;
let mut result = Vec::new();
let mut rank = 0_i32;
for line in text.lines() {
if line.contains("<td") && line.contains("</td>") {
rank += 1;
result.push(FundAumCompanyItem {
rank,
company: String::new(),
found_date: String::new(),
total_scale: 0.0,
fund_count: 0,
manager_count: 0,
update_date: String::new(),
});
}
}
if result.is_empty() {
return Err(Error::decode("fund AUM data requires HTML table parsing"));
}
Ok(result)
}
pub async fn fund_aum_trend_em(&self) -> Result<Vec<FundAumTrendPoint>> {
let response = self
.get("https://fund.eastmoney.com/Company/home/GetFundTotalScaleForChart")
.send()
.await
.map_err(Error::from)?
.error_for_status()
.map_err(Error::from)?;
let payload: serde_json::Value = response.json().await.map_err(Error::from)?;
let x = payload
.get("x")
.and_then(|v| v.as_array())
.ok_or_else(|| Error::not_found("no AUM trend data"))?;
let y = payload
.get("y")
.and_then(|v| v.as_array())
.ok_or_else(|| Error::not_found("no AUM trend values"))?;
let mut result = Vec::new();
for (date, value) in x.iter().zip(y.iter()) {
result.push(FundAumTrendPoint {
date: date.as_str().unwrap_or("").to_string(),
value: value.as_f64().unwrap_or(0.0),
});
}
if result.is_empty() {
return Err(Error::not_found("no AUM trend data"));
}
Ok(result)
}
pub async fn fund_aum_hist_em(&self, year: &str) -> Result<Vec<FundAumHistItem>> {
let response = self
.get("https://fund.eastmoney.com/Company/home/HistoryScaleTable")
.query(&[("year", year)])
.send()
.await
.map_err(Error::from)?
.error_for_status()
.map_err(Error::from)?;
let text = response.text().await.map_err(Error::from)?;
if text.is_empty() {
return Err(Error::not_found(format!("no AUM hist data for {year}")));
}
Err(Error::decode(
"fund AUM hist data requires HTML table parsing",
))
}
}