{"record":{"id":"c748c0f9ac896cba","repo":"microsoft/qlib","slug":"direction-direction-is-not-supported","errorCode":null,"errorMessage":"direction {direction} is not supported!","messagePattern":"direction (.+?) is not supported!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/exchange.py","lineNumber":376,"sourceCode":"        -------\n        True: the trading of the stock is limited (maybe hit the highest/lowest price), hence the stock is not tradable\n        False: the trading of the stock is not limited, hence the stock may be tradable\n        \"\"\"\n        # NOTE:\n        # **all** is used when checking limitation.\n        # For example, the stock trading is limited in a day if every minute is limited in a day if every minute is limited.\n        if direction is None:\n            # The trading limitation is related to the trading direction\n            # if the direction is not provided, then any limitation from buy or sell will result in trading limitation\n            buy_limit = self.quote.get_data(stock_id, start_time, end_time, field=\"limit_buy\", method=\"all\")\n            sell_limit = self.quote.get_data(stock_id, start_time, end_time, field=\"limit_sell\", method=\"all\")\n            return bool(buy_limit or sell_limit)\n        elif direction == Order.BUY:\n            return cast(bool, self.quote.get_data(stock_id, start_time, end_time, field=\"limit_buy\", method=\"all\"))\n        elif direction == Order.SELL:\n            return cast(bool, self.quote.get_data(stock_id, start_time, end_time, field=\"limit_sell\", method=\"all\"))\n        else:\n            raise ValueError(f\"direction {direction} is not supported!\")\n\n    def check_stock_suspended(\n        self,\n        stock_id: str,\n        start_time: pd.Timestamp,\n        end_time: pd.Timestamp,\n    ) -> bool:\n        \"\"\"if stock is suspended(hence not tradable), True will be returned\"\"\"\n        # is suspended\n        if stock_id in self.quote.get_all_stock():\n            # suspended stocks are represented by None $close stock\n            # The $close may contain NaN,\n            close = self.quote.get_data(stock_id, start_time, end_time, \"$close\")\n            if close is None:\n                # if no close record exists\n                return True\n            elif isinstance(close, IndexData):\n                # **any** non-NaN $close represents trading opportunity may exist","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/exchange.py#L358-L394","documentation":"Exchange.check_stock_limit(stop_time...) queries the limit_buy/limit_sell quote fields based on the requested direction: None checks either side, Order.BUY checks limit_buy, Order.SELL checks limit_sell. Any other value for direction cannot select a field, so ValueError is raised. Order.BUY/Order.SELL are integers (1/-1), so arbitrary ints or strings fail.","triggerScenarios":"is_stock_tradable(stock_id, start, end, direction=0), direction='buy', or passing an OrderDir-like enum from a different/older qlib version with different values.","commonSituations":"Custom strategies passing direction as a string; mixing qlib versions where Order.BUY/SELL constants or OrderDir enum members were imported from mismatched modules.","solutions":["Pass direction=None (either-side check), Order.BUY (=1), or Order.SELL (=-1)","Import Order/OrderDir from the same qlib version as the Exchange: from qlib.backtest.exchange import Exchange, OrderDir","If direction comes from an order object, pass order.direction directly rather than re-encoding it"],"exampleFix":"# before\ntradable = exch.is_stock_tradable(sid, t0, t1, direction='buy')\n# after\nfrom qlib.backtest.exchange import Order\ntradable = exch.is_stock_tradable(sid, t0, t1, direction=Order.BUY)","handlingStrategy":"validation","validationCode":"from qlib.backtest.order import Order\nassert direction is None or direction in (Order.BUY, Order.SELL)\nexch.is_stock_tradable(sid, t0, t1, direction=direction)","typeGuard":"def is_valid_direction(d) -> bool:\n    from qlib.backtest.order import Order\n    return d is None or d in (Order.BUY, Order.SELL)","tryCatchPattern":null,"preventionTips":["Never pass strings like 'buy'; use Order.BUY/Order.SELL constants","Forward order.direction instead of re-encoding direction values"],"tags":["qlib","exchange","direction","invalid-argument"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}