Crates.io | tdameritrade_rust |
lib.rs | tdameritrade_rust |
version | 0.1.6 |
source | src |
created_at | 2022-09-22 14:10:09.859582 |
updated_at | 2023-06-03 01:24:01.785443 |
description | An unofficial rust library for TD Ameritrade's API |
homepage | |
repository | https://github.com/Lolser9/tdameritrade_rust |
max_upload_size | |
id | 671735 |
size | 269,141 |
An unofficial rust library for TD Ameritrade's API
tdameritrade_rust's OrderBuilder was heavily inspired by Alex Golec's OrderBuilder from tda api. His documentation of OrderBuilder is an amazing resource, and should work with the OrderBuilder from this library.
Add this to your Cargo.toml
[dependencies]
tdameritrade_rust = "0.1.6"
use tdameritrade_rust::init;
fn main() {
// Create Token File
init::create_token_file(
"chrome_driver_path".into(), // Path To Chromedriver
"client_id@AMER.OAUTHAP".into(), // Client Id (Consumer Key)
"redirect_uri".into(), // Redirect URI (Callback URL)
"token_file_path".into(), // Where To Put Token File After Completion
)
}
use tdameritrade_rust::{
output::quotes::{QuoteType, Quotes},
SyncTDAClient, TDAClientError,
};
mod config;
fn main() -> Result<(), TDAClientError> {
// Create Synchronous TDAClient
let client = SyncTDAClient::new(
config::client_id(),
config::redirect_uri(),
config::token_path(),
)?;
// 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(())
}
use tdameritrade_rust::{
output::quotes::{QuoteType, Quotes},
AsyncTDAClient, TDAClientError,
};
mod config;
#[tokio::main]
async fn main() -> Result<(), TDAClientError> {
// Create Asynchronous TDAClient
let client = AsyncTDAClient::new(
config::client_id(),
config::redirect_uri(),
config::token_path(),
)?;
// 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.