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(
11 feature = "schemars",
12 derive(schemars::JsonSchema),
13 schemars(rename = "DemandRecord")
14)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct DemandRecord<
17 DateTime,
18 BidderId: Eq + Hash,
19 DemandId: Eq + Hash,
20 PortfolioId: Eq + Hash,
21 AppData,
22> {
23 /// Unique identifier for this demand instance.
24 /// Generated by the application when creating a new demand.
25 pub id: DemandId,
26
27 /// Timestamp when this version of the demand was created or last updated.
28 /// Used for temporal queries and history tracking.
29 pub as_of: DateTime,
30
31 /// The bidder who owns this demand.
32 pub bidder_id: BidderId,
33
34 /// Application-specific data attached to this demand.
35 /// This field allows extending the demand with custom data without
36 /// modifying the core schema.
37 pub app_data: AppData,
38
39 /// Optional demand curve defining the bidder's pricing preferences.
40 ///
41 /// When present, this curve is used by the solver to determine optimal
42 /// allocations. Setting this to `None` effectively deletes the demand
43 /// from active consideration while preserving its history.
44 pub curve_data: Option<DemandCurve>,
45
46 /// Map of portfolios associated with this demand and their weights.
47 ///
48 /// The map keys are portfolio IDs and values are weights that determine
49 /// how this demand is distributed across portfolios. An empty map means
50 /// the demand is not yet associated with any portfolios.
51 pub portfolio_group: Map<PortfolioId, f64>,
52}