pub struct Config {
pub base_url: String,
pub api_key: String,
pub secret: String,
pub timeout: Duration,
pub lang: String,
pub trade_type: i32,
}Expand description
Client configuration.
Fields§
§base_url: StringAPI base URL. Defaults to “http://www.dce.com.cn”.
api_key: StringAPI key (required).
secret: StringAPI secret (required).
timeout: DurationHTTP request timeout. Defaults to 30 seconds.
lang: StringLanguage for API responses. “zh” or “en”. Defaults to “zh”.
trade_type: i32Trade type. 1 = futures, 2 = options. Defaults to 1.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new configuration with default values.
Note: api_key and secret must be set before using the client.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a configuration from environment variables.
Reads DCE_API_KEY and DCE_SECRET from environment.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Set the base URL.
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Set the API key.
Sourcepub fn with_secret(self, secret: impl Into<String>) -> Self
pub fn with_secret(self, secret: impl Into<String>) -> Self
Set the API secret.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the HTTP timeout.
Sourcepub fn with_trade_type(self, trade_type: i32) -> Self
pub fn with_trade_type(self, trade_type: i32) -> Self
Set the trade type.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the configuration.
Returns an error if required fields are missing.
Sourcepub fn apply_defaults(&mut self)
pub fn apply_defaults(&mut self)
Apply default values to empty fields.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more