diff --git a/freqtrade/rpc/api_server/api_download_data.py b/freqtrade/rpc/api_server/api_download_data.py index 0ba960243..fddf9fa2b 100644 --- a/freqtrade/rpc/api_server/api_download_data.py +++ b/freqtrade/rpc/api_server/api_download_data.py @@ -11,6 +11,7 @@ from freqtrade.rpc.api_server.api_pairlists import handleExchangePayload from freqtrade.rpc.api_server.api_schemas import BgJobStarted, DownloadDataPayload from freqtrade.rpc.api_server.deps import get_config, get_exchange from freqtrade.rpc.api_server.webserver_bgwork import ApiBG +from freqtrade.util.progress_tracker import get_progress_tracker logger = logging.getLogger(__name__) @@ -27,7 +28,12 @@ def __run_download(job_id: str, config_loc: Config): with FtNoDBContext(): exchange = get_exchange(config_loc) - download_data(config_loc, exchange) + def ft_callback(task) -> None: + print(task) + + pt = get_progress_tracker(ft_callback=ft_callback) + + download_data(config_loc, exchange, progress_tracker=pt) # ApiBG.jobs[job_id]["result"] = { # } diff --git a/freqtrade/util/rich_progress.py b/freqtrade/util/rich_progress.py index 6ada4f13f..9c2abbeae 100644 --- a/freqtrade/util/rich_progress.py +++ b/freqtrade/util/rich_progress.py @@ -1,7 +1,8 @@ from collections.abc import Callable +from typing import Any from rich.console import ConsoleRenderable, Group, RichCast -from rich.progress import Progress +from rich.progress import Progress, Task, TaskID class CustomProgress(Progress): @@ -10,13 +11,44 @@ class CustomProgress(Progress): *args, cust_objs: list[ConsoleRenderable] | None = None, cust_callables: list[Callable[[], ConsoleRenderable]] | None = None, + ft_callback: Callable[[Task], None] | None = None, **kwargs, ) -> None: self._cust_objs = cust_objs or [] self._cust_callables = cust_callables or [] + self._ft_callback = ft_callback + if self._ft_callback: + kwargs["disable"] = True super().__init__(*args, **kwargs) + def update( + self, + task_id: TaskID, + *, + total: float | None = None, + completed: float | None = None, + advance: float | None = None, + description: str | None = None, + visible: bool | None = None, + refresh: bool = False, + **fields: Any, + ) -> None: + if self._ft_callback: + self._ft_callback( + self.tasks[task_id], + ) + return super().update( + task_id, + total=total, + completed=completed, + advance=advance, + description=description, + visible=visible, + refresh=refresh, + **fields, + ) + def get_renderable(self) -> ConsoleRenderable | RichCast | str: objs = [obj for obj in self._cust_objs] for cust_call in self._cust_callables: