{"record":{"id":"155dfc70b3c1a18f","repo":"microsoft/qlib","slug":"add-date-is-not-tradable-date","errorCode":null,"errorMessage":"add date is not tradable date","messagePattern":"add date is not tradable date","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/operator.py","lineNumber":86,"sourceCode":"        \"\"\"Add a new user into the a folder to run 'online' module.\r\n\r\n        Parameters\r\n        ----------\r\n        id : str\r\n            User id, should be unique.\r\n        config : str\r\n            The file path (yaml) of user config\r\n        path : str\r\n            Path to save user account.\r\n        date : str (YYYY-MM-DD)\r\n            The date that user account was added.\r\n        \"\"\"\r\n        create_user_folder(path)\r\n        qlib.init_from_yaml_conf(self.client)\r\n        um = UserManager(user_data_path=path)\r\n        add_date = D.calendar(end_time=date)[-1]\r\n        if not is_tradable_date(add_date):\r\n            raise ValueError(\"add date is not tradable date\".format(add_date.date()))\r\n        um.add_user(user_id=id, config_file=config, add_date=add_date)\r\n\r\n    def remove_user(self, id, path):\r\n        \"\"\"Remove user from folder used in 'online' module.\r\n\r\n        Parameters\r\n        ----------\r\n        id : str\r\n            User id, should be unique.\r\n        path : str\r\n            Path to save user account.\r\n        \"\"\"\r\n        um = UserManager(user_data_path=path)\r\n        um.remove_user(user_id=id)\r\n\r\n    def generate(self, date, path):\r\n        \"\"\"Generate order list that will be traded at 'date'.\r\n\r","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/operator.py#L68-L104","documentation":"Raised by OnlineOperator.add_user when the computed add_date (last calendar date <= the given date) is not a tradable date. The user's strategy initialization is anchored to a real trading day, so the account start date must be in the calendar. Like error 311, the .format() call has no placeholder so the date is omitted from the message.","triggerScenarios":"Calling op.add_user(id, config, path, date) where D.calendar(end_time=date)[-1] resolves to a non-trading day, or where the date is outside/edge-of the calendar such that the last element is not tradable per is_tradable_date.","commonSituations":"Adding users on weekends/holidays; calendar/data dump that ends before the requested date; suspended trading periods in the local calendar data.","solutions":["Pass a date that is a known trading day (check D.calendar() for the market).","Roll back explicitly: add_date = D.calendar(end_time=date)[-1] in your own code and validate is_tradable_date(add_date) before calling add_user.","Update/point at a qlib data dump whose calendar covers the requested date."],"exampleFix":"# before\nop.add_user(id=\"u1\", config=cfg, path=p, date=\"2021-10-02\")\n# ValueError: add date is not tradable date\n\n# after\nfrom qlib.data import D\nd = D.calendar(end_time=\"2021-10-02\")[-1]  # last trading day <= date\nop.add_user(id=\"u1\", config=cfg, path=p, date=str(d.date()))","handlingStrategy":"validation","validationCode":"from qlib.data import D\nfrom qlib.contrib.online.operator import is_tradable_date\n\nd = D.calendar(end_time=date)[-1]\nif not is_tradable_date(d):\n    raise RuntimeError(f\"add date {d} not tradable; supply a trading day\")\nop.add_user(id=id, config=cfg, path=p, date=str(d.date()))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-compute the last trading day and validate tradability yourself before add_user.","Keep a helper get_last_trading_day(date) used by all online entry points.","Refresh the qlib data dump so the calendar covers current dates."],"tags":["qlib","online-operator","trading-calendar","dates","user"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}