Class OrderBook

  • All Implemented Interfaces:
    de.dlr.gitlab.fame.communication.transfer.Portable
    Direct Known Subclasses:
    DemandOrderBook, SupplyOrderBook

    public abstract class OrderBook
    extends Object
    implements de.dlr.gitlab.fame.communication.transfer.Portable
    Handles a list of bids or asks at an energy DayAheadMarket for a single time frame of trading
    Author:
    Martin Klein, Christoph Schimeczek, A. Achraf El Ghazi
    • Field Detail

      • awardedPrice

        protected double awardedPrice
        market clearing price
      • awardedCumulativePower

        protected double awardedCumulativePower
        total power awarded to both supply and demand
      • isSorted

        protected boolean isSorted
        tells if this OrderBook has been yet finalised and sorted
    • Constructor Detail

      • OrderBook

        public OrderBook()
        required for Portables
    • Method Detail

      • addBid

        public void addBid​(Bid bid,
                           long traderUuid)
        Adds given Bid to this OrderBook; the OrderBook must not be sorted yet
        Parameters:
        bid - to be added to the unsorted OrderBook
        traderUuid - id of the trader associated with the bids
      • ensureNotYetSortedOrThrow

        protected void ensureNotYetSortedOrThrow​(String exceptionMessage)
        Ensures the OrderBook items are not yet sorted
        Parameters:
        exceptionMessage - message of the thrown exception (if any)
        Throws:
        RuntimeException - if items are already sorted
      • ensureSortedOrThrow

        protected void ensureSortedOrThrow​(String exceptionMessage)
        Ensures the OrderBook items are already sorted
        Parameters:
        exceptionMessage - message of the thrown exception (if any)
        Throws:
        RuntimeException - if items are not yet sorted
      • ensurePositiveBidPower

        protected void ensurePositiveBidPower()
        Ensures the OrderBook's items have non-negative block power.
        Throws:
        RuntimeException - if bid's block power is negative
      • addBids

        public void addBids​(List<Bid> bids,
                            long traderUuid)
        Adds multiple Bids to this OrderBook; the OrderBook must not be sorted yet
        Parameters:
        bids - to add to this unsorted OrderBook
        traderUuid - id of the trader associated with the bids
      • getOrderBookItems

        public ArrayList<OrderBookItem> getOrderBookItems()
        Returns:
        a list of items, which are sorted and have assigned cumulated power values
      • getLastBid

        protected abstract Bid getLastBid()
        Returns:
        the last virtual Bid depending on the type of order book
      • updateAwardedPowerInBids

        public void updateAwardedPowerInBids​(double totalAwardedPower,
                                             double awardedPrice,
                                             OrderBook.DistributionMethod method)
        Updates awarded powers of all contained OrderBookItems, based on the given parameters
        Parameters:
        totalAwardedPower - obtained at market clearing - after this call: equals to sum of all OrderBookItem's awarded power
        awardedPrice - uniform market clearing price
        method - determines, how power is distributed among multiple price-setting bids
      • filterForBidsByTrader

        public ArrayList<OrderBookItem> filterForBidsByTrader​(long traderID)
        Returns list of OrderBookItems that belong to the specified trader
        Parameters:
        traderID - to look for
        Returns:
        list of Items that associated with specified trader
      • addComponentsTo

        public void addComponentsTo​(de.dlr.gitlab.fame.communication.transfer.ComponentCollector collector)
        required for Portables
        Specified by:
        addComponentsTo in interface de.dlr.gitlab.fame.communication.transfer.Portable
      • populate

        public void populate​(de.dlr.gitlab.fame.communication.transfer.ComponentProvider provider)
        required for Portables
        Specified by:
        populate in interface de.dlr.gitlab.fame.communication.transfer.Portable
      • getTradersSumOfPower

        public double getTradersSumOfPower​(long traderUuid)
        Return sum of power across all bids in this OrderBook for given trader
        Parameters:
        traderUuid - UUID of trader to sum up awarded power
        Returns:
        awarded power of given trader
      • getCumulatePowerOfItems

        public double getCumulatePowerOfItems()
        Returns:
        sum of power value of orderBookItems
      • hasNoValidBids

        public boolean hasNoValidBids()
        Checks if this OrderBook contains no bids with power; this closes the order book - no further calls to addBid(Bid, long) or addBids(List, long) are allowed afterwards
        Returns:
        true if no bids with power are contained