Skip to main content

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, openapi::types::Resolution, 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//!         Resolution::X1s,
27//!         |candle: TokenCandle| {
28//!             println!("Open: {}, Close: {}", candle.open, candle.close);
29//!         },
30//!         None,
31//!         None,
32//!     ).await.unwrap();
33//!
34//!     // Keep the connection alive
35//!     tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
36//!
37//!     // Unsubscribe when done
38//!     unsub.unsubscribe();
39//!
40//!     // Close all connections
41//!     client.close().await;
42//! }
43//! ```
44
45#![allow(clippy::doc_lazy_continuation)]
46#![allow(clippy::doc_overindented_list_items)]
47
48pub mod chainstream;
49pub mod error;
50pub mod openapi;
51pub mod stream;
52pub mod wallet_auth;
53
54// Re-export main types at crate root
55pub use chainstream::{
56    ChainStreamClient, ChainStreamClientOptions, StaticTokenProvider, TokenProvider,
57};
58pub use error::ChainStreamError;
59
60/// The default base URL for the ChainStream API
61pub const CHAINSTREAM_BASE_URL: &str = "https://api.chainstream.io";
62
63/// The default WebSocket URL for the ChainStream Stream API
64pub const CHAINSTREAM_STREAM_URL: &str = "wss://realtime-dex.chainstream.io/connection/websocket";