Example #1
0
 def update_forwarded_offer_trade_original_info(self, trade_original_info,
                                                market_offer):
     if not trade_original_info:
         return None
     original_bid_rate, bid_rate, trade_rate_source = trade_original_info
     trade_bid_info = TradeBidInfo(
         original_bid_rate=original_bid_rate,
         propagated_bid_rate=bid_rate,
         original_offer_rate=market_offer.original_offer_price /
         market_offer.energy,
         propagated_offer_rate=market_offer.energy_rate,
         trade_rate=trade_rate_source)
     return trade_bid_info
    def match_offers_bids(self):
        if not (self.current_tick_in_slot + 1) % int(
                self.mcp_update_point) == 0:
            return

        clearing = self._perform_pay_as_clear_matching()

        if clearing is None:
            return

        clearing_rate, clearing_energy = clearing
        if clearing_energy > 0:
            log.info(f"Market Clearing Rate: {clearing_rate} "
                     f"||| Clearing Energy: {clearing_energy} "
                     f"||| Clearing Market {self.name}")
            self.state.clearing[self.now] = (clearing_rate, clearing_energy)

        matchings = self._create_bid_offer_matchings(clearing_energy,
                                                     self.sorted_offers,
                                                     self.sorted_bids)

        for index, match in enumerate(matchings):
            offer = match.offer
            bid = match.bid

            assert math.isclose(match.offer_energy, match.bid_energy)

            selected_energy = match.offer_energy
            original_bid_rate = bid.original_bid_price / bid.energy
            propagated_bid_rate = bid.energy_rate
            offer_original_rate = offer.original_offer_price / offer.energy
            offer_propagated_rate = offer.energy_rate

            trade_rate_original = self.fee_class.calculate_original_trade_rate_from_clearing_rate(
                original_bid_rate, propagated_bid_rate, clearing_rate)

            trade_bid_info = TradeBidInfo(
                original_bid_rate=original_bid_rate,
                propagated_bid_rate=propagated_bid_rate,
                original_offer_rate=offer_original_rate,
                propagated_offer_rate=offer_propagated_rate,
                trade_rate=trade_rate_original)

            bid_trade, trade = self.accept_bid_offer_pair(
                bid, offer, clearing_rate, trade_bid_info, selected_energy)

            if trade.residual is not None or bid_trade.residual is not None:
                matchings = self._replace_offers_bids_with_residual_in_matching_list(
                    matchings, index + 1, trade, bid_trade)
    def match_offers_bids(self):
        while len(self._perform_pay_as_bid_matching()) > 0:
            for bid, offer in self._perform_pay_as_bid_matching():
                selected_energy = bid.energy if bid.energy < offer.energy else offer.energy
                original_bid_rate = bid.original_bid_price / bid.energy
                matched_rate = bid.energy_rate

                trade_bid_info = TradeBidInfo(
                    original_bid_rate=original_bid_rate,
                    propagated_bid_rate=bid.price/bid.energy,
                    original_offer_rate=offer.original_offer_price/offer.energy,
                    propagated_offer_rate=offer.price/offer.energy,
                    trade_rate=original_bid_rate)

                self.accept_bid_offer_pair(bid, offer, matched_rate,
                                           trade_bid_info, selected_energy)
Example #4
0
    def match_offers_bids(self):
        # TODO: Please reintegrate when merging this PR
        #  https://github.com/gridsingularity/d3a/pull/584
        # while len(self._perform_pay_as_bid_matching()) > 0:
        for bid, offer in self._perform_pay_as_bid_matching():
            selected_energy = bid.energy if bid.energy < offer.energy else offer.energy
            original_bid_rate = bid.original_bid_price / bid.energy
            matched_rate = bid.price / bid.energy

            trade_bid_info = TradeBidInfo(
                original_bid_rate=original_bid_rate,
                propagated_bid_rate=bid.price / bid.energy,
                original_offer_rate=offer.original_offer_price / offer.energy,
                propagated_offer_rate=offer.price / offer.energy,
                trade_rate=original_bid_rate)
            self.accept_bid_offer_pair(bid, offer, matched_rate,
                                       trade_bid_info, selected_energy)