tradestation-api 0.1.0

Complete TradeStation REST API v3 wrapper for Rust
Documentation
//! Stream live quotes for one or more symbols.
//!
//! Run with:
//! ```sh
//! TRADESTATION_CLIENT_ID=xxx TRADESTATION_CLIENT_SECRET=yyy cargo run --example stream_quotes
//! ```

use tradestation_api::{Client, Credentials, Scope};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client_id =
        std::env::var("TRADESTATION_CLIENT_ID").unwrap_or_else(|_| "YOUR_CLIENT_ID".to_string());
    let client_secret = std::env::var("TRADESTATION_CLIENT_SECRET")
        .unwrap_or_else(|_| "YOUR_CLIENT_SECRET".to_string());

    let creds = Credentials::new(client_id, client_secret);
    println!("Authorization URL:");
    println!("{}", creds.authorization_url(&Scope::defaults()));

    // In a real app, authenticate first:
    // let mut client = Client::new(creds);
    // client.authenticate("AUTH_CODE").await?;
    //
    // Then stream quotes:
    // use futures::StreamExt;
    // let mut stream = client.stream_quotes(&["AAPL", "MSFT"]).await?;
    // while let Some(result) = stream.next().await {
    //     match result {
    //         Ok(quote) => {
    //             if quote.is_go_away() {
    //                 println!("Server requested reconnect");
    //                 break;
    //             }
    //             if !quote.is_status() {
    //                 println!(
    //                     "{}: last={} bid={} ask={}",
    //                     quote.symbol.as_deref().unwrap_or("?"),
    //                     quote.last.as_deref().unwrap_or("?"),
    //                     quote.bid.as_deref().unwrap_or("?"),
    //                     quote.ask.as_deref().unwrap_or("?"),
    //                 );
    //             }
    //         }
    //         Err(e) => {
    //             eprintln!("Stream error: {e}");
    //             break;
    //         }
    //     }
    // }

    let _client = Client::new(creds);
    println!("(See README for full streaming flow)");
    Ok(())
}