Skip to main content

Crate chainstream_sdk

Crate chainstream_sdk 

Source
Expand description

ChainStream SDK for Rust

This SDK provides a Rust client for interacting with the ChainStream API, including both REST API and real-time WebSocket streaming capabilities.

§Features

  • REST API: Auto-generated OpenAPI client for all ChainStream endpoints
  • Stream API: Real-time WebSocket subscriptions using the Centrifuge protocol
  • Type-safe: Strongly typed models for all API responses

§Quick Start

use chainstream_sdk::{ChainStreamClient, stream::TokenCandle};

#[tokio::main]
async fn main() {
    // Create a client with your access token
    let client = ChainStreamClient::new("your-access-token", None);

    // Subscribe to real-time token candles
    let unsub = client.stream.subscribe_token_candles(
        "sol",
        "So11111111111111111111111111111111111111112",
        "1s",
        |candle: TokenCandle| {
            println!("Open: {}, Close: {}", candle.open, candle.close);
        },
        None,
    ).await.unwrap();

    // Keep the connection alive
    tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;

    // Unsubscribe when done
    unsub.unsubscribe();

    // Close all connections
    client.close().await;
}

Re-exports§

pub use chainstream::ChainStreamClient;
pub use chainstream::ChainStreamClientOptions;
pub use chainstream::StaticTokenProvider;
pub use chainstream::TokenProvider;
pub use error::ChainStreamError;

Modules§

chainstream
ChainStream Client - Main entry point for the SDK
error
openapi
OpenAPI generated REST API client for ChainStream
stream
WebSocket Stream API for real-time data subscriptions

Constants§

CHAINSTREAM_BASE_URL
The default base URL for the ChainStream API
CHAINSTREAM_STREAM_URL
The default WebSocket URL for the ChainStream Stream API