{"record":{"id":"8adb10b51798bb62","repo":"microsoft/qlib","slug":"trade-date-is-not-tradable-date","errorCode":null,"errorMessage":"trade date is not tradable date","messagePattern":"trade date is not tradable date","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/operator.py","lineNumber":63,"sourceCode":"            path : str\r\n                Path to save user account.\r\n            date : str (YYYY-MM-DD)\r\n                Trade date, when the generated order list will be traded.\r\n        Return\r\n        ----------\r\n            um: UserManager()\r\n            pred_date: pd.Timestamp\r\n            trade_date: pd.Timestamp\r\n        \"\"\"\r\n        qlib.init_from_yaml_conf(client)\r\n        um = UserManager(user_data_path=pathlib.Path(path))\r\n        um.load_users()\r\n        if not date:\r\n            trade_date, pred_date = None, None\r\n        else:\r\n            trade_date = pd.Timestamp(date)\r\n            if not is_tradable_date(trade_date):\r\n                raise ValueError(\"trade date is not tradable date\".format(trade_date.date()))\r\n            pred_date = get_pre_trading_date(trade_date, future=True)\r\n        return um, pred_date, trade_date\r\n\r\n    def add_user(self, id, config, path, date):\r\n        \"\"\"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","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/operator.py#L45-L81","documentation":"Raised by OnlineOperator.init (qlib/contrib/online/operator.py) when the requested trade date is not in qlib's trading calendar (is_tradable_date returns False). Online operations (generate orders, execute, check) must run on a trading day known to the provider's calendar. Note the message itself has a formatting bug: it uses .format() on a string with no {} placeholder, so the date is not shown.","triggerScenarios":"Calling operator methods (execute/order/check) with date= set to a weekend or holiday for the active market, or a date outside the calendar range of the initialized provider.","commonSituations":"Cron jobs scheduled on calendar days that land on non-trading days; running against a CN-market calendar with US dates or vice versa; using a date beyond the local data dump's calendar end.","solutions":["Pass the last trading day at or before your date: trade_date = D.calendar(end_time=date)[-1], then use that.","Check tradability first: from qlib.contrib.online.operator import is_tradable_date; skip if not tradable.","Verify qlib.init was pointed at the right provider/calendar (client config) for the market you trade."],"exampleFix":"# before\nop.execute(date=\"2021-10-03\", ...)  # Sunday -> ValueError: trade date is not tradable date\n\n# after\nfrom qlib.data import D\ntrade_date = D.calendar(end_time=\"2021-10-04\")[-1]  # rolls back to last trading day\nop.execute(date=str(trade_date.date()), ...)","handlingStrategy":"validation","validationCode":"from qlib.data import D\nfrom qlib.contrib.online.operator import is_tradable_date\n\ntrade_date = D.calendar(end_time=date)[-1]\nif not is_tradable_date(trade_date):\n    raise RuntimeError(f\"{trade_date} not tradable; check provider calendar\")\nop.execute(date=str(trade_date.date()), ...)","typeGuard":null,"tryCatchPattern":"try:\n    op.execute(date=date, ...)\nexcept ValueError as e:\n    if \"not tradable\" in str(e):\n        date = str(D.calendar(end_time=date)[-1].date())\n        op.execute(date=date, ...)\n    else:\n        raise","preventionTips":["Always roll dates back with D.calendar(end_time=...)[-1] before online ops.","Schedule jobs on trading days derived from the calendar, not raw weekdays.","Confirm provider/market calendar matches the instruments you trade."],"tags":["qlib","online-operator","trading-calendar","dates","configuration"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}