Crates.io | etrade |
lib.rs | etrade |
version | 0.6.0 |
source | src |
created_at | 2021-01-02 18:22:59.58561 |
updated_at | 2023-03-06 06:14:39.939948 |
description | Wraps the etrade API and implements the oauth flows |
homepage | |
repository | https://github.com/casualjim/rs-etrade |
max_upload_size | |
id | 330686 |
size | 201,422 |
Wraps the etrade API and implements the required oauth1 flow.
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;
#[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(())
}