tdameritrade_rust

An unofficial rust library for TD Ameritrade’s API

New in version 0.1.6

New in version 0.1.5

New in version 0.1.4

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.

Features

Installation

Add this to your Cargo.toml

[dependencies]
tdameritrade_rust = "0.1.6"

Getting Started

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 ) }


## Synchronous
- After creating the token file, create a TD Ameritrade Client to access the API endpoints. Here's an example with the synchronous client

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(()) } ```

Asynchronous

#[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(()) } ```

Future Plans

Disclaimer

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.