1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
//! # Alpaca Finance //! //! Alpaca.markets provides a great set of APIs for developing algorithmic-based //! stock trading. //! //! **ALWAYS VERIFY WITH THE PAPER API BEFORE USING THE LIVE API** //! //! Currently `alpaca_finance` provides: //! * Access and authentication against the paper trading and live trading APIs //! * Account API to get important information about your account //! * Orders API to place, replace, cancel and get open orders. //! * Realtime streaming updates to orders and account changes //! //! ## Quick Examples //! //! To find out how much cash you have in your account: //! //! ``` no run //! 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) //! } //! ``` //! //! To buy 100 shares of AAPL, through the paper API, at a limit price of $100.0 before the end of today: //! //! ``` no run //! 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(); //! } //! ``` //! //! To watch for changes to orders or the account: //! //! ``` no run //! 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; //! } //! ``` mod account; pub use account::{ Account, AccountStatus }; mod alpaca; pub use alpaca::Alpaca; mod error; use snafu::Snafu; /// An opaque error hit when calling Alpaca #[derive(Debug, Snafu)] pub struct Error(error::InnerError); /// The result of an operation pub type Result<T> = std::result::Result<T, Error>; mod order; pub use order::{ Order, OrderBuilder, OrderStatus, OrderType, OrderUpdater, TimeInForce }; mod streaming; pub use streaming::{ OrderEvent, Streamer, StreamMessage }; mod util;