precolator-sdk 1.0.0

Rust async client SDK for the Precolator perpetual futures trading platform — markets, portfolio, leaderboard, and trading statistics.
Documentation
//! Strongly-typed response models for every Precolator API endpoint.

use serde::{Deserialize, Serialize};

// ─── Generic API wrapper ────────────────────────────────────────────────────

/// Standard JSON envelope returned by every endpoint.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiResponse<T> {
    pub data: T,
    pub timestamp: String,
    pub status: String,
}

/// Error body returned on non-2xx responses.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiError {
    pub error: String,
    pub status: u16,
    pub message: String,
}

// ─── Health ─────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthStatus {
    pub status: String,
    pub uptime: Option<f64>,
    pub version: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DetailedHealth {
    pub status: String,
    pub uptime: Option<f64>,
    pub version: Option<String>,
    pub solana_rpc: Option<String>,
    pub database: Option<String>,
}

// ─── Markets ────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Market {
    pub id: String,
    pub name: String,
    pub base_token: String,
    pub quote_token: String,
    pub price: f64,
    pub volume_24h: Option<f64>,
    pub open_interest: Option<f64>,
    pub max_leverage: Option<u8>,
    pub status: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketStats {
    pub market_id: String,
    pub volume_24h: f64,
    pub trades_24h: u64,
    pub high_24h: f64,
    pub low_24h: f64,
    pub price_change_24h: f64,
    pub open_interest: f64,
}

// ─── Trades ─────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Trade {
    pub trade_id: String,
    pub market_id: String,
    pub trader: String,
    pub side: String,
    pub size: f64,
    pub price: f64,
    pub leverage: Option<u8>,
    pub pnl: Option<f64>,
    pub fee: Option<f64>,
    pub timestamp: String,
}

// ─── Portfolio ──────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Portfolio {
    pub wallet: String,
    pub total_balance: f64,
    pub unrealized_pnl: f64,
    pub realized_pnl: f64,
    pub positions: Vec<PortfolioPosition>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortfolioPosition {
    pub market_id: String,
    pub side: String,
    pub size: f64,
    pub entry_price: f64,
    pub current_price: f64,
    pub pnl: f64,
    pub leverage: u8,
    pub liquidation_price: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortfolioHistory {
    pub wallet: String,
    pub entries: Vec<HistoryEntry>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoryEntry {
    pub timestamp: String,
    pub balance: f64,
    pub pnl: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortfolioStats {
    pub wallet: String,
    pub total_trades: u64,
    pub win_rate: f64,
    pub avg_pnl: f64,
    pub best_trade: f64,
    pub worst_trade: f64,
    pub total_volume: f64,
}

// ─── Leaderboard ────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LeaderboardEntry {
    pub rank: u32,
    pub wallet: String,
    pub pnl: f64,
    pub win_rate: f64,
    pub total_trades: u64,
    pub volume: f64,
}

// ─── Tokens ─────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Token {
    pub symbol: String,
    pub name: String,
    pub mint: Option<String>,
    pub decimals: Option<u8>,
    pub price: Option<f64>,
    pub market_cap: Option<f64>,
}

// ─── Statistics ─────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformStats {
    pub total_volume: f64,
    pub total_trades: u64,
    pub total_users: u64,
    pub open_interest: f64,
    pub total_fees: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketOverview {
    pub markets: Vec<MarketStats>,
    pub total_markets: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExchangeMetrics {
    pub volume_24h: f64,
    pub trades_24h: u64,
    pub active_users_24h: u64,
    pub liquidations_24h: u64,
    pub fees_24h: f64,
}