use dceapi_rs::{Client, Config, GetArticleByPageRequest, QuotesRequest, RequestOptions};
#[tokio::main]
async fn main() -> dceapi_rs::Result<()> {
let config = Config::from_env();
let client = Client::new(config)?;
println!("DCE API client created successfully!");
println!("\n--- Getting current trade date ---");
match client.common.get_curr_trade_date(None).await {
Ok(trade_date) => println!("Current trade date: {}", trade_date.date),
Err(e) => println!("Error getting trade date: {}", e),
}
println!("\n--- Getting variety list ---");
match client.common.get_variety_list(None).await {
Ok(varieties) => {
println!("Found {} varieties:", varieties.len());
for v in varieties.iter().take(5) {
println!(" - {} ({})", v.name, v.code);
}
if varieties.len() > 5 {
println!(" ... and {} more", varieties.len() - 5);
}
}
Err(e) => println!("Error getting varieties: {}", e),
}
println!("\n--- Getting exchange announcements ---");
let article_req = GetArticleByPageRequest {
column_id: "244".to_string(), page_no: 1,
page_size: 5,
site_id: 5,
};
match client.news.get_article_by_page(article_req, None).await {
Ok(response) => {
println!("Found {} articles:", response.total_count);
for article in response.result_list.iter().take(3) {
println!(" - {}", article.title);
}
}
Err(e) => println!("Error getting articles: {}", e),
}
println!("\n--- Getting day quotes ---");
let quotes_req = QuotesRequest {
variety_id: Some("a".to_string()), variety: None,
trade_date: "20240115".to_string(),
trade_type: "1".to_string(), lang: Some("zh".to_string()),
statistics_type: None,
};
let opts = RequestOptions::new().with_trade_type(1);
match client.market.get_day_quotes("es_req, Some(opts)).await {
Ok(quotes) => {
println!("Found {} quotes:", quotes.len());
for quote in quotes.iter().take(3) {
println!(
" - {} | Open: {} | High: {} | Low: {} | Close: {}",
quote.contract_id, quote.open, quote.high, quote.low, quote.close
);
}
}
Err(e) => println!("Error getting quotes: {}", e),
}
println!("\nDone!");
Ok(())
}