Skip to main content

lightcone_sdk/api/
mod.rs

1//! REST API client module for Lightcone.
2//!
3//! This module provides a type-safe HTTP client for interacting with
4//! the Lightcone REST API for market data, orderbooks, orders, and more.
5//!
6//! # Quick Start
7//!
8//! ```rust,ignore
9//! use lightcone_sdk::api::LightconeApiClient;
10//!
11//! #[tokio::main]
12//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
13//!     // Create client with default settings
14//!     let client = LightconeApiClient::new("https://api.lightcone.xyz");
15//!
16//!     // Get all markets
17//!     let markets = client.get_markets().await?;
18//!     println!("Found {} markets", markets.total);
19//!
20//!     // Get a specific market
21//!     let market = client.get_market("market_pubkey").await?;
22//!     println!("Market: {}", market.market.market_name);
23//!
24//!     // Get orderbook
25//!     let orderbook = client.get_orderbook("orderbook_id", Some(10)).await?;
26//!     println!("Best bid: {:?}, Best ask: {:?}", orderbook.best_bid, orderbook.best_ask);
27//!
28//!     Ok(())
29//! }
30//! ```
31//!
32//! # Client Configuration
33//!
34//! Use the builder pattern for custom configuration:
35//!
36//! ```rust,ignore
37//! use lightcone_sdk::api::LightconeApiClient;
38//! use std::time::Duration;
39//!
40//! let client = LightconeApiClient::builder("https://api.lightcone.xyz")
41//!     .timeout(Duration::from_secs(60))
42//!     .header("X-Custom-Header", "value")
43//!     .build()?;
44//! ```
45//!
46//! # Error Handling
47//!
48//! All methods return `ApiResult<T>` which is an alias for `Result<T, ApiError>`.
49//! The [`ApiError`] enum covers all possible error cases:
50//!
51//! ```rust,ignore
52//! use lightcone_sdk::api::{LightconeApiClient, ApiError};
53//!
54//! match client.get_market("invalid_pubkey").await {
55//!     Ok(market) => println!("Found market"),
56//!     Err(ApiError::NotFound(resp)) => println!("Market not found: {}", resp),
57//!     Err(ApiError::BadRequest(resp)) => println!("Invalid request: {}", resp),
58//!     Err(e) => println!("Other error: {}", e),
59//! }
60//! ```
61//!
62//! # Order Submission
63//!
64//! Orders must be pre-signed with Ed25519. Use the program module to create
65//! and sign orders, then submit via the API:
66//!
67//! ```rust,ignore
68//! use lightcone_sdk::api::{LightconeApiClient, SubmitOrderRequest};
69//!
70//! let request = SubmitOrderRequest {
71//!     maker: "maker_pubkey".to_string(),
72//!     nonce: 1,
73//!     market_pubkey: "market_pubkey".to_string(),
74//!     base_token: "base_token".to_string(),
75//!     quote_token: "quote_token".to_string(),
76//!     side: 0, // BID
77//!     maker_amount: 1000000,
78//!     taker_amount: 500000,
79//!     expiration: 0, // No expiration
80//!     signature: "hex_encoded_signature".to_string(),
81//!     orderbook_id: "orderbook_id".to_string(),
82//! };
83//!
84//! let response = client.submit_order(request).await?;
85//! println!("Order hash: {}", response.order_hash);
86//! ```
87
88pub mod client;
89pub mod error;
90pub mod types;
91
92// Re-export main types for convenience
93pub use client::{LightconeApiClient, LightconeApiClientBuilder, RetryConfig};
94pub use error::{ApiError, ApiResult, ErrorResponse};
95pub use types::*;