fts-core 0.4.0

A collection of ports and models for use in flow trading implementations
Documentation
use crate::models::{DemandGroup, ProductGroup};
use std::hash::Hash;

/// Represents a portfolio entity in the flow trading system.
///
/// A portfolio acts as a container that groups together related demands and products
/// for a specific bidder. It enables:
/// - Aggregation of multiple demands into a single trading entity
/// - Association of demands with specific products they can trade
/// - Weighted distribution of allocations across demands
///
/// # Relationships
///
/// - **Bidder**: Each portfolio is owned by exactly one bidder
/// - **Demands**: Multiple demands can be associated to a portfolio, each with individual weights
/// - **Products**: Multiple products can be associated to a portfolio, each with individual weights
#[cfg_attr(
    feature = "schemars",
    derive(schemars::JsonSchema),
    schemars(rename = "PortfolioRecord")
)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Serialize, serde::Deserialize),
    serde(bound(serialize = "
            DateTime: serde::Serialize,
            BidderId: serde::Serialize,
            PortfolioId: serde::Serialize + Clone,
            DemandId: serde::Serialize + Clone,
            ProductId: serde::Serialize + Clone,
            AppData: serde::Serialize
        "))
)]
pub struct PortfolioRecord<
    DateTime,
    BidderId: Eq,
    PortfolioId: Eq + Hash,
    DemandId: Eq + Hash,
    ProductId: Eq + Hash,
    AppData,
> {
    /// Unique identifier for this portfolio instance.
    /// Generated by the application when creating a new portfolio.
    pub id: PortfolioId,

    /// Timestamp when this version of the portfolio was created or last updated.
    /// Used for temporal queries and history tracking.
    pub as_of: DateTime,

    /// Application-specific data attached to this portfolio.
    /// This field allows extending the portfolio with custom data without
    /// modifying the core schema.
    pub app_data: AppData,

    /// The bidder who owns this portfolio.
    /// A bidder can have multiple portfolios to organize different trading strategies.
    pub bidder_id: BidderId,

    /// Map of demands associated with this portfolio and their weights.
    pub demand_group: DemandGroup<DemandId>,

    /// Map of products this portfolio can trade and their weights.
    pub product_group: ProductGroup<ProductId>,
}