fts_core/models/
portfolio.rs

1use crate::models::{DemandGroup, ProductGroup};
2use std::hash::Hash;
3
4/// Represents a portfolio entity in the flow trading system.
5///
6/// A portfolio acts as a container that groups together related demands and products
7/// for a specific bidder. It enables:
8/// - Aggregation of multiple demands into a single trading entity
9/// - Association of demands with specific products they can trade
10/// - Weighted distribution of allocations across demands
11///
12/// # Relationships
13///
14/// - **Bidder**: Each portfolio is owned by exactly one bidder
15/// - **Demands**: Multiple demands can be associated to a portfolio, each with individual weights
16/// - **Products**: Multiple products can be associated to a portfolio, each with individual weights
17#[cfg_attr(
18    feature = "schemars",
19    derive(schemars::JsonSchema),
20    schemars(rename = "PortfolioRecord")
21)]
22#[cfg_attr(
23    feature = "serde",
24    derive(serde::Serialize, serde::Deserialize),
25    serde(bound(serialize = "
26            DateTime: serde::Serialize,
27            BidderId: serde::Serialize,
28            PortfolioId: serde::Serialize + Clone,
29            DemandId: serde::Serialize + Clone,
30            ProductId: serde::Serialize + Clone,
31            AppData: serde::Serialize
32        "))
33)]
34pub struct PortfolioRecord<
35    DateTime,
36    BidderId: Eq,
37    PortfolioId: Eq + Hash,
38    DemandId: Eq + Hash,
39    ProductId: Eq + Hash,
40    AppData,
41> {
42    /// Unique identifier for this portfolio instance.
43    /// Generated by the application when creating a new portfolio.
44    pub id: PortfolioId,
45
46    /// Timestamp when this version of the portfolio was created or last updated.
47    /// Used for temporal queries and history tracking.
48    pub as_of: DateTime,
49
50    /// Application-specific data attached to this portfolio.
51    /// This field allows extending the portfolio with custom data without
52    /// modifying the core schema.
53    pub app_data: AppData,
54
55    /// The bidder who owns this portfolio.
56    /// A bidder can have multiple portfolios to organize different trading strategies.
57    pub bidder_id: BidderId,
58
59    /// Map of demands associated with this portfolio and their weights.
60    pub demand_group: DemandGroup<DemandId>,
61
62    /// Map of products this portfolio can trade and their weights.
63    pub product_group: ProductGroup<ProductId>,
64}