def bid(self, id: int, price: Wad) -> Tuple[Optional[Wad], Optional[Transact], Optional[Rad]]: assert isinstance(id, int) assert isinstance(price, Wad) bid = self.flipper.bids(id) # dent phase if bid.bid == bid.tab: our_lot = Wad(bid.bid / Rad(price)) if our_lot < self.min_lot: return None, None, None if (our_lot * self.beg <= bid.lot) and (our_lot < bid.lot): return price, self.flipper.dent(id, our_lot, bid.bid), bid.bid else: return None, None, None # tend phase else: if bid.lot < self.min_lot: return None, None, None our_bid = Rad.min(Rad(bid.lot) * price, bid.tab) our_price = price if our_bid < bid.tab else bid.bid / Rad(bid.lot) if (our_bid >= bid.bid * self.beg or our_bid == bid.tab) and our_bid > bid.bid: return our_price, self.flipper.tend(id, bid.lot, our_bid), our_bid else: return None, None, None
def bid(self, id: int, price: Wad) -> Tuple[Optional[Wad], Optional[Transact], Optional[Rad]]: assert isinstance(id, int) assert isinstance(price, Wad) bid = self.flipper.bids(id) # dent phase if bid.bid == bid.tab: our_lot = Wad(bid.bid / Rad(price)) if our_lot < self.min_lot: self.logger.debug(f"dent lot {our_lot} less than minimum {self.min_lot}") return None, None, None if (our_lot * self.beg <= bid.lot) and (our_lot < bid.lot): return price, self.flipper.dent(id, our_lot, bid.bid), bid.bid else: self.logger.debug(f"dent lot {our_lot} would not exceed the bid increment") return None, None, None # tend phase else: if bid.lot < self.min_lot: self.logger.debug(f"tend lot {bid.lot} less than minimum {self.min_lot}") return None, None, None our_bid = Rad.min(Rad(bid.lot) * price, bid.tab) our_price = price if our_bid < bid.tab else bid.bid / Rad(bid.lot) if (our_bid >= bid.bid * self.beg or our_bid == bid.tab) and our_bid > bid.bid: return our_price, self.flipper.tend(id, bid.lot, our_bid), our_bid else: self.logger.debug(f"tend bid {our_bid} would not exceed the bid increment") return None, None, None
def test_min_value_should_reject_comparison_with_ints(self): with pytest.raises(ArithmeticError): Rad.min(Rad(10), 20) with pytest.raises(ArithmeticError): Rad.min(20, Rad(10))
def test_min_value_should_reject_comparison_with_rays(self): with pytest.raises(ArithmeticError): Rad.min(Rad(10), Ray(20)) with pytest.raises(ArithmeticError): Rad.min(Ray(25), Rad(15))
def test_min_value(self): assert Rad.min(Rad(10), Rad(20)) == Rad(10) assert Rad.min(Rad(25), Rad(15)) == Rad(15) assert Rad.min(Rad(25), Rad(15), Rad(5)) == Rad(5)