def test_calculate_exchange_rate_by_inference(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {
            "USD/JPY": Decimal("110.100"),
            "AUD/USD": Decimal("0.80000"),
        }
        ask_rates = {
            "USD/JPY": Decimal("110.130"),
            "AUD/USD": Decimal("0.80010"),
        }

        # Act
        result1 = converter.get_rate(
            JPY,
            AUD,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )

        result2 = converter.get_rate(
            AUD,
            JPY,
            PriceType.ASK,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert Decimal("0.01135331516802906448683015441") == pytest.approx(
            result1)  # JPYAUD
        assert Decimal("88.11501299999999999999999997") == pytest.approx(
            result2)  # AUDJPY
    def test_get_rate_when_price_type_last_raises_value_error(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"AUD/USD": Decimal("0.80000")}
        ask_rates = {"AUD/USD": Decimal("0.80010")}

        # Act, Assert
        with pytest.raises(ValueError):
            converter.get_rate(USD, JPY, PriceType.LAST, bid_rates, ask_rates)
    def test_get_rate(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"AUD/USD": Decimal("0.80000")}
        ask_rates = {"AUD/USD": Decimal("0.80010")}

        # Act
        result = converter.get_rate(
            AUD,
            USD,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert result == Decimal("0.80000")
    def test_get_rate_when_no_currency_rate_returns_zero(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"AUD/USD": Decimal("0.80000")}
        ask_rates = {"AUD/USD": Decimal("0.80010")}

        # Act
        result = converter.get_rate(
            USD,
            JPY,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert result == 0
    def test_calculate_exchange_rate_for_mid_price_type2(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"USD/JPY": Decimal("110.100")}
        ask_rates = {"USD/JPY": Decimal("110.130")}

        # Act
        result = converter.get_rate(
            USD,
            JPY,
            PriceType.MID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert result == Decimal("110.115")
    def test_calculate_exchange_rate_for_mid_price_type(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"USD/JPY": Decimal("110.100")}
        ask_rates = {"USD/JPY": Decimal("110.130")}

        # Act
        result = converter.get_rate(
            JPY,
            USD,
            PriceType.MID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert result == Decimal("0.009081414884438995595513781047")
    def test_get_rate_for_inverse2(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"USD/JPY": Decimal("110.100")}
        ask_rates = {"USD/JPY": Decimal("110.130")}

        # Act
        result = converter.get_rate(
            JPY,
            USD,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert Decimal("0.009082652") == pytest.approx(result)
    def test_get_rate_for_inverse1(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"BTC/USD": Decimal("10501.5")}
        ask_rates = {"BTC/USD": Decimal("10500.0")}

        # Act
        result = converter.get_rate(
            USD,
            BTC,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )

        # Assert
        assert result == Decimal("0.00009522449173927534161786411465")
 def get_xrate(bid_quotes, ask_quotes):
     ExchangeRateCalculator().get_rate(
         from_currency=ETH,
         to_currency=USDT,
         price_type=PriceType.MID,
         bid_quotes=bid_quotes,
         ask_quotes=ask_quotes,
     )