10 releases (5 breaking)

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

#221 in Finance

26 downloads per month

MIT and LGPL-3.0-or-later

125KB
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.

Usage

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;

#[tokio::main]
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";
  io::stderr().write_all(msg1.as_bytes()).await?;

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

  let msg2 = "Consumer secret:\n";
  io::stderr().write_all(msg2.as_bytes()).await?;

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

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

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

  for account in &account_list {
    let balance = accounts
        .balance(
          &account.account_id_key,
          BalanceRequest::default(),
          etrade::OOB,
        )
        .await?;
    println!("{:?}", balance);
  }

  Ok(())
}

Dependencies

~39–54MB
~607K SLoC