chainstream_sdk/lib.rs
1//! ChainStream SDK for Rust
2//!
3//! This SDK provides a Rust client for interacting with the ChainStream API,
4//! including both REST API and real-time WebSocket streaming capabilities.
5//!
6//! # Features
7//!
8//! - **REST API**: Auto-generated OpenAPI client for all ChainStream endpoints
9//! - **Stream API**: Real-time WebSocket subscriptions using the Centrifuge protocol
10//! - **Type-safe**: Strongly typed models for all API responses
11//!
12//! # Quick Start
13//!
14//! ```rust,no_run
15//! use chainstream_sdk::{ChainStreamClient, stream::TokenCandle};
16//!
17//! #[tokio::main]
18//! async fn main() {
19//! // Create a client with your access token
20//! let client = ChainStreamClient::new("your-access-token", None);
21//!
22//! // Subscribe to real-time token candles
23//! let unsub = client.stream.subscribe_token_candles(
24//! "sol",
25//! "So11111111111111111111111111111111111111112",
26//! "1s",
27//! |candle: TokenCandle| {
28//! println!("Open: {}, Close: {}", candle.open, candle.close);
29//! },
30//! None,
31//! ).await.unwrap();
32//!
33//! // Keep the connection alive
34//! tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
35//!
36//! // Unsubscribe when done
37//! unsub.unsubscribe();
38//!
39//! // Close all connections
40//! client.close().await;
41//! }
42//! ```
43
44#![allow(clippy::doc_lazy_continuation)]
45#![allow(clippy::doc_overindented_list_items)]
46
47pub mod chainstream;
48pub mod error;
49pub mod openapi;
50pub mod stream;
51
52// Re-export main types at crate root
53pub use chainstream::{ChainStreamClient, ChainStreamClientOptions, StaticTokenProvider, TokenProvider};
54pub use error::ChainStreamError;
55
56/// The default base URL for the ChainStream API
57pub const CHAINSTREAM_BASE_URL: &str = "https://api-dex.chainstream.io";
58
59/// The default WebSocket URL for the ChainStream Stream API
60pub const CHAINSTREAM_STREAM_URL: &str = "wss://realtime-dex.chainstream.io/connection/websocket";