Expand description
§Tushare API Client Library
A comprehensive Rust client library for accessing Tushare financial data APIs. This library provides a simple and efficient way to fetch financial data from Tushare, with built-in support for request/response handling, error management, and logging.
§Features
- Easy-to-use API: Simple client interface for making Tushare API calls
- Type Safety: Strong typing for requests and responses
- Error Handling: Comprehensive error types and handling
- Logging Support: Built-in logging with configurable levels
- Async Support: Full async/await support with tokio
- Flexible Configuration: Customizable HTTP client settings
- Environment Integration: Automatic token loading from environment variables
- Automatic Conversion: Derive macros for automatic struct conversion from API responses
§Quick Start
use tushare_api::{TushareClient, Api, TushareRequest, TushareEntityList, params, fields};
use tushare_api::DeriveFromTushareData;
// Define your data structure with derive macro
#[derive(Debug, Clone, DeriveFromTushareData)]
pub struct Stock {
ts_code: String,
symbol: String,
name: String,
area: Option<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client from environment variable TUSHARE_TOKEN
let client = TushareClient::from_env()?;
// Create request using manual construction
let request = TushareRequest::new(
Api::StockBasic,
params!("list_status" => "L"),
fields!["ts_code", "symbol", "name", "area"]
);
// Make the API call with automatic conversion
let stocks: TushareEntityList<Stock> = client.call_api_as(request).await?;
println!("Received {} stocks", stocks.len());
for stock in stocks.iter().take(5) {
println!("{}: {}", stock.ts_code, stock.name);
}
Ok(())
}Re-exports§
pub use api::Api;pub use client::HttpClientConfig;pub use logging::LogConfig;pub use logging::LogLevel;pub use logging::Logger;pub use utils::response_to_vec;pub use serde_json;
Modules§
- api
- basic_
types - Basic Rust type implementations for FromTushareValue and FromOptionalTushareValue traits
- client
- client_
ex - custom_
date_ format - Custom date format implementations for FromTushareValueWithFormat trait
- error
- logging
- third_
party_ types - Third-party type implementations for FromTushareValue and FromOptionalTushareValue traits
- traits
- Traits for Tushare API data conversion
- types
- utils
- Utility functions for working with Tushare API responses
Macros§
- fields
- Macro for creating fields Vec
- params
- Macro for creating parameter HashMap
- request
- More concise builder macro - directly create TushareRequest
Derive Macros§
- Derive
From Tushare Data - Derive macro for automatically implementing FromTushareData trait