Example #1
0
    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
        self.assertEqual(0, result)
Example #2
0
    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
        self.assertEqual(Decimal("0.009081414884438995595513781047"), result)
Example #3
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
        self.assertEqual(Decimal("110.115"), result)
Example #4
0
    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
        self.assertAlmostEqual(Decimal("0.009082652"), result)
    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
        self.assertEqual(Decimal("0.80000"), 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
        self.assertEqual(Decimal("0.00009522449173927534161786411465"), result)
Example #7
0
    def test_calculate_exchange_rate_for_inverse(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"USDJPY": 110.100}
        ask_rates = {"USDJPY": 110.130}

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

        # Assert
        self.assertEqual(0.009082652134423252, result)
    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
        self.assertAlmostEqual(
            Decimal("0.01135331516802906448683015441"), result1
        )  # JPYAUD
        self.assertAlmostEqual(
            Decimal("88.11501299999999999999999997"), 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
        self.assertRaises(
            ValueError,
            converter.get_rate,
            USD,
            JPY,
            PriceType.LAST,
            bid_rates,
            ask_rates,
        )
Example #10
0
    def test_get_rate_when_no_currency_rate_raises(self):
        # Arrange
        converter = ExchangeRateCalculator()
        bid_rates = {"AUDUSD": 0.80000}
        ask_rates = {"AUDUSD": 0.80010}

        # Act
        # Assert
        self.assertRaises(
            ValueError,
            converter.get_rate,
            USD,
            JPY,
            PriceType.BID,
            bid_rates,
            ask_rates,
        )
    def get_xrate():
        bid_quotes = {
            'BTC/USD': Decimal("11291.38"),
            'ETH/USDT': Decimal("371.90"),
            'XBT/USD': Decimal("11285.50"),
        }

        ask_quotes = {
            'BTC/USD': Decimal("11292.58"),
            'ETH/USDT': Decimal("372.11"),
            'XBT/USD': Decimal("11286.0"),
        }

        ExchangeRateCalculator().get_rate(
            from_currency=ETH,
            to_currency=USDT,
            price_type=PriceType.MID,
            bid_quotes=bid_quotes,
            ask_quotes=ask_quotes,
        )