pub struct TushareRequest {
pub api_name: Api,
pub params: HashMap<String, String>,
pub fields: Vec<String>,
}Expand description
Tushare API request structure
Supports flexible string type usage, allowing direct use of string literals and String variables
Fields§
§api_name: Api§params: HashMap<String, String>§fields: Vec<String>Implementations§
Sourcepub fn new<K, V, F, P, Fs>(api_name: Api, params: P, fields: Fs) -> Selfwhere
K: Into<String>,
V: Into<String>,
F: Into<String>,
P: IntoIterator<Item = (K, V)>,
Fs: IntoIterator<Item = F>,
pub fn new<K, V, F, P, Fs>(api_name: Api, params: P, fields: Fs) -> Selfwhere
K: Into<String>,
V: Into<String>,
F: Into<String>,
P: IntoIterator<Item = (K, V)>,
Fs: IntoIterator<Item = F>,
Create a new TushareRequest
Examples found in repository?
examples/custom_type_example.rs (lines 119-129)
111async fn main() -> Result<(), Box<dyn std::error::Error>> {
112 // Set up logging
113 env_logger::init();
114
115 // Create client from environment variable
116 let client = TushareClient::from_env()?;
117
118 // Create request for daily stock data
119 let request = TushareRequest::new(
120 Api::Daily,
121 params![
122 "ts_code" => "000001.SZ",
123 "start_date" => "20240101",
124 "end_date" => "20240131"
125 ],
126 fields![
127 "ts_code", "trade_date", "open", "high", "low", "close", "vol", "amount"
128 ]
129 );
130
131 println!("Fetching daily stock data with custom Decimal types...");
132
133 // Call API and get typed response with automatic conversion
134 let stock_prices: TushareEntityList<StockPrice> = client.call_api_as(request).await?;
135
136 println!("Retrieved {} stock price records", stock_prices.len());
137 println!("Has more data: {}", stock_prices.has_more());
138 println!("Total count: {}", stock_prices.count());
139
140 // Display first few records
141 for (i, price) in stock_prices.iter().take(5).enumerate() {
142 println!("\nRecord {}:", i + 1);
143 println!(" Stock Code: {}", price.ts_code);
144 println!(" Trade Date: {}", price.trade_date);
145 println!(" Open Price: {}", price.open_price);
146 println!(" High Price: {}", price.high_price);
147 println!(" Low Price: {}", price.low_price);
148 println!(" Close Price: {}", price.close_price);
149
150 if let Some(vol) = &price.volume {
151 println!(" Volume: {}", vol);
152 }
153
154 if let Some(amount) = &price.amount {
155 println!(" Amount: {}", amount);
156 }
157 }
158
159 Ok(())
160}Sourcepub fn with_str_params<const N: usize>(
api_name: Api,
params: [(&str, &str); N],
fields: &[&str],
) -> Self
pub fn with_str_params<const N: usize>( api_name: Api, params: [(&str, &str); N], fields: &[&str], ) -> Self
Create parameters from string literals
Trait Implementations§
Source§fn clone(&self) -> TushareRequest
fn clone(&self) -> TushareRequest
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a conversion error.
Auto Trait Implementations§
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