Skip to main content

datamaxi/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![forbid(unsafe_code)]
3#![warn(missing_docs)]
4//! # DataMaxi+ Rust SDK
5//!
6//! This is the official implementation of Rust SDK for [DataMaxi+](https://datamaxiplus.com/).
7//! The package can be used to fetch both historical and latest data using [DataMaxi+ API](https://docs.datamaxiplus.com/).
8//!
9//! - [Installation](#installation)
10//! - [Configuration](#configuration)
11//! - [Links](#links)
12//! - [Contributing](#contributing)
13//! - [License](#license)
14//!
15//! ## Installation
16//!
17//! ```shell
18//! [dependencies]
19//! datamaxi = { git = "https://github.com/bisonai/datamaxi-rust.git" }
20//! ```
21//!
22//! ### Minimum Supported Rust Version (MSRV)
23//!
24//! This crate requires **Rust 1.86** or newer. The MSRV is verified in CI and
25//! may be raised in a minor version bump.
26//!
27//! ## Configuration
28//!
29//! Private API endpoints are protected by an API key.
30//! You can get the API key upon registering at <https://datamaxiplus.com/auth>.
31//!
32//!
33//!| Option     | Explanation                                                                   |
34//!|------------|-------------------------------------------------------------------------------|
35//!| `api_key`  | Your API key                                                                  |
36//!| `base_url` | If `base_url` is not provided, it defaults to `https://api.datamaxiplus.com`. |
37//!
38//! ## Examples
39//!
40//! ### CEX Candle
41//!
42//! The client is async by default (requires a runtime such as `tokio`). For a
43//! synchronous client, enable the `sync` feature; everything the sync API
44//! needs then lives under the single `datamaxi::sync` module, e.g.
45//! `use datamaxi::sync::{Client, CexCandle};`.
46//!
47//! ```no_run
48//! use datamaxi::{
49//!     CexCandleExchangesMarket, CexCandleMarket, CexCandleOptions, CexCandleSymbolsOptions,
50//!     Client,
51//! };
52//!
53//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
54//! let client = Client::new("my_api_key");
55//! let candle = client.cex_candle();
56//!
57//! // Supported exchanges, symbols and intervals
58//! let _ = candle.exchanges(CexCandleExchangesMarket::Spot).await?;
59//! let _ = candle.symbols("binance", CexCandleSymbolsOptions::new()).await?;
60//! let _ = candle.intervals().await?;
61//!
62//! // Fetch CEX candle data
63//! let _ = candle
64//!     .get(
65//!         "binance",
66//!         "BTC-USDT",
67//!         CexCandleOptions::new().market(CexCandleMarket::Spot),
68//!     )
69//!     .await?;
70//! # Ok(())
71//! # }
72//! ```
73//!
74//! ## Links
75//!
76//! - [Official Website](https://datamaxiplus.com/)
77//! - [Documentation](https://docs.datamaxiplus.com/)
78//!
79//! ## Contributing
80//!
81//! We welcome contributions!
82//! If you discover a bug in this project, please feel free to open an issue to discuss the changes you would like to propose.
83//!
84//! ## License
85//!
86//![MIT License](./LICENSE)
87
88/// API definitions and related utilities.
89pub mod api;
90
91// `generated.rs` is code-generated (DO NOT EDIT). Its contents are re-exported
92// at the crate root (below), so callers write `datamaxi::CexCandle` rather than
93// through this module path. Hidden from the docs but kept `pub` for backward
94// compatibility. The lint allows reflect the generator's unconditional imports
95// and its `new()`-only option constructors.
96#[doc(hidden)]
97#[allow(unused_imports, clippy::new_without_default, missing_docs)]
98pub mod generated;
99
100/// Typed wrappers for every REST endpoint on the data API — the canonical
101/// surface (CEX candle, OI, Liquidation, cex-symbol, …). Endpoint groups are
102/// reached through accessors on the root [`Client`]. Async by default; with the
103/// `sync` feature, a parallel [`sync`] module offers synchronous
104/// equivalents.
105///
106/// ```no_run
107/// use datamaxi::{Client, LiquidationHeatmapOptions};
108///
109/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
110/// let client = Client::new("YOUR_API_KEY");
111/// let heatmap = client
112///     .liquidation()
113///     .heatmap(LiquidationHeatmapOptions::new())
114///     .await?;
115/// # Ok(())
116/// # }
117/// ```
118pub use generated::*;
119
120// The async endpoint-wrapper structs (`CexCandle`, `Announcements`, …) now live
121// in a `#[doc(hidden)]` submodule of `generated`; re-export them flat at the
122// crate root so `datamaxi::CexCandle` still resolves. The parallel sync wrappers
123// stay under `datamaxi::sync` (feature `sync`), never flat at the root.
124pub use generated::async_internal::*;
125
126/// The root client and its builder are re-exported at the crate root so callers
127/// write `datamaxi::Client` / `datamaxi::ClientBuilder`. Endpoint groups hang
128/// off the client via generated accessors, e.g. `client.cex_candle()`.
129pub use api::{Client, ClientBuilder};
130
131#[cfg(feature = "sync")]
132#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
133pub mod sync {
134    //! Synchronous entry point for the SDK (feature `sync`) — the synchronous
135    //! counterpart to the crate root.
136    //!
137    //! This one module gathers everything the sync API needs: the [`Client`] /
138    //! [`ClientBuilder`] (synchronous equivalents of the crate-root
139    //! [`crate::Client`] / [`crate::ClientBuilder`]), the [`Paginator`], and the
140    //! synchronous endpoint-wrapper types (`CexCandle`, `Announcements`, …) that
141    //! mirror the ones re-exported at the crate root. Prefer the single import
142    //! path `use datamaxi::sync::{Client, CexCandle};` over combining
143    //! [`crate::api::sync`] with the crate root.
144    //!
145    //! The [`Client`] / [`ClientBuilder`] / [`Paginator`] here are re-exports of
146    //! the same types in [`crate::api::sync`], so those longer paths keep
147    //! working unchanged.
148    //!
149    //! ```no_run
150    //! use datamaxi::sync::Client;
151    //! use datamaxi::CexCandleOptions;
152    //!
153    //! # fn run() -> Result<(), Box<dyn std::error::Error>> {
154    //! let client = Client::new("YOUR_API_KEY");
155    //! let candle = client.cex_candle();
156    //! let _ = candle.get("binance", "BTC-USDT", CexCandleOptions::new())?;
157    //! # Ok(())
158    //! # }
159    //! ```
160    pub use crate::api::sync::{Client, ClientBuilder, Paginator};
161    pub use crate::generated::sync_internal::*;
162}
163
164/// Re-exported so callers can name the exact `reqwest::Client` /
165/// `reqwest::blocking::Client` type expected by
166/// [`ClientBuilder::http_client`] / `sync::ClientBuilder::http_client`
167/// (and the `reqwest::Error` wrapped by [`api::Error::Http`]) without adding
168/// `reqwest` to their own `Cargo.toml` and risking a version mismatch with
169/// this crate's dependency.
170pub use reqwest;
171
172#[cfg(not(any(feature = "native-tls", feature = "rustls-tls")))]
173compile_error!(
174    "datamaxi requires a TLS backend: enable either the `native-tls` (default) \
175     or `rustls-tls` feature. If you set `default-features = false`, add \
176     `features = [\"rustls-tls\"]`."
177);