#api #trading #tdameritrade

yanked tdameritrade_rust-async

A Fully Automated Unofficial Asynchronous Rust Library For The TD Ameritrade API

0.1.0 Sep 20, 2022

#165 in #trading

MIT license

59KB
811 lines

tdameritrade_rust-async

An Unofficial Asynchronous Rust Library For TD Ameritrade's API. The library automatically handles authentification so you don't have to worry about it.

Installation

Add this to your Cargo.toml

[dependencies]
tdameritrade_rust-async = "0.1.0"

Getting Started

  • Register at the TD Ameritrade API Website
  • Go to the My Apps section and add a new app
  • Click on your app and copy the consumer key
  • Click on the details section of your app and copy the callback url
  • Download chromedriver
  • Copy code below, replace_fields, run, and login when prompted to receive a token file from TD Ameritrade
use tdameritrade_rust_async::TDAClient;

#[tokio::main]
async fn main() {
    // Get Token File
    TDAClient::init_start(
        "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 
    )
    .await;
}
  • After receiving the token file, you can create a client to access the API endpoints. Here's an example
use tdameritrade_rust_async::TDAClient;

#[tokio::main]
async fn main() {
    // Create TDAClient
    let mut client = TDAClient::new(
        "client_id@AMER.OAUTHAP".into(), // Client Id (Consumer Key)
        "redirect_uri".into(), // Redirect URI (Callback URL)
        "token_file_path".into(), // Location Of Token File
    );

    // Get Quote
    let res = client.get_quote("AAPL").await;
    println!("{}", res);
}

Future Plans

  • I plan to add more documentation
  • I plan to make the watchlist and order endpoints easier to use
  • I plan to decode output into custom structs instead of relying on serde_json::Value
  • I plan to add a synchronous client

Disclaimer

tdameritrade_rust-async is released under the MIT license

tdameritrade_rust-async 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.

Dependencies

~14–30MB
~446K SLoC