code: def get_market_data(
      model, market_specs, group, lookback_period, intraday_data=False
  ):
      r"""Get data from an external feed.
  
      Parameters
      ----------
      model : alphapy.Model
          The model object describing the data.
      market_specs : dict
          The specifications for controlling the MarketFlow pipeline.
      group : alphapy.Group
          The group of symbols.
      lookback_period : int
          The number of periods of data to retrieve.
      intraday_data : bool
          If True, then get intraday data.
  
      Returns
      -------
      n_periods : int
          The maximum number of periods actually retrieved.
  
      """
  
      # Unpack market specifications
  
      data_fractal = market_specs["data_fractal"]
      subschema = market_specs["subschema"]
  
      # Unpack model specifications
  
      directory = model.specs["directory"]
      extension = model.specs["extension"]
      separator = model.specs["separator"]
  
      # Unpack group elements
  
      gspace = group.space
      schema = gspace.schema
      fractal = gspace.fractal
  
      # Determine the feed source
  
      if intraday_data:
          # intraday data (date and time)
          logger.info(
              "%s Intraday Data [%s] for %d periods",
              schema,
              data_fractal,
              lookback_period,
          )
          index_column = "datetime"
      else:
          # daily data or higher (date only)
          logger.info(
              "%s Daily Data [%s] for %d periods",
              schema,
              data_fractal,
              lookback_period,
          )
          index_column = "date"
  
      # Get the data from the relevant feed
  
      data_dir = SSEP.join([directory, "data"])
      n_periods = 0
      resample_data = True if fractal != data_fractal else False
  
      # Date Arithmetic
  
      to_date = pd.to_datetime("today")
      from_date = to_date - pd.to_timedelta(lookback_period, unit="d")
      to_date = to_date.strftime("%Y-%m-%d")
      from_date = from_date.strftime("%Y-%m-%d")
  
      # Get the data from the specified data feed
  
      df = pd.DataFrame()
      for symbol in group.members:
          logger.info(
              "Getting %s data from %s to %s",
              symbol.upper(),
              from_date,
              to_date,
          )
          # Locate the data source
          if schema == "data":
              # local intraday or daily
              dspace = Space(
                  gspace.subject, gspace.schema, data_fractal
              )
              fname = frame_name(symbol.lower(), dspace)
              df = read_frame(data_dir, fname, extension, separator)
          elif schema in data_dispatch_table.keys():
              df = data_dispatch_table[schema](
                  schema,
                  subschema,
                  symbol,
                  intraday_data,
                  data_fractal,
                  from_date,
                  to_date,
                  lookback_period,
              )
          else:
              logger.error("Unsupported Data Source: %s", schema)
          # Now that we have content, standardize the data
          if not df.empty:
              logger.info("Rows: %d [%s]", len(df), data_fractal)
              # convert data to canonical form
              df = convert_data(df, index_column, intraday_data)
              # resample data and forward fill any NA values
              if resample_data:
                  df = df.resample(fractal).agg(
                      {
                          "open": "first",
                          "high": "max",
                          "low": "min",
                          "close": "last",
                          "volume": "sum",
                      }
                  )
                  df.dropna(axis=0, how="any", inplace=True)
                  logger.info(
                      "Rows after Resampling at %s: %d",
                      fractal,
                      len(df),
                  )
              # add intraday columns if necessary
              if intraday_data:
                  df = enhance_intraday_data(df)
              # allocate global Frame
              newf = Frame(symbol.lower(), gspace, df)
              if newf is None:
                  logger.error(
                      "Could not allocate Frame for: %s", symbol.upper()
                  )
              # calculate maximum number of periods
              df_len = len(df)
              if df_len > n_periods:
                  n_periods = df_len
          else:
              logger.info("No DataFrame for %s", symbol.upper())
  
      # The number of periods actually retrieved
      return n_periods
  
imports: from alphapy.frame import Frame
  from alphapy.frame import frame_name
  from alphapy.frame import read_frame
  from alphapy.globals import ModelType
  from alphapy.globals import Partition, datasets
  from alphapy.globals import PSEP, SSEP, USEP
  from alphapy.globals import SamplingMethod
  from alphapy.globals import WILDCARD
  from alphapy.space import Space
  import arrow
  from datetime import datetime
  from datetime import timedelta
  from iexfinance.stocks import get_historical_data
  from iexfinance.stocks import get_historical_intraday
  from imblearn.combine import SMOTEENN
  from imblearn.combine import SMOTETomek
  import imblearn.ensemble
  from imblearn.over_sampling import RandomOverSampler
  from imblearn.over_sampling import SMOTE
  from imblearn.under_sampling import ClusterCentroids
  from imblearn.under_sampling import CondensedNearestNeighbour
  from imblearn.under_sampling import EditedNearestNeighbours
  from imblearn.under_sampling import InstanceHardnessThreshold
  from imblearn.under_sampling import NearMiss
  from imblearn.under_sampling import NeighbourhoodCleaningRule
  from imblearn.under_sampling import OneSidedSelection
  from imblearn.under_sampling import RandomUnderSampler
  from imblearn.under_sampling import RepeatedEditedNearestNeighbours
  from imblearn.under_sampling import TomekLinks
  import logging
  import math
  import numpy
  import os
  import pandas
  import pandas_datareader.data
  import re
  import requests
  from scipy import sparse
  from sklearn.preprocessing import LabelEncoder
  import sys
label_desc: Use image node_id 12 for calling a global function with example usage: get_market_data(model, market_specs, group, lookback_period, intraday_data) and returns: n_periods