fts_core/ports/batch.rs
1use crate::models::{DateTimeRangeQuery, DateTimeRangeResponse, OutcomeRecord};
2
3/// Repository interface for batch auction execution and outcome retrieval.
4///
5/// This trait provides methods for running batch auctions at specific timestamps
6/// and retrieving the resulting allocations and prices.
7pub trait BatchRepository<T: super::Solver<Self::DemandId, Self::PortfolioId, Self::ProductId>>:
8 super::Repository
9{
10 /// Execute a batch auction for a specific timestamp.
11 ///
12 /// Gather all the portfolios and demand curves for the requested time
13 /// and solve the corresponding auction using `solver`.
14 ///
15 /// # Returns
16 ///
17 /// - Ok(Ok(())) if the batch completed successfully
18 /// - Ok(Err(solver_error)) if the solver failed
19 /// - Err(repository_error) if there is some other error
20 fn run_batch(
21 &self,
22 timestamp: Self::DateTime,
23 solver: T,
24 state: T::State,
25 ) -> impl Future<Output = Result<Result<(), T::Error>, Self::Error>> + Send;
26
27 /// Retrieve historical batch outcomes for a portfolio.
28 ///
29 /// # Returns
30 ///
31 /// A paginated response containing the portfolio's allocations from past batches.
32 fn get_portfolio_outcomes(
33 &self,
34 portfolio_id: Self::PortfolioId,
35 query: DateTimeRangeQuery<Self::DateTime>,
36 limit: usize,
37 ) -> impl Future<
38 Output = Result<
39 DateTimeRangeResponse<
40 OutcomeRecord<Self::DateTime, T::PortfolioOutcome>,
41 Self::DateTime,
42 >,
43 Self::Error,
44 >,
45 > + Send;
46
47 /// Retrieve historical batch outcomes for a product.
48 ///
49 /// # Returns
50 ///
51 /// A paginated response containing the product's clearing prices from past batches.
52 fn get_product_outcomes(
53 &self,
54 product_id: Self::ProductId,
55 query: DateTimeRangeQuery<Self::DateTime>,
56 limit: usize,
57 ) -> impl Future<
58 Output = Result<
59 DateTimeRangeResponse<OutcomeRecord<Self::DateTime, T::ProductOutcome>, Self::DateTime>,
60 Self::Error,
61 >,
62 > + Send;
63}