Crates.io | alpaca-finance |
lib.rs | alpaca-finance |
version | 0.2.1 |
source | src |
created_at | 2020-04-27 16:22:39.840824 |
updated_at | 2020-05-12 02:06:26.246508 |
description | An API to interact with alpaca.markets |
homepage | https://github.com/fbriden/alpaca-finance-rs |
repository | https://github.com/fbriden/alpaca-finance-rs |
max_upload_size | |
id | 234704 |
size | 43,084 |
An API for interacting with Alpaca.
use alpaca_finance::{ Account, Alpaca };
#[tokio::main]
async fn main() {
// Get a connection to the live API
let alpaca = Alpaca::live("My KEY ID", "My Secret Key").await.unwrap();
let account = Account::get(&alpaca).await.unwrap();
println!("I have ${:.2} in my account.", account.cash)
}
use alpaca_finance::{ Account, Alpaca };
#[tokio::main]
async fn main() {
// Get a connection to the live API
let alpaca = Alpaca::paper("My KEY ID", "My Secret Key").await.unwrap();
let order = Order::buy("AAPL", 100, OrderType::Limit, TimeInForce::DAY)
.limit_price(100.0)
.place(sandbox).await.unwrap();
}
use alpaca_finance::{ Alpaca, Streamer, StreamMessage };
use futures::{ future, StreamExt };
#[tokio::main]
async fn main() {
// Get a connection to the live API
let alpaca = Alpaca::paper("My KEY ID", "My Secret Key").await.unwrap();
let streamer = Streamer:new(&alpaca);
streamer.start().await
.for_each(|msg| {
match msg {
StreamMessage::Account(_) => println!("Got an account update!"),
StreamMessage::Order(_) => println!("Got an order update!"),
_ => println!("Got an unexpected msg")
}
future::ready(())
})
.await;
}
Add this to your Cargo.toml
:
alpaca-finance = "0.2"