dexscreener_rs/
lib.rs

1//! # dexscreener-rs
2//!
3//! A Rust client library for interacting with the [DexScreener API](https://docs.dexscreener.com/api/reference).
4//! This library provides a type-safe, ergonomic way to access DexScreener's data about decentralized
5//! exchange trading pairs across multiple blockchains.
6//!
7//! ## Features
8//!
9//! - Complete support for all DexScreener API endpoints
10//! - Fully asynchronous API with Tokio runtime support
11//! - Type-safe return values with comprehensive error handling
12//! - Flexible configuration options
13//! - Robust parsing of various data formats
14//!
15//! ## Basic Usage
16//!
17//! ```no_run
18//! use dexscreener_rs::DexScreenerClient;
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//!     // Create a new client instance
23//!     let client = DexScreenerClient::new();
24//!
25//!     // Get information for a specific trading pair
26//!     let pair_response = client.get_pairs_by_chain_and_address(
27//!         "ethereum",
28//!         "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
29//!     ).await?;
30//!
31//!     if let Some(pair) = pair_response.pairs.first() {
32//!         println!("Pair: {} - {}", pair.base_token.symbol, pair.quote_token.symbol);
33//!         println!("Price: ${:.2}", pair.price_usd.unwrap_or(0.0));
34//!         println!("24h Volume: ${:.2}", pair.volume.h24);
35//!     }
36//!
37//!     // Get all pairs containing a specific token
38//!     let token_response = client.get_pair_by_token_address(
39//!         "ethereum",
40//!         "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"  // WETH
41//!     ).await?;
42//!
43//!     println!("Found {} pairs containing the token", token_response.pairs.len());
44//!
45//!     Ok(())
46//! }
47//! ```
48//!
49//! ## Error Handling
50//!
51//! All API methods return a `Result<T, DexScreenerError>` where `T` is the appropriate response type.
52//! The `DexScreenerError` enum provides detailed information about what went wrong, including
53//! API errors, network issues, and parsing problems.
54//!
55//! ## Rate Limiting
56//!
57//! The DexScreener API has rate limits that vary by endpoint. These are documented in each method.
58//! When a rate limit is exceeded, the API will return an error, which this library will propagate
59//! as a `DexScreenerError::ApiError`.
60
61// Module declarations
62pub mod client;
63pub mod errors;
64pub mod models;
65
66// Public exports
67pub use client::DexScreenerClient;
68pub use errors::DexScreenerError;
69pub use models::{
70    BaseToken, Liquidity, PairResponse, PairTransactionCounts, PriceChangePeriods, SearchResponse,
71    TokenPair, TransactionCount, VolumeChangePeriods,
72};
73
74/// API version used by this crate
75pub const API_VERSION: &str = "latest";
76
77/// Base URL for DexScreener API
78pub const API_BASE_URL: &str = "https://api.dexscreener.com";