An unofficial rust library for TD Ameritrade's API
Add this to your Cargo.toml
toml
[dependencies]
tdameritrade_rust = "0.1.3"
fn main() { // Create Token File init::createtokenfile( "chromedriverpath".into(), // Path To Chromedriver "clientid@AMER.OAUTHAP".into(), // Client Id (Consumer Key) "redirecturi".into(), // Redirect URI (Callback URL) "tokenfilepath".into(), // Where To Put Token File After Completion ) } ```
fn main() -> Result<(), TDAClientError> { // Create Synchronous TDAClient let mut client = SyncTDAClient::new( "clientid@AMER.OAUTHAP".into(), // Client Id (Consumer Key) "redirecturi".into(), // Redirect URI (Callback URL) "tokenfilepath".into(), // Token File Location );
// Get Quote
let symbol = "AAPL";
let res = client.get_quote(symbol)?;
let res_json = serde_json::from_str::<Quotes>(&res)?;
if let QuoteType::Equity(equity) = &res_json.symbol[symbol] {
println!("{}", equity.close_price);
}
// Get Quotes
let symbols = vec!["AAPL", "AMZN", "AMD", "NVDA"];
let res = client.get_quotes(&symbols)?;
let res_json = serde_json::from_str::<Quotes>(&res)?;
for symbol in symbols.into_iter() {
if let QuoteType::Equity(equity) = &res_json.symbol[symbol] {
println!("{}", equity.close_price)
}
}
Ok(())
} ```
async fn main() -> Result<(), TDAClientError> { // Create Asynchronous TDAClient let mut client = AsyncTDAClient::new( "clientid@AMER.OAUTHAP".into(), // Client Id (Consumer Key) "redirecturi".into(), // Redirect URI (Callback URL) "tokenfilepath".into(), // Token File Location );
// Get Quote
let symbol = "AAPL";
let res = client.get_quote(symbol).await?;
let res_json = serde_json::from_str::<Quotes>(&res)?;
if let QuoteType::Equity(equity) = &res_json.symbol[symbol] {
println!("{}", equity.close_price);
}
// Get Quotes
let symbols = vec!["AAPL", "AMZN", "AMD", "NVDA"];
let res = client.get_quotes(&symbols).await?;
let res_json = serde_json::from_str::<Quotes>(&res)?;
for symbol in symbols.into_iter() {
if let QuoteType::Equity(equity) = &res_json.symbol[symbol] {
println!("{}", equity.close_price)
}
}
Ok(())
} ```
tdameritrade_rust is released under the MIT license
tdameritrade_rust is an unofficial API wrapper. It is in no way endorsed by or affiliated with TD Ameritrade or any associated organization. The authors will accept no responsibility for any damage that might stem from use of this package. See the LICENSE file for more details.