Expand description
§Tradestation Rust Client
High level, fully featured, and ergonomic rust client for the TradeStation API.
§Features
- Accounting
- Market Data
- Execution
§Install
Use Cargo CLI:
cargo install tradestation-rs
Or manually add it into your Cargo.toml
:
[dependencies]
tradestation = "0.1.2"
§Usage
Simple example for streaming 4 hour aggregated bars of trading activity for Crude Oil Futures:
ⓘ
use tradestation_rs::{
responses::MarketData::StreamBarsResp,
ClientBuilder, Error,
MarketData::{self, BarUnit},
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut client = ClientBuilder::new()?
.credentials("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")?
.authorize("YOUR_AUTHORIZATION_CODE")
.await?
.build()
.await?;
println!("Your TradeStation API Bearer Token: {:?}", client.token);
let stream_bars_query = MarketData::StreamBarsQueryBuilder::new()
.symbol("CLX24")
.unit(BarUnit::Minute)
.interval("240")
.build()?;
let streamed_bars = client
.stream_bars(&stream_bars_query, |stream_data| {
match stream_data {
StreamBarsResp::Bar(bar) => {
// Do something with the bars like making a chart
println!("{bar:?}")
}
StreamBarsResp::Heartbeat(heartbeat) => {
if heartbeat.heartbeat > 10 {
return Err(Error::StopStream);
}
}
StreamBarsResp::Status(status) => {
println!("{status:?}");
}
StreamBarsResp::Error(err) => {
println!("{err:?}");
}
}
Ok(())
})
.await?;
// All the bars collected during the stream
println!("{streamed_bars:?}");
Ok(())
}
Re-exports§
pub use client::Client;
pub use client::ClientBuilder;
pub use error::Error;
pub use market_data as MarketData;
pub use token::Token;
pub use execution::Route;