dceapi_rs/
lib.rs

1//! DCE API Client Library
2//!
3//! A Rust client library for the Dalian Commodity Exchange (DCE) API.
4//!
5//! # Overview
6//!
7//! This library provides access to:
8//! - **News**: Articles and announcements
9//! - **Common**: Trade dates and variety (commodity) information
10//! - **Market**: Quotes and market data (day, night, week, month)
11//! - **Delivery**: Delivery data, warehouse receipts, costs
12//! - **Member**: Member trading rankings
13//! - **Trade**: Trading parameters and contract information
14//! - **Settlement**: Settlement parameters
15//!
16//! # Quick Start
17//!
18//! ```no_run
19//! use dceapi::{Client, Config};
20//!
21//! #[tokio::main]
22//! async fn main() -> dceapi::Result<()> {
23//!     // Create client with credentials
24//!     let config = Config::new()
25//!         .with_api_key("your-api-key")
26//!         .with_secret("your-secret");
27//!     
28//!     let client = Client::new(config)?;
29//!     
30//!     // Get current trade date
31//!     let trade_date = client.common.get_curr_trade_date(None).await?;
32//!     println!("Current trade date: {}", trade_date.date);
33//!     
34//!     // Get variety list
35//!     let varieties = client.common.get_variety_list(None).await?;
36//!     for v in varieties {
37//!         println!("Variety: {} ({})", v.name, v.code);
38//!     }
39//!     
40//!     Ok(())
41//! }
42//! ```
43//!
44//! # Using Environment Variables
45//!
46//! You can also create a client from environment variables:
47//!
48//! ```no_run
49//! use dceapi::Client;
50//!
51//! # async fn example() -> dceapi::Result<()> {
52//! // Set DCE_API_KEY and DCE_SECRET environment variables
53//! let client = Client::from_env()?;
54//! # Ok(())
55//! # }
56//! ```
57//!
58//! # Error Handling
59//!
60//! All API methods return `Result<T, Error>`. The error types include:
61//! - `Error::Api` - API returned an error response
62//! - `Error::Auth` - Authentication failed
63//! - `Error::Network` - Network or HTTP error
64//! - `Error::Validation` - Invalid request parameters
65//! - `Error::Parse` - Failed to parse response
66//!
67//! # Request Options
68//!
69//! Most methods accept optional `RequestOptions` to override defaults:
70//!
71//! ```no_run
72//! use dceapi::{Client, Config, RequestOptions};
73//!
74//! # async fn example() -> dceapi::Result<()> {
75//! # let client = Client::new(Config::new().with_api_key("k").with_secret("s"))?;
76//! let opts = RequestOptions::new()
77//!     .with_trade_type(2)  // Options instead of futures
78//!     .with_lang("en");    // English language
79//!
80//! let varieties = client.common.get_variety_list(Some(opts)).await?;
81//! # Ok(())
82//! # }
83//! ```
84
85#![warn(missing_docs)]
86#![warn(rust_2018_idioms)]
87
88mod client;
89mod config;
90mod error;
91mod http;
92mod models;
93mod services;
94mod token;
95
96// Re-export main types
97pub use client::Client;
98pub use config::{Config, DEFAULT_BASE_URL, DEFAULT_LANG, DEFAULT_TIMEOUT_SECS, DEFAULT_TRADE_TYPE};
99pub use error::{Error, ErrorCode, Result};
100pub use http::RequestOptions;
101pub use token::TokenManager;
102
103// Re-export all models
104pub use models::*;
105
106// Re-export services for direct access
107pub use services::{
108    CommonService, DeliveryService, MarketService, MemberService, NewsService, SettleService,
109    TradeService,
110};
111
112// Re-export news helper
113pub use services::news::is_valid_column_id;