UFTP
UFTP 3.1 (Shapeshifter) in Rust: FlexRequests as deviation envelopes, orders as deviations, FlexOrderSettlement items, and checking a received one.
UFTP 3.1, the USEF Flex Trading Protocol (maintained by LF Energy as Shapeshifter), is how a DSO buys flexibility from an aggregator: a FlexRequest (the space the DSO needs), a FlexOffer (what the aggregator offers), a FlexOrder (what the DSO buys) and, monthly, a FlexSettlement with one FlexOrderSettlement per order.
The uftp feature maps all four to this crate's shapes using the uftp crate, re-exported as flexibility::uftp::wire.
flexibility = { version = "0.4", features = ["uftp"] }The default build does not depend on uftp; the protocols overview has the rules every converter keeps.
Sign#
UFTP's power sign is this crate's (§ 4.2.1: positive is consumption), so MinPower, MaxPower, ISP Power, BaselinePower, ActualPower and OrderedFlexPower map without change.
DeliveredFlexPower and PowerDeficiency are the exception: the specification does not sign them, and its § 2.6.2 table prints magnitudes. The uftp crate documents them with the sign of OrderedFlexPower. So every function that writes or checks them takes a required FlexSign, and none assumes one:
FlexSign | 300 kW ordered down, 280 kW delivered: delivered, deficiency |
|---|---|
Magnitude | 280000, 20000 (as the § 2.6.2 table prints them) |
AsOrdered | -280000, -20000 (as the uftp crate documents them) |
For an upward order both readings agree, so a test written only for increases passes either. Agree on one in the contract.
Does this offer fit the request?#
uftp::request(&request) gives a DeviationEnvelope on the request's day: per ISP a Band (min and max deviation, and Requested, Available or Unstated when the message has no Disposition — the XSD has no default). uftp::profile reads an offer option's or an order's ISP elements as a deviation per ISP, from the first to the last ISP named, None in an ISP between them that none names.
let env = uftp::request(&request)?;
let offered = uftp::profile(&offer.header, &offer.options[0].isps)?;
for misfit in env.check(&offered)? {
println!("{misfit}");
}
// ISP 70 (17:15–17:30 +01:00): offered -200 kW outside -500 kW to -300 kW (requested) set by dso.example 0505…
// ISP 71 (17:30–17:45 +01:00): not offered, outside -500 kW to -300 kW (requested) set by dso.example 0505…The uftp crate checks references, parties and expiry; this check is about the powers.
The ordered deviation#
A partially activated order keeps the offer's ISP list unchanged (§ 4.2.24: "AGR implementations will (and must) reject FlexOrder messages where the ISP list is not exactly the same as offered"), and OrderedFlexPower is the ISP power × ActivationFactor. uftp::ordered(&order, rounding) computes that in integers and rounds once, as you name it:
let ordered = uftp::ordered(&order, Rounding::Exact)?; // -300 kW × 0.50 = -150 kW per ISPRounding::Exact refuses a fraction of a watt (−333 W × 0.50); HalfAwayFromZero gives −167 W.
Building the settlement item#
let ours = settle(&base, &actual, &ordered, MeasurementPoint::ConnectionPoint)?;
let item = uftp::settlement(&order, &ours, FlexSign::AsOrdered)?;The item copies the order's references, and its price × ActivationFactor (the activation factor is applied once, at settlement, as the uftp crate reads the specification). It has one ISP element per settled ISP the order covers. It is refused, with Error::Mismatch, if the settlement is on another day, zone or ISP length, or if the order names another baseline method: in BaselineReference (read with uftp::method_of as a plain method id such as xofy@1; UFTP defines no syntax for parameters) or by naming a D-Prognosis (the aggregator's forecast, used as dprognosis@1) for another method. When the order names neither, the item's BaselineReference is the method id.
The aggregator's uftp check (FlexSettlement::check_against) accepts every item built this way; a property test holds it.
Checking a received settlement#
| Function | Compares | Needs |
|---|---|---|
uftp::check(&item, sign) | each ISP's DeliveredFlexPower and PowerDeficiency against the rule applied to the item's own BaselinePower, OrderedFlexPower and ActualPower | the message alone |
uftp::compare(&item, &ours, sign) | all five fields of every ISP against your own Settlement, plus ISPs on one side only | your settlement |
Both expand ISP spans, report an ISP addressed twice, and return every Discrepancy in ISP order; an empty vector means the message is consistent. A message whose spans expand to more than MAX_ISPS is refused.
assert_eq!(uftp::check(&item, FlexSign::AsOrdered)?, []);
// A DSO that forgot the deficiency in ISP 73:
wrong.isps[4].power_deficiency = 0;
for d in uftp::check(&wrong, FlexSign::AsOrdered)? {
println!("{d}"); // ISP 73: PowerDeficiency sent 0 W, expected -50 kW
}The full program is examples/check_a_settlement.rs: cargo run --features uftp --example check_a_settlement.