Ejemplo n.º 1
0
def test_fiat_convert_find_price(mocker):
    fiat_convert = CryptoToFiatConverter()

    fiat_convert._coinlistings = {}
    fiat_convert._backoff = 0
    mocker.patch(
        'freqtrade.rpc.fiat_convert.CryptoToFiatConverter._load_cryptomap',
        return_value=None)
    assert fiat_convert.get_price(crypto_symbol='BTC',
                                  fiat_symbol='EUR') == 0.0

    with pytest.raises(ValueError, match=r'The fiat ABC is not supported.'):
        fiat_convert._find_price(crypto_symbol='BTC', fiat_symbol='ABC')

    assert fiat_convert.get_price(crypto_symbol='XRP',
                                  fiat_symbol='USD') == 0.0

    mocker.patch(
        'freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
        return_value=12345.0)
    assert fiat_convert.get_price(crypto_symbol='BTC',
                                  fiat_symbol='USD') == 12345.0
    assert fiat_convert.get_price(crypto_symbol='btc',
                                  fiat_symbol='usd') == 12345.0

    mocker.patch(
        'freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
        return_value=13000.2)
    assert fiat_convert.get_price(crypto_symbol='BTC',
                                  fiat_symbol='EUR') == 13000.2
def test_fiat_convert_unsupported_crypto(mocker, caplog):
    mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._cryptomap',
                 return_value=[])
    fiat_convert = CryptoToFiatConverter()
    assert fiat_convert._find_price(crypto_symbol='CRYPTO_123',
                                    fiat_symbol='EUR') == 0.0
    assert log_has('unsupported crypto-symbol CRYPTO_123 - returning 0.0',
                   caplog)
Ejemplo n.º 3
0
def test_fiat_convert_without_network(mocker):
    # Because CryptoToFiatConverter is a Singleton we reset the value of _coingekko

    fiat_convert = CryptoToFiatConverter()

    cmc_temp = CryptoToFiatConverter._coingekko
    CryptoToFiatConverter._coingekko = None

    assert fiat_convert._coingekko is None
    assert fiat_convert._find_price(crypto_symbol='btc', fiat_symbol='usd') == 0.0
    CryptoToFiatConverter._coingekko = cmc_temp
Ejemplo n.º 4
0
def test_fiat_convert_without_network(mocker):
    # Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap

    fiat_convert = CryptoToFiatConverter()

    cmc_temp = CryptoToFiatConverter._coinmarketcap
    CryptoToFiatConverter._coinmarketcap = None

    assert fiat_convert._coinmarketcap is None
    assert fiat_convert._find_price(crypto_symbol='BTC',
                                    fiat_symbol='USD') == 0.0
    CryptoToFiatConverter._coinmarketcap = cmc_temp
Ejemplo n.º 5
0
def test_fiat_convert_find_price(mocker):
    patch_coinmarketcap(mocker)

    fiat_convert = CryptoToFiatConverter()

    with pytest.raises(ValueError, match=r'The fiat ABC is not supported.'):
        fiat_convert._find_price(crypto_symbol='BTC', fiat_symbol='ABC')

    assert fiat_convert.get_price(crypto_symbol='XRP',
                                  fiat_symbol='USD') == 0.0

    mocker.patch(
        'freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
        return_value=12345.0)
    assert fiat_convert.get_price(crypto_symbol='BTC',
                                  fiat_symbol='USD') == 12345.0
    assert fiat_convert.get_price(crypto_symbol='btc',
                                  fiat_symbol='usd') == 12345.0

    mocker.patch(
        'freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
        return_value=13000.2)
    assert fiat_convert.get_price(crypto_symbol='BTC',
                                  fiat_symbol='EUR') == 13000.2