A comprehensive Rust SDK for accessing Cosmic Markets APIs, providing seamless integration with Solana DeFi protocols including Drift Protocol, Jupiter, Kamino, and more.
- π― Drift Protocol V2 - Markets, positions, orders, PnL history, and analytics
- π Jupiter Integration - DCA orders, limit orders, and token analytics
- π§ Kamino Finance - Swap data and analytics
- π OHLC Data - Historical price data for tokens
- π€ Trader Profiles - Trader scoring and performance metrics
- π Token Search - Comprehensive token discovery
- πͺΆ Minimal Dependencies - Only 5 dependencies for a lightweight footprint
Add this to your Cargo.toml:
[dependencies]
cosmic-rust-sdk = { git = "https://github.com/cosmic-markets/cosmic-rust-sdk", rev = "034d488" }Note: For local development, use
path = "."instead of the git dependency.
use cosmic_rust_sdk::Cosmic;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize client (no API key = rate limits apply)
let client = Cosmic::new(None)?;
// Fetch all Drift markets
let markets = client.drift.get_all_markets(Default::default()).await?;
println!("π Found {} markets", markets.content.len());
Ok(())
}use cosmic_rust_sdk::Cosmic;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize with API key for higher rate limits
let client = Cosmic::new(Some("YOUR_API_KEY".to_string()))?;
// Your code here...
Ok(())
}use cosmic_rust_sdk::Cosmic;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Cosmic::new(None)?;
let wallet = "EXYq2HaS5nTarjzNHVYfcHbAbbLDJTPYkn1Jb5Q6bGz4";
let positions = client.drift.get_user_perp_positions(wallet).await?;
println!("π Found {} active positions", positions.len());
for pos in positions {
if let Some(market) = &pos.market_name {
println!("Market: {}", market);
println!(" Size: {} {}",
pos.base_asset_amount.unwrap_or(0.0),
pos.base_asset_symbol.unwrap_or_default()
);
println!(" Unrealized PnL: ${:.2}", pos.unrealized_pnl.unwrap_or(0.0));
}
}
Ok(())
}use cosmic_rust_sdk::Cosmic;
use cosmic_rust_sdk::api::jupiter::GetDcaOrdersRequest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Cosmic::new(None)?;
let request = GetDcaOrdersRequest {
page: Some(1),
size: Some(10),
..Default::default()
};
let orders = client.jupiter.get_orders(request).await?;
println!("π Found {} DCA orders", orders.content.len());
Ok(())
}use cosmic_rust_sdk::Cosmic;
use cosmic_rust_sdk::api::drift::GetDriftMarketsRequest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Cosmic::new(None)?;
let request = GetDriftMarketsRequest {
size: Some(5),
..Default::default()
};
let markets = client.drift.get_all_markets(request).await?;
for market in markets.content {
println!("Market: {}", market.market_name.unwrap_or_default());
println!(" Index: {}", market.market_index.unwrap_or(0));
println!(" Type: {}", market.market_type.unwrap_or_default());
}
Ok(())
}To avoid strict rate limits, use an API key. You can purchase one at cosmic.markets/api/docs.
let client = Cosmic::new(Some("YOUR_API_KEY".to_string()))?;- π Official API Docs
- π¦ Rust Docs
Run these examples to see the SDK in action:
| Example | Command | Description |
|---|---|---|
| Perp Positions | cargo run --example perp_positions |
Retrieves active perpetual futures positions for a wallet |
| PnL History | cargo run --example pnl_history |
Analyzes settled PnL over time for a specific market |
| DEX Volume | cargo run --example dex_volume |
Tracks volume across Drift and Jupiter protocols |
| Limit Orders | cargo run --example limit_orders |
Inspects recent limit order activity on Jupiter |
| DCA Orders | cargo run --example dca_orders |
Inspects recent DCA order activity |
When running tests without a paid API key, use single-threaded execution to avoid rate limits:
cargo test -- --test-threads=1With a paid API key, you can run tests in parallel:
cargo test| Module | Description |
|---|---|
drift |
Drift Protocol V2 - Markets, positions, orders, history, and analytics |
jupiter |
Jupiter aggregator - DCA orders, limit orders, and token analytics |
kamino |
Kamino Finance - Swap data and analytics |
ohlc |
Historical OHLC price data for tokens |
trader |
Trader profiling, scoring, and performance metrics |
search |
Token search and discovery capabilities |
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- π Cosmic Markets
- π API Documentation
- π¬ GitHub Issues