Expand description
REST API client module for market data, orders, and positions. REST API client module for Lightcone.
This module provides a type-safe HTTP client for interacting with the Lightcone REST API for market data, orderbooks, orders, and more.
§Quick Start
ⓘ
use lightcone_sdk::api::LightconeApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client with default settings
let client = LightconeApiClient::new("https://api.lightcone.xyz");
// Get all markets
let markets = client.get_markets().await?;
println!("Found {} markets", markets.total);
// Get a specific market
let market = client.get_market("market_pubkey").await?;
println!("Market: {}", market.market.market_name);
// Get orderbook
let orderbook = client.get_orderbook("orderbook_id", Some(10)).await?;
println!("Best bid: {:?}, Best ask: {:?}", orderbook.best_bid, orderbook.best_ask);
Ok(())
}§Client Configuration
Use the builder pattern for custom configuration:
ⓘ
use lightcone_sdk::api::LightconeApiClient;
use std::time::Duration;
let client = LightconeApiClient::builder("https://api.lightcone.xyz")
.timeout(Duration::from_secs(60))
.header("X-Custom-Header", "value")
.build()?;§Error Handling
All methods return ApiResult<T> which is an alias for Result<T, ApiError>.
The [ApiError] enum covers all possible error cases:
ⓘ
use lightcone_sdk::api::{LightconeApiClient, ApiError};
match client.get_market("invalid_pubkey").await {
Ok(market) => println!("Found market"),
Err(ApiError::NotFound(resp)) => println!("Market not found: {}", resp),
Err(ApiError::BadRequest(resp)) => println!("Invalid request: {}", resp),
Err(e) => println!("Other error: {}", e),
}§Order Submission
Orders must be pre-signed with Ed25519. Use the program module to create and sign orders, then submit via the API:
ⓘ
use lightcone_sdk::api::{LightconeApiClient, SubmitOrderRequest};
let request = SubmitOrderRequest {
maker: "maker_pubkey".to_string(),
nonce: 1,
market_pubkey: "market_pubkey".to_string(),
base_token: "base_token".to_string(),
quote_token: "quote_token".to_string(),
side: 0, // BID
maker_amount: 1000000,
taker_amount: 500000,
expiration: 0, // No expiration
signature: "hex_encoded_signature".to_string(),
orderbook_id: "orderbook_id".to_string(),
};
let response = client.submit_order(request).await?;
println!("Order hash: {}", response.order_hash);Re-exports§
pub use client::LightconeApiClient;pub use client::LightconeApiClientBuilder;pub use client::RetryConfig;pub use error::ApiError;pub use error::ApiResult;pub use error::ErrorResponse;pub use types::*;