#quote #finance #stocks #etrade #stock-options

bin+lib etrade

Wraps the etrade API and implements the oauth flows

9 unstable releases

0.5.0 Dec 30, 2022
0.4.0 Mar 13, 2021
0.3.0 Mar 8, 2021
0.2.1 Jan 6, 2021
0.1.4 Jan 2, 2021

#8 in Finance

35 downloads per month

MIT and LGPL-3.0-or-later

3.5K SLoC

Rust etrade

Wraps the etrade API and implements the required oauth1 flow.

State storage

The default feature for the crate includes a thread safe in-memory store for the oauth tokens. There is an optional feature keychain which will the OS native secret store to track the token information.

You only need to initialize the consumer key/secret once, the temporary credentials will be managed by the session.


use anyhow::{anyhow, Result};
use etrade::orders::{ListOrdersRequest, OrderStatus, TransactionType};
use etrade::KeychainStore;
use etrade::{self, SortOrder};
use etrade::{accounts, MarketSession, SecurityType};
use accounts::BalanceRequest;

async fn main() -> Result<()> {
  let mode: etrade::Mode = etrade::Mode::Live;
  let session = Arc::new(etrade::Session::new(mode, KeychainStore));
  let accounts = etrade::accounts::Api::new(session.clone());

  let msg1 = "Consumer key:\n";

  let mut consumer_token = String::new();
  io::BufReader::new(io::stdin()).read_line(&mut consumer_token).await?;

  let msg2 = "Consumer secret:\n";

  let mut consumer_secret = String::new();
  io::BufReader::new(io::stdin()).read_line(&mut consumer_secret).await?;

    .initialize(consumer_token.trim().to_string(), consumer_secret.trim().to_string())
  println!("updated the {} consumer token and key", mode);

  let account_list = accounts.list(etrade::OOB).await?;

  for account in &account_list {
    let balance = accounts
    println!("{:?}", balance);



~558K SLoC