0 Votes

Trading algorithm

Last modified by Sven Moosberger on 2026/08/26 10:24

In each timestep, and for each type of energy, the following trading takes place between Traders:

  • We assume that all the devices belonging to the same Trader can freely exchange energy between themselves. For each Trader, the internal energy exchange between the connected devices takes place, until either all the energy needs (use or charge) are satisfied, or all the energy surplus (production, generation or discharge) is consumed. We will call Traders with unsatisfied needs Buyers, and Traders with an energy surplus Sellers. Each Trader will for this timestep be either a Seller or a Buyer.
    TradingStep1.png
     
  • All the Contracts between non-utility Traders, where either the seller or the buyer has a better Contract with a Utility, are ignored for the purpose of the rest of the algorithm in this timestep.TradingStep2.png
  • All non-utility Traders are divided into groups of Traders in such a way that there are no Contracts between the groups that point in the direction from a seller to a buyer. These groups of Traders form independent markets from here on.
    TradingStep3.png

TradingMarket.png

Example of an independent market in a situation with two non-utility Sellers (traders with energy surplus) and two non-utility Buyers (traders with energy shortage) and their related energy meters.

  • The total power balance of all (non-utility) Traders within each independent market  is calculated. We call a global shortage situation a Seller's market, and a global surplus situation a Buyer's market (numbers in the example are shortages and surpluses of each Trader in kW).
    TradingStep4.png

 

  • In case of a Seller's market, each Selling Trader selects the selling Contract with the highest price available to them. If there is no case of competition between Sellers about selling to the same Buyer (the Contracts may be with the same Utility), all Selling Traders sell as much energy as they can via the selected Contracts. If two or more Selling Traders want to sell to the same Buying Trader (competition case), the trades take place in the order of increasing price. When these rules lead to an ambiguity, i.e., when a Selling Trader has more than one selling Contract with the (same) highest price, or two or more Selling Traders want to sell to the same Buying Trader at the same price, the trades take place as if over all such Contracts (with the same price), energy is transferred with the same power, until either the participating Selling Traders have no energy left to sell, or the participating Buying Traders’ needs are satisfied.
    In case of a Seller’s market, trading starts with the highest rate between two non-utility Traders. This trading happens until the Seller’s energy is sold out or the Buyer’s need is satisfied.
    TradingStep5.png
     
  • The above step is repeated while there are Contracts between non-utility  Traders in action.. Afterwards, all the Buying Traders buy the energy they still need from the most favourable Utility Contract.
    TradingStep6.png
     

Similarly, in case of a Buyer's market, steps 53. and 64. take place with the roles of Buying and Selling Traders reversed.