tradestation_api/streaming/mod.rs
1//! HTTP chunked-transfer streaming for TradeStation v3.
2//!
3//! TradeStation uses HTTP streaming (NOT WebSocket):
4//! - Content-Type: `application/vnd.tradestation.streams.v3+json`
5//! - Newline-delimited JSON objects
6//! - `StreamStatus` messages signal snapshot boundaries (`EndSnapshot`) and
7//! reconnect requests (`GoAway`)
8//!
9//! All stream methods return a [`BoxStream`] of typed updates that can be
10//! consumed with `futures::StreamExt`.
11//!
12//! # Example
13//!
14//! ```no_run
15//! # use tradestation_api::{Client, Credentials};
16//! # async fn example(client: &mut Client) -> Result<(), Box<dyn std::error::Error>> {
17//! use futures::StreamExt;
18//!
19//! let mut stream = client.stream_quotes(&["AAPL"]).await?;
20//! while let Some(result) = stream.next().await {
21//! let quote = result?;
22//! if !quote.is_status() {
23//! println!("{}: {}", quote.symbol.as_deref().unwrap_or("?"), quote.last.as_deref().unwrap_or("?"));
24//! }
25//! }
26//! # Ok(())
27//! # }
28//! ```
29
30use futures::stream::Stream;
31use std::pin::Pin;
32
33use crate::Error;
34
35mod brokerage_streams;
36mod dto;
37mod market_data_streams;
38
39pub use dto::*;
40
41/// Type alias for a boxed async stream of results.
42///
43/// All streaming methods return this type. Consume it with
44/// `futures::StreamExt::next()`.
45pub type BoxStream<T> = Pin<Box<dyn Stream<Item = Result<T, Error>> + Send>>;