pub struct TushareClientEx { /* private fields */ }Expand description
Extended client wrapper that adds advanced behaviors on top of TushareClient.
Currently supported:
-
Per-API minimum interval rate limiting (default: sleep) If an API is configured with a minimum interval (e.g. 10 seconds), repeated calls to the same API will be automatically delayed so that two calls are at least
min_intervalapart. Callers do not need to implement any sleep logic. -
Retry with exponential backoff (optional) When enabled via
Self::with_retry_config, network/timeout failures will be retried with exponential backoff.
This wrapper is designed to keep the core client stable while allowing you to opt into additional behaviors.
Implementations§
Sourcepub fn new(inner: TushareClient) -> Self
pub fn new(inner: TushareClient) -> Self
Create a new wrapper client.
By default, no per-API interval limit is applied and retry is disabled.
Sourcepub fn with_api_min_interval(self, api: Api, min_interval: Duration) -> Self
pub fn with_api_min_interval(self, api: Api, min_interval: Duration) -> Self
Configure a minimum interval between two calls of the same API.
If the interval is not met, the wrapper will sleep until it becomes
eligible to call.
Example:
use std::time::Duration;
use tushare_api::{Api, TushareClient, TushareClientEx};
TushareClientEx::new(inner)
.with_api_min_interval(Api::Daily, Duration::from_secs(10))Sourcepub fn with_retry_config(self, config: RetryConfig) -> Self
pub fn with_retry_config(self, config: RetryConfig) -> Self
Enable retry with exponential backoff.
Retryable errors:
Non-retryable errors (by design):
TushareError::ApiError(business-level errors returned by Tushare)
Sourcepub fn inner(&self) -> &TushareClient
pub fn inner(&self) -> &TushareClient
Borrow the underlying TushareClient.
Sourcepub fn into_inner(self) -> TushareClient
pub fn into_inner(self) -> TushareClient
Consume the wrapper and return the underlying TushareClient.
Sourcepub async fn call_api<T>(&self, request: &T) -> TushareResult<TushareResponse>where
for<'a> &'a T: TryInto<TushareRequest>,
for<'a> <&'a T as TryInto<TushareRequest>>::Error: Into<TushareError>,
pub async fn call_api<T>(&self, request: &T) -> TushareResult<TushareResponse>where
for<'a> &'a T: TryInto<TushareRequest>,
for<'a> <&'a T as TryInto<TushareRequest>>::Error: Into<TushareError>,
Call API with configured rate limiting (sleep) and optional retry.