{"record":{"id":"a2652bb11741388d","repo":"microsoft/qlib","slug":"the-account-data-is-not-newest-last-trading-date","errorCode":null,"errorMessage":"The account data is not newest! last trading date {}, today {}","messagePattern":"The account data is not newest! last trading date (.+?), today (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"qlib/contrib/online/operator.py","lineNumber":155,"sourceCode":"\r\n    def execute(self, date, exchange_config, path):\r\n        \"\"\"Execute the orderlist at 'date'.\r\n\r\n        Parameters\r\n        ----------\r\n           date : str (YYYY-MM-DD)\r\n               Trade date, that the generated order list will be traded.\r\n           exchange_config: str\r\n               The file path (yaml) of exchange config\r\n           path : str\r\n               Path to save user account.\r\n        \"\"\"\r\n        um, pred_date, trade_date = self.init(self.client, path, date)\r\n        for user_id, user in um.users.items():\r\n            dates, trade_exchange = prepare(um, trade_date, user_id, exchange_config)\r\n            executor = SimulatorExecutor(trade_exchange=trade_exchange)\r\n            if str(dates[0].date()) != str(pred_date.date()):\r\n                raise ValueError(\r\n                    \"The account data is not newest! last trading date {}, today {}\".format(\r\n                        dates[0].date(), trade_date.date()\r\n                    )\r\n                )\r\n\r\n            # load and execute the order list\r\n            # will not modify the trade_account after executing\r\n            order_list = load_order_list(user_path=(pathlib.Path(path) / user_id), trade_date=trade_date)\r\n            trade_info = executor.execute(order_list=order_list, trade_account=user.account, trade_date=trade_date)\r\n            executor.save_executed_file_from_trade_info(\r\n                trade_info=trade_info,\r\n                user_path=(pathlib.Path(path) / user_id),\r\n                trade_date=trade_date,\r\n            )\r\n            self.logger.info(\"execute order list at {} for {}\".format(trade_date.date(), user_id))\r\n\r\n    def update(self, date, path, type=\"SIM\"):\r\n        \"\"\"Update account at 'date'.\r","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/operator.py#L137-L173","documentation":"Raised in OnlineOperator.execute (the order-execution path) when the user account's last trading date (dates[0] from prepare()) does not equal the expected prediction date pred_date. Online execution assumes the account is fully synced up to the previous trading day; otherwise orders computed for stale scores could be executed against the wrong portfolio state.","triggerScenarios":"Running execute() for trade_date when the user's saved account last_updated date is behind pred_date — e.g. the daily job was skipped for one or more days, or execute is called twice in a day after the account was already advanced.","commonSituations":"Missed scheduled runs (server down over a trading day); manually re-running or catching up execute() out of order; clock/timezone skew making 'today' resolve to a different trading date than the account state.","solutions":["Catch up the account first: run the missed dates' execute/order cycle in chronological order until the account reaches pred_date, then run today's.","If the state is acceptable to reset, remove and re-add the user (or restore from a fresh account) to realign dates.","Schedule the online job reliably for every trading day so the account never falls behind."],"exampleFix":"# before\nop.execute(date=\"2021-10-11\", ...)\n# ValueError: The account data is not newest! last trading date 2021-09-30, today 2021-10-11\n\n# after\n# replay missed trading days in order, then run today\nfor d in [\"2021-10-08\", \"2021-10-09\", \"2021-10-11\"]:\n    op.execute(date=d, ...)","handlingStrategy":"validation","validationCode":"# before executing, verify the account is current\num, pred_date, trade_date = op.init(client, path, date)\nfor uid, user in um.users.items():\n    dates, _ = prepare(um, trade_date, uid, exchange_config)\n    if str(dates[0].date()) != str(pred_date.date()):\n        raise RuntimeError(\n            f\"account {uid} stale (last={dates[0].date()}, need={pred_date.date()}); \"\n            \"replay missed trading days first\"\n        )\nop.execute(date=date, ...)","typeGuard":null,"tryCatchPattern":"try:\n    op.execute(date=date, ...)\nexcept ValueError as e:\n    if \"not newest\" in str(e):\n        # determine missed dates from the message and replay them in order\n        log.error(\"stale account; replay missed days: %s\", e)\n    raise","preventionTips":["Make the daily online job atomic and monitored; alert on missed runs.","Keep a ledger of executed trade dates per user and assert continuity before executing.","Never execute out of order; replay missed days chronologically."],"tags":["qlib","online-operator","state-sync","dates","scheduling"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}