Repository: OpenBB-finance/OpenBBTerminal
File: openbb_platform/core/openbb_core/app/command_runner.py (Python)

Code before:
            # We also pop custom headers
            model_headers = system_settings.api_settings.custom_headers or {}
            custom_headers = {
                name: kwargs.pop(name.replace("-", "_"), default)
                for name, default in model_headers.items() or {}
            } or None

            try:
                obbject = await cls._command(func, kwargs)

                # This section prepares the obbject to pass to the charting service.
                obbject._route = route  # pylint: disable=protected-access
                std_params = kwargs.get("standard_params", {})
                if std_params and hasattr(std_params, "__dict__"):
                    std_params = std_params.__dict__
                elif "data" in kwargs:
                    std_params = kwargs

                xtra_params = kwargs.get("extra_params", {})
                if xtra_params and hasattr(xtra_params, "__dict__"):
                    xtra_params = xtra_params.__dict__

                obbject._standard_params = (  # pylint: disable=protected-access
                    std_params
                )
                obbject._extra_params = xtra_params  # pylint: disable=protected-access
                if chart and obbject.results:
                    cls._chart(obbject, **kwargs)
            finally:
                ls = LoggingService(system_settings, user_settings)
                ls.log(
                    user_settings=user_settings,
                    system_settings=system_settings,
                    route=route,
                    func=func,
                    kwargs=kwargs,
                    exec_info=exc_info(),
                    custom_headers=custom_headers,
                )

        if warning_list:
            obbject.warnings = []
            for w in warning_list:
                obbject.warnings.append(cast_warning(w))
                if user_settings.preferences.show_warnings:
                    showwarning(
                        message=w.message,
                        category=w.category,
                        filename=w.filename,
                        lineno=w.lineno,
                        file=w.file,

Review comment (refactor):
```suggestion
 def extract_params(kwargs, key):
	params = kwargs.get(key, {})
	if hasattr(params, "__dict__"):
		return params.__dict__
	return params
  
std_params = extract_params(kwargs, "standard_params") or (kwargs if "data" in kwargs else {})
extra_params = extract_params(kwargs, "extra_params")

obbject._standard_params = std_params  # pylint: disable=protected-access
obbject._extra_params = extra_params    # pylint: disable=protected-access
```

Code after:
                execution_context=execution_context,
                func=func,
                kwargs=kwargs,
            )

            # If we're on the api we need to remove "chart" here because the parameter is added on
            # commands.py and the function signature does not expect "chart"
            kwargs.pop("chart", None)
            # We also pop custom headers
            model_headers = system_settings.api_settings.custom_headers or {}
            custom_headers = {
                name: kwargs.pop(name.replace("-", "_"), default)
                for name, default in model_headers.items() or {}
            } or None

            try:
                obbject = await cls._command(func, kwargs)

                # This section prepares the obbject to pass to the charting service.
                obbject._route = route  # pylint: disable=protected-access
                std_params = cls._extract_params(kwargs, "standard_params") or (
                    kwargs if "data" in kwargs else {}
                )
                extra_params = cls._extract_params(kwargs, "extra_params")
                obbject._standard_params = (  # pylint: disable=protected-access
                    std_params
                )
                obbject._extra_params = extra_params  # pylint: disable=protected-access
                if chart and obbject.results:
                    cls._chart(obbject, **kwargs)
            finally:
                ls = LoggingService(system_settings, user_settings)
                ls.log(
                    user_settings=user_settings,
                    system_settings=system_settings,
                    route=route,
                    func=func,
                    kwargs=kwargs,
                    exec_info=exc_info(),
                    custom_headers=custom_headers,
                )

        if warning_list:
            obbject.warnings = []
            for w in warning_list:
                obbject.warnings.append(cast_warning(w))
                if user_settings.preferences.show_warnings:
                    showwarning(
                        message=w.message,
                        category=w.category,
                        filename=w.filename,