nomy-data-models 0.35.5

Data model definitions for Nomy wallet analysis data processing
Documentation
#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
//! MarketPrice model definition.
//!
//! This file is generated automatically from the Python SQLAlchemy model.
//! Do not edit this file manually.

use serde::{Deserialize, Serialize};

// Standard imports that may be needed
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde_json::Value as JsonValue;
use uuid::Uuid;

// Additional imports specific to this model
// No additional imports needed

/// 
///     Market price model for storing current asset prices in USD.
/// 
///     This model stores the current market price for assets identified by their symbol.
///     It does not track historical prices - each symbol will have only one entry
///     that is updated (upserted) when new price data is available.
/// 
///     Attributes:
///         token_symbol: The unique identifier for the token (e.g., "BTC", "ETH", "SOL")
///         price_usd: The current price of the token in USD
///         source: The source of the price data (e.g., "coinmarketcap", "coingecko")
///         market_cap_usd: Optional market capitalization in USD
///         volume_24h_usd: Optional 24-hour trading volume in USD
/// 
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketPrice {
    pub token_symbol: String,
    pub price_usd: Decimal,
    pub price_change_24h: Option<Decimal>,
    pub source: String,
    pub market_cap_usd: Option<Decimal>,
    pub volume_24h_usd: Option<Decimal>,
    pub id: Uuid,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub created_by: Option<String>,
    pub updated_by: Option<String>,
}

impl MarketPrice {
    /// Create a new MarketPrice.
    pub fn new(
        token_symbol: String,
        price_usd: Decimal,
        price_change_24h: Decimal,
        source: String,
        market_cap_usd: Decimal,
        volume_24h_usd: Decimal,
        id: Uuid,
        created_at: DateTime<Utc>,
        updated_at: DateTime<Utc>,
        created_by: String,
        updated_by: String,
    ) -> Self {
        Self {
            token_symbol,
            price_usd,
            price_change_24h: Some(price_change_24h),
            source,
            market_cap_usd: Some(market_cap_usd),
            volume_24h_usd: Some(volume_24h_usd),
            id,
            created_at,
            updated_at,
            created_by: Some(created_by),
            updated_by: Some(updated_by),
        }
    }

    /// Convert to a JSON string.
    pub fn to_json(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string(self)
    }

    /// Convert from a JSON string.
    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
        serde_json::from_str(json)
    }

    /// Convert to a dictionary-like structure.
    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
        if let serde_json::Value::Object(map) = json {
            map
        } else {
            serde_json::Map::new()
        }
    }
}