tradestation-api 0.1.0

Complete TradeStation REST API v3 wrapper for Rust
Documentation
//! Place an order using the TradeStation API.
//!
//! Run with:
//! ```sh
//! TRADESTATION_CLIENT_ID=xxx TRADESTATION_CLIENT_SECRET=yyy cargo run --example place_order
//! ```
//!
//! WARNING: Use the simulation API (`Client::with_sim()`) when testing to avoid
//! placing real orders.

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

#[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 (use sim API for testing!):
    // let mut client = Client::new(creds).with_sim();
    // client.authenticate("AUTH_CODE").await?;
    //
    // Build an order request:
    // let order = OrderRequest {
    //     account_id: "SIM123456".into(),
    //     symbol: "AAPL".into(),
    //     quantity: "10".into(),
    //     order_type: "Market".into(),
    //     trade_action: "BUY".into(),
    //     time_in_force: TimeInForce::day(),
    //     limit_price: None,
    //     stop_price: None,
    // };
    //
    // Preview the order first:
    // let preview = client.confirm_order(&order).await?;
    // println!("Preview: {preview:?}");
    //
    // Then place it:
    // let result = client.place_order(&order).await?;
    // if let Some(orders) = &result.orders {
    //     for o in orders {
    //         println!("Order placed: id={:?}", o.order_id);
    //     }
    // }
    // if let Some(errors) = &result.errors {
    //     for e in errors {
    //         eprintln!("Order error: {:?}", e.message);
    //     }
    // }

    // Demonstrate that the types compile
    let _order = OrderRequest {
        account_id: "SIM123456".into(),
        symbol: "AAPL".into(),
        quantity: "10".into(),
        order_type: "Market".into(),
        trade_action: "BUY".into(),
        time_in_force: TimeInForce::day(),
        limit_price: None,
        stop_price: None,
    };

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