Skip to content

Commit

Permalink
Merge pull request #1134 from gridsingularity/staging_to_dev_backport…
Browse files Browse the repository at this point in the history
…_06052021

Staging to dev backport 06052021
  • Loading branch information
spyrostz authored May 6, 2021
2 parents 73f1da7 + 65d4d29 commit d6258a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/d3a/models/market/one_sided.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Union # noqa
from logging import getLogger
from pendulum import DateTime
from math import isclose

from d3a.events.event_structures import MarketEvent
from d3a.models.market.market_structures import Offer, Trade
Expand Down Expand Up @@ -215,7 +216,7 @@ def accept_offer(self, offer_or_id: Union[str, Offer], buyer: str, *, energy: in
if offer is None:
raise OfferNotFoundException()

if energy is None:
if energy is None or isclose(energy, offer.energy, abs_tol=1e-8):
energy = offer.energy

original_offer = offer
Expand Down Expand Up @@ -246,7 +247,8 @@ def accept_offer(self, offer_or_id: Union[str, Offer], buyer: str, *, energy: in
offer.update_price(trade_price)

elif energy > offer.energy:
raise InvalidTrade("Energy can't be greater than offered energy")
raise InvalidTrade(f"Energy ({energy}) can't be greater than "
f"offered energy ({offer.energy})")
else:
# Requested energy is equal to offer's energy - just proceed normally
fee_price, trade_price = self.determine_offer_price(
Expand Down

0 comments on commit d6258a5

Please sign in to comment.