1 unstable release

0.1.0 Mar 25, 2025

#257 in HTTP client

Download history 50/week @ 2025-03-19 63/week @ 2025-03-26

113 downloads per month

MIT license

32KB
324 lines

dexscreener-rs

Crates.io Documentation License: MIT

A Rust client library for interacting with the DexScreener API.

Features

  • Support for all DexScreener API endpoints
  • Asynchronous API calls
  • Type-safe return values
  • Simple and intuitive interface design
  • Pure Rust implementation with minimal dependencies

Installation

Add the following dependency to your Cargo.toml file:


lib.rs:

dexscreener-rs

A Rust client library for interacting with the DexScreener API. This library provides a type-safe, ergonomic way to access DexScreener's data about decentralized exchange trading pairs across multiple blockchains.

Features

  • Complete support for all DexScreener API endpoints
  • Fully asynchronous API with Tokio runtime support
  • Type-safe return values with comprehensive error handling
  • Flexible configuration options
  • Robust parsing of various data formats

Basic Usage

use dexscreener_rs::DexScreenerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new client instance
    let client = DexScreenerClient::new();

    // Get information for a specific trading pair
    let pair_response = client.get_pairs_by_chain_and_address(
        "ethereum",
        "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
    ).await?;

    if let Some(pair) = pair_response.pairs.first() {
        println!("Pair: {} - {}", pair.base_token.symbol, pair.quote_token.symbol);
        println!("Price: ${:.2}", pair.price_usd.unwrap_or(0.0));
        println!("24h Volume: ${:.2}", pair.volume.h24);
    }

    // Get all pairs containing a specific token
    let token_response = client.get_pair_by_token_address(
        "ethereum",
        "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"  // WETH
    ).await?;

    println!("Found {} pairs containing the token", token_response.pairs.len());

    Ok(())
}

Error Handling

All API methods return a Result<T, DexScreenerError> where T is the appropriate response type. The DexScreenerError enum provides detailed information about what went wrong, including API errors, network issues, and parsing problems.

Rate Limiting

The DexScreener API has rate limits that vary by endpoint. These are documented in each method. When a rate limit is exceeded, the API will return an error, which this library will propagate as a DexScreenerError::ApiError.

Dependencies

~7–19MB
~254K SLoC