Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/casualjim/rs-etrade
Rust client for the etrade api
https://github.com/casualjim/rs-etrade
Last synced: 6 days ago
JSON representation
Rust client for the etrade api
- Host: GitHub
- URL: https://github.com/casualjim/rs-etrade
- Owner: casualjim
- License: mit
- Created: 2020-12-28T06:32:20.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T06:13:43.000Z (over 1 year ago)
- Last Synced: 2024-11-02T09:31:55.514Z (13 days ago)
- Language: Rust
- Size: 175 KB
- Stars: 9
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```rust
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(())
}
```