fts_core/models/portfolio.rs
1use crate::models::Map;
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(feature = "schemars", derive(schemars::JsonSchema))]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct Portfolio<
20 DateTime,
21 BidderId: Eq,
22 PortfolioId: Eq + Hash,
23 DemandId: Eq + Hash,
24 ProductId: Eq + Hash,
25 AppData,
26> {
27 /// Unique identifier for this portfolio instance.
28 /// Generated by the application when creating a new portfolio.
29 pub id: PortfolioId,
30
31 /// Timestamp when this version of the portfolio was created or last updated.
32 /// Used for temporal queries and history tracking.
33 pub as_of: DateTime,
34
35 /// Application-specific data attached to this portfolio.
36 /// This field allows extending the portfolio with custom data without
37 /// modifying the core schema.
38 pub app_data: AppData,
39
40 /// The bidder who owns this portfolio.
41 /// A bidder can have multiple portfolios to organize different trading strategies.
42 pub bidder_id: BidderId,
43
44 /// Map of demands associated with this portfolio and their weights.
45 pub demand_group: Map<DemandId>,
46
47 /// Map of products this portfolio can trade and their weights.
48 pub product_group: Map<ProductId>,
49}