fts_core/models/
demand.rs

1use crate::models::{DemandCurve, Map};
2use std::hash::Hash;
3
4/// Represents a demand entity in the flow trading system.
5///
6/// A demand captures a bidder's interest in acquiring products through the system.
7/// Each demand is owned by a single bidder and can optionally include:
8/// - A demand curve that defines pricing preferences
9/// - A portfolio group that links this demand to one or more portfolios
10#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct Demand<
13    DateTime,
14    BidderId: Eq + Hash,
15    DemandId: Eq + Hash,
16    PortfolioId: Eq + Hash,
17    AppData,
18> {
19    /// Unique identifier for this demand instance.
20    /// Generated by the application when creating a new demand.
21    pub id: DemandId,
22
23    /// Timestamp when this version of the demand was created or last updated.
24    /// Used for temporal queries and history tracking.
25    pub as_of: DateTime,
26
27    /// The bidder who owns this demand.
28    pub bidder_id: BidderId,
29
30    /// Application-specific data attached to this demand.
31    /// This field allows extending the demand with custom data without
32    /// modifying the core schema.
33    pub app_data: AppData,
34
35    /// Optional demand curve defining the bidder's pricing preferences.
36    ///
37    /// When present, this curve is used by the solver to determine optimal
38    /// allocations. Setting this to `None` effectively deletes the demand
39    /// from active consideration while preserving its history.
40    pub curve_data: Option<DemandCurve>,
41
42    /// Map of portfolios associated with this demand and their weights.
43    ///
44    /// The map keys are portfolio IDs and values are weights that determine
45    /// how this demand is distributed across portfolios. An empty map means
46    /// the demand is not yet associated with any portfolios.
47    pub portfolio_group: Map<PortfolioId, f64>,
48}