Example #1
0
def create_inquirer(
    data_directory,
    should_mock_current_price_queries,
    mocked_prices,
    current_price_oracles_order,
) -> Inquirer:
    # Since this is a singleton and we want it initialized everytime the fixture
    # is called make sure its instance is always starting from scratch
    Inquirer._Inquirer__instance = None  # type: ignore
    # Get a cryptocompare without a DB since invoking DB fixture here causes problems
    # of existing user for some tests
    cryptocompare = Cryptocompare(data_directory=data_directory, database=None)
    gecko = Coingecko(data_directory=data_directory)
    inquirer = Inquirer(
        data_dir=data_directory,
        cryptocompare=cryptocompare,
        coingecko=gecko,
    )
    inquirer.set_oracles_order(current_price_oracles_order)

    if not should_mock_current_price_queries:
        return inquirer

    def mock_find_price(
            from_asset,
            to_asset,
            ignore_cache: bool = False,  # pylint: disable=unused-argument
    ):
        return mocked_prices.get((from_asset, to_asset), FVal('1.5'))

    inquirer.find_price = mock_find_price  # type: ignore

    def mock_find_usd_price(asset, ignore_cache: bool = False):  # pylint: disable=unused-argument
        return mocked_prices.get(asset, FVal('1.5'))

    inquirer.find_usd_price = mock_find_usd_price  # type: ignore

    def mock_query_fiat_pair(base, quote):  # pylint: disable=unused-argument
        return FVal(1)

    inquirer._query_fiat_pair = mock_query_fiat_pair  # type: ignore

    return inquirer
Example #2
0
def create_inquirer(
    data_directory,
    should_mock_current_price_queries,
    mocked_prices,
    current_price_oracles_order,
    ethereum_manager,
    ignore_mocked_prices_for=None,
) -> Inquirer:
    # Since this is a singleton and we want it initialized everytime the fixture
    # is called make sure its instance is always starting from scratch
    Inquirer._Inquirer__instance = None  # type: ignore
    # Get a cryptocompare without a DB since invoking DB fixture here causes problems
    # of existing user for some tests
    cryptocompare = Cryptocompare(data_directory=data_directory, database=None)
    gecko = Coingecko()
    inquirer = Inquirer(
        data_dir=data_directory,
        cryptocompare=cryptocompare,
        coingecko=gecko,
    )
    if ethereum_manager is not None:
        inquirer.inject_ethereum(ethereum_manager)
        uniswap_v2_oracle = UniswapV2Oracle(ethereum_manager)
        uniswap_v3_oracle = UniswapV3Oracle(ethereum_manager)
        saddle_oracle = SaddleOracle(ethereum_manager)
        Inquirer().add_defi_oracles(
            uniswap_v2=uniswap_v2_oracle,
            uniswap_v3=uniswap_v3_oracle,
            saddle=saddle_oracle,
        )
    inquirer.set_oracles_order(current_price_oracles_order)

    if not should_mock_current_price_queries:
        return inquirer

    def mock_find_price(
            from_asset,
            to_asset,
            ignore_cache: bool = False,  # pylint: disable=unused-argument
    ):
        return mocked_prices.get((from_asset, to_asset), FVal('1.5'))

    def mock_find_usd_price(asset, ignore_cache: bool = False):  # pylint: disable=unused-argument
        return mocked_prices.get(asset, FVal('1.5'))

    if ignore_mocked_prices_for is None:
        inquirer.find_price = mock_find_price  # type: ignore
        inquirer.find_usd_price = mock_find_usd_price  # type: ignore
    else:

        def mock_some_prices(from_asset, to_asset, ignore_cache=False):
            if from_asset.symbol in ignore_mocked_prices_for:
                return inquirer.find_price_old(from_asset, to_asset,
                                               ignore_cache)
            return mock_find_price(from_asset, to_asset, ignore_cache)

        def mock_some_usd_prices(asset, ignore_cache=False):
            if asset.symbol in ignore_mocked_prices_for:
                return inquirer.find_usd_price_old(asset, ignore_cache)
            return mock_find_usd_price(asset, ignore_cache)

        inquirer.find_price_old = inquirer.find_price  # type: ignore
        inquirer.find_usd_price_old = inquirer.find_usd_price  # type: ignore
        inquirer.find_price = mock_some_prices  # type: ignore
        inquirer.find_usd_price = mock_some_usd_prices  # type: ignore

    def mock_query_fiat_pair(base, quote):  # pylint: disable=unused-argument
        return FVal(1)

    inquirer._query_fiat_pair = mock_query_fiat_pair  # type: ignore

    return inquirer