Skip to main content

fathom_charts/
lib.rs

1//! Rust client for [Fathom Charts](https://fathomcharts.com): real-time order-flow indicator streams (WebSocket) and
2//! history (REST), on Tokio.
3//!
4//! The SDK handles authentication, the initial snapshot, resuming after a disconnect, duplicates, history pagination and
5//! rate-limit retries. Documentation: <https://fathomcharts.com/docs/sdk/rust>.
6//!
7//! ```no_run
8//! use fathom_charts::{FathomChartsStream, Mode, StreamEvent, SubscribeOptions};
9//! use futures_util::StreamExt;
10//! use serde_json::json;
11//!
12//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
13//! let stream = FathomChartsStream::builder("wss://stream.fathomcharts.com/v1")
14//!     .api_key(std::env::var("FATHOM_CHARTS_API_KEY").map_err(|_| "FATHOM_CHARTS_API_KEY is not set")?)
15//!     .build()?;
16//! let mut big_trades = stream.subscribe::<serde_json::Value>(
17//!     SubscribeOptions::new("NQ.front", "big-trades").params(json!({ "minimum": 30 })).mode(Mode::Confirmed),
18//! )?;
19//! while let Some(event) = big_trades.next().await {
20//!     if let StreamEvent::Upsert(upsert) = event? {
21//!         println!("{} {}", upsert.cursor, upsert.data);
22//!     }
23//! }
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! Cancellation is Rust's: dropping a [`Subscription`] unsubscribes, dropping the future of a REST call or the stream of
29//! `pages`, `history` or `export_ndjson` stops it (including while it waits to retry).
30
31mod error;
32mod protocol;
33mod rest;
34mod stream;
35// The `fathom-charts-types` binary: not part of the library's API.
36#[doc(hidden)]
37pub mod typegen;
38
39pub use error::{Error, ErrorCode, ProblemFieldError, ERROR_CODES};
40pub use protocol::{compare_cursors, CloseCode, From, Item, MaintenanceWindow, Mode, NoticeKind, ResetReason, SourceState, StartFrom};
41pub use rest::{
42    ByteStream, Catalog, CatalogField, CatalogIndicator, CatalogObject, CatalogParam, EngineStatus, Estimate, ExportOptions, ExportResume,
43    ExportStream, FathomChartsRest, HistoryItem, Instrument, InstrumentStatus, Limits, Mutation, MutationKind, Page, PageQuery,
44    PageSnapshot, RangeQuery, RestBuilder, ServiceStatus, StreamToken, Usage, UsageCounters, UsageRemaining,
45};
46pub use stream::{
47    BoxError, ConnectionClose, ConnectionState, FathomChartsStream, Frame, Notice, Reconnect, Remove, Reset, Retrying, Snapshot, Socket,
48    Status, StreamBuilder, StreamEvent, SubscribeOptions, Subscribed, Subscription, Upsert,
49};
50
51#[cfg(test)]
52mod tests;