A high-performance, asynchronous Rust client library for the Dalian Commodity Exchange (DCE) API.
Ported from the dceapi-go library, this SDK provides a type-safe and efficient way to interact with DCE market data, news, delivery, and trading services.
- Asynchronous: Built on
tokioandreqwestfor modern async/await workflows. - Auto-Token Management: Handles API token acquisition and automatic refresh before expiry.
- Retry Mechanism: Automatically retries requests on token expiration (HTTP 402).
- Compression Support: Supports Gzip, Brotli, and Deflate for faster data transfer.
- Type Safety: Comprehensive Rust models for all request and response structures.
- Error Handling: Detailed error types using
thiserror. - Complete Coverage: 100% API endpoint coverage (37 methods across 34 unique endpoints)
- Get articles, announcements, and notices
- Retrieve detailed news content
- Retrieve current trade dates and variety (commodity) lists
- Get variety month/year statistics
- Fetch day, night, week, and month quotes
- Contract statistics (max volume, turnover, open interest, price)
- Rise/fall event (limit up/down) queries
- Division price information
- Warehouse receipt data
- Get trading parameters (day/month)
- Contract information (standard, new, arbitrage)
- Margin and performance parameters
- Market maker continuous quote series
- Retrieve settlement parameters
- Access member trading and volume rankings (daily and phase)
- Get delivery data and match information
- Warehouse receipts and premiums
- TC congregate delivery and roll delivery
- Bonded delivery (standard and T+D)
- Factory spot basis spreads
- Plywood delivery commodities
Add this to your Cargo.toml:
[dependencies]
dceapi = { path = "./path/to/dceapi-rs" } # Adjust the path accordingly
tokio = { version = "1", features = ["full"] }export DCE_API_KEY="your-api-key"
export DCE_SECRET="your-secret"use dceapi::{Client, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client from environment variables
let client = Client::from_env()?;
// Get current trade date
let trade_date = client.common.get_curr_trade_date(None).await?;
println!("Current trade date: {}", trade_date.date);
// Get variety list
let varieties = client.common.get_variety_list(None).await?;
for v in varieties.iter().take(5) {
println!("Variety: {} ({})", v.name, v.code);
}
Ok(())
}The project includes two examples:
-
Basic: Simple demonstration of trade date and variety list retrieval.
cargo run --example basic
-
Complete: Comprehensive demonstration of all 36+ API endpoints across 7 services:
- Common Service (3 endpoints)
- News Service (2 endpoints)
- Market Service (10 endpoints)
- Trade Service (8 endpoints)
- Settle Service (3 endpoints)
- Member Service (2 endpoints)
- Delivery Service (11 endpoints)
All API calls are spaced 1 second apart to respect rate limits.
cargo run --example complete
You can also configure the client manually:
use dceapi::{Client, Config};
use std::time::Duration;
let config = Config::new()
.with_api_key("your-api-key")
.with_secret("your-secret")
.with_timeout(Duration::from_secs(30))
.with_lang("zh");
let client = Client::new(config)?;MIT / Apache-2.0