use tushare_api::{TushareClient, Api, request, TushareEntityList, TushareRequest, params, fields};
use tushare_api::DeriveFromTushareData;
#[derive(Debug, Clone, DeriveFromTushareData)]
struct Stock {
ts_code: String,
symbol: String,
name: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = TushareClient::from_env()?;
let request = request!(Api::StockBasic, {
"list_status" => "L"
}, [
"ts_code", "symbol", "name"
]);
let stock_list: TushareEntityList<Stock> = client.call_api_as(request).await?;
println!("Found {} stocks:", stock_list.len());
for (i, stock) in stock_list.iter().take(10).enumerate() {
println!("{}. {} ({}) - {}", i + 1, stock.ts_code, stock.symbol, stock.name);
}
if stock_list.len() > 10 {
println!("... and {} more stocks", stock_list.len() - 10);
}
println!("Total records: {}", stock_list.count());
println!("Has more pages: {}", stock_list.has_more());
Ok(())
}