code: def ensure_crypto_benchmark_data(
      symbol,
      first_date,
      last_date,
      now,
      trading_day,
      bundle,
      bundle_data,
      environ=None,
  ):
      filename = get_benchmark_filename(symbol)
  
      logger.info(
          (
              "Loading benchmark data for {symbol!r} "
              "from {first_date} to {last_date}"
          ),
          symbol=symbol,
          first_date=first_date,
          last_date=last_date,
      )
  
      data = _load_cached_data(
          filename,
          first_date,
          last_date,
          now,
          "benchmark",
          environ,
      )
  
      if data is not None:
          return data
  
      # If no cached data was found or it was missing any dates then download the
      # necessary data.
  
      if bundle == "poloniex":
          """
          If we're using the Poloniex bundle, we'll get the benchmark from the
          bundle instead of downloading it from Poloniex every time we need it.
          Poloniex has a captcha for API queries originating from outside the US
          that prevents users abroad from getting Catalyst to work
          """
          logger.info(
              (
                  "Retrieving benchmark data from bundle for {symbol!r}"
                  " from {first_date} to {last_date}"
              ),
              symbol=symbol,
              first_date=first_date,
              last_date=last_date,
          )
  
          asset = bundle_data.asset_finder.lookup_symbol(
              symbol=symbol, as_of_date=None
          )
          fields = ["day", "close"]
          raw = bundle_data.daily_bar_reader.load_raw_arrays(
              columns=fields,
              start_date=first_date - trading_day,
              end_date=last_date,
              assets=[
                  asset,
              ],
          )
          bench_raw = pd.concat(
              [
                  pd.DataFrame(raw[0], columns=["date"]),
                  pd.DataFrame(raw[1], columns=["close"]),
              ],
              axis=1,
          )
          bench_raw["date"] = pd.to_datetime(
              bench_raw["date"], unit="s"
          )
          bench_raw.set_index("date", inplace=True)
          bench_raw.sort_index(inplace=True)
          bench_raw = bench_raw[
              pd.to_datetime(first_date - trading_day) : pd.to_datetime(
                  last_date
              )
          ]
  
      else:
          # This is how it used to be: downloading the benchmark everytime.
          # Leaving this code here to be repurposed in the future for
          # other bundles.
          logger.info(
              (
                  "Downloading benchmark data for {symbol!r}"
                  " from {first_date} to {last_date}"
              ),
              symbol=symbol,
              first_date=first_date,
              last_date=last_date,
          )
  
          raise DeprecationWarning("poloniex bundle deprecated")
          # Load benchmark symbol from Poloniex API
          # try:
          #     bundle = PoloniexBundle()
          #     bench_raw = bundle._fetch_symbol_frame(
          #         None,
          #         symbol,
          #         get_calendar(bundle.calendar_name),
          #         first_date - trading_day,
          #         last_date,
          #         'daily',
          #     )
          # except (OSError, IOError, HTTPError):
          #     logger.exception('Failed to fetch new crypto benchmark returns')
          #     raise
  
      # select close column and compute percent change between days
      daily_close = bench_raw[["close"]]
      daily_close = daily_close.pct_change(1).iloc[1:]
  
      try:
          # write to benchmark csv cache
          daily_close.to_csv(get_data_filepath(filename, environ))
      except (OSError, IOError, HTTPError):
          logger.exception("Failed to cache the new benchmark returns")
          raise
  
      if not has_data_for_dates(daily_close, first_date, last_date):
          logger.warn(
              "Still don't have expected data after redownload!"
          )
  
      return daily_close
  
imports: import os
  from collections import OrderedDict
  import logbook
  import pandas
  import pytz
  from pandas_datareader.data import DataReader
  from six import iteritems
  from six.moves.urllib_error import HTTPError
  from catalyst.constants import LOG_LEVEL
  from catalyst.utils.calendars import get_calendar
  from .None import treasuries, treasuries_can
  from .benchmarks import get_benchmark_returns
  from ..utils.deprecate import deprecated
  from ..utils.paths import cache_root, data_root
label_desc: Use image node_id 8 for calling a global function with example usage: ensure_crypto_benchmark_data(symbol, first_date, last_date, now, trading_day, bundle, bundle_data, environ) and returns: daily_close, data