tradestation_rs/
lib.rs

1//! # Tradestation Rust Client
2//!
3//! High level, fully featured, and ergonomic rust client for the TradeStation API.
4//!
5//! ## Features
6//!
7//! - Accounting
8//! - Market Data
9//! - Execution
10//!
11//! ## Install
12//!
13//! Use Cargo CLI:
14//! ```bash
15//! cargo install tradestation-rs
16//! ```
17//! Or manually add it into your `Cargo.toml`:
18//! ```toml
19//! [dependencies]
20//! tradestation = "0.1.2"
21//! ```
22//!
23//! ## Usage
24//!
25//! Simple example for streaming 4 hour aggregated
26//! bars of trading activity for Crude Oil Futures:
27//! ```ignore
28//! use tradestation_rs::{
29//!     responses::MarketData::StreamBarsResp,
30//!     ClientBuilder, Error,
31//!     MarketData::{self, BarUnit},
32//! };
33//!
34//! #[tokio::main]
35//! async fn main() -> Result<(), Error> {
36//!     let mut client = ClientBuilder::new()?
37//!         .credentials("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")?
38//!         .authorize("YOUR_AUTHORIZATION_CODE")
39//!         .await?
40//!         .build()
41//!         .await?;
42//!     println!("Your TradeStation API Bearer Token: {:?}", client.token);
43//!
44//!     let stream_bars_query = MarketData::StreamBarsQueryBuilder::new()
45//!         .symbol("CLX24")
46//!         .unit(BarUnit::Minute)
47//!         .interval("240")
48//!         .build()?;
49//!
50//!     let streamed_bars = client
51//!         .stream_bars(&stream_bars_query, |stream_data| {
52//!             match stream_data {
53//!                 StreamBarsResp::Bar(bar) => {
54//!                     // Do something with the bars like making a chart
55//!                     println!("{bar:?}")
56//!                 }
57//!                 StreamBarsResp::Heartbeat(heartbeat) => {
58//!                     if heartbeat.heartbeat > 10 {
59//!                         return Err(Error::StopStream);
60//!                     }
61//!                 }
62//!                 StreamBarsResp::Status(status) => {
63//!                     println!("{status:?}");
64//!                 }
65//!                 StreamBarsResp::Error(err) => {
66//!                     println!("{err:?}");
67//!                 }
68//!             }
69//!
70//!             Ok(())
71//!         })
72//!         .await?;
73//!
74//!     // All the bars collected during the stream
75//!     println!("{streamed_bars:?}");
76//!
77//!     Ok(())
78//! }
79//! ```
80
81pub mod account;
82pub mod responses;
83
84pub mod client;
85pub use client::{Client, ClientBuilder};
86
87pub mod error;
88pub use error::Error;
89
90pub mod market_data;
91pub use market_data as MarketData;
92
93pub mod token;
94pub use token::Token;
95
96pub mod execution;
97pub use execution::Route;