{"record":{"id":"429b44deb73203e9","repo":"microsoft/qlib","slug":"get-unexpected-arguments-kwargs","errorCode":null,"errorMessage":"Get Unexpected arguments {kwargs}","messagePattern":"Get Unexpected arguments (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/exchange.py","lineNumber":137,"sourceCode":"                                                $close is for calculating the total value at end of each day.\n                                            Optional fields:\n                                                $volume is only necessary when we limit the trade amount or calculate\n                                                PA(vwap) indicator\n                                                $vwap is only necessary when we use the $vwap price as the deal price\n                                                $factor is for rounding to the trading unit\n                                                limit_sell will be set to False by default (False indicates we can sell\n                                                this target on this day).\n                                                limit_buy will be set to False by default (False indicates we can buy\n                                                this target on this day).\n                                    index: MultipleIndex(instrument, pd.Datetime)\n        \"\"\"\n        self.freq = freq\n        self.start_time = start_time\n        self.end_time = end_time\n\n        self.trade_unit = kwargs.pop(\"trade_unit\", C.trade_unit)\n        if len(kwargs) > 0:\n            raise ValueError(f\"Get Unexpected arguments {kwargs}\")\n\n        if limit_threshold is None:\n            limit_threshold = C.limit_threshold\n        if deal_price is None:\n            deal_price = C.deal_price\n\n        # we have some verbose information here. So logging is enabled\n        self.logger = get_module_logger(\"online operator\")\n\n        # TODO: the quote, trade_dates, codes are not necessary.\n        # It is just for performance consideration.\n        self.limit_type = self._get_limit_type(limit_threshold)\n        if limit_threshold is None:\n            if C.region in [REG_CN, REG_TW]:\n                self.logger.warning(f\"limit_threshold not set. The stocks hit the limit may be bought/sold\")\n        elif self.limit_type == self.LT_FLT and abs(cast(float, limit_threshold)) > 0.1:\n            if C.region in [REG_CN, REG_TW]:\n                self.logger.warning(f\"limit_threshold may not be set to a reasonable value\")","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/exchange.py#L119-L155","documentation":"The Exchange constructor accepts only one extra keyword beyond its named parameters: 'trade_unit', which it pops from kwargs. After that pop, any remaining entry in kwargs is a typo'd or unsupported parameter, and the constructor raises ValueError listing the leftovers. This is a fail-fast guard against silently ignored misspelled arguments.","triggerScenarios":"Instantiating Exchange(...) with unknown keywords, e.g. Exchange(volume_threshold=...) when it is a named param misspelled, or passing removed/renamed options like Exchange(trade_units=100) or dealer-style kwargs; also forwarding **config dicts that contain stale keys.","commonSituations":"Version upgrades where Exchange parameters were renamed or removed; config files (yaml/json) whose keys are dumped into Exchange(**cfg); copy-pasted example code from an older qlib README.","solutions":["Inspect the error message: the {kwargs} dict names exactly which keys are unrecognized; fix or remove those keys","If building Exchange from a config dict, filter keys against the constructor signature (inspect.signature) before the call","Check the current Exchange.__init__ signature in your installed qlib version for renamed parameters (e.g. trade_unit is the only accepted extra kwarg)"],"exampleFix":"# before\nexch = Exchange(freq='day', trade_units=100)  # 'trade_units' -> ValueError\n# after\nexch = Exchange(freq='day', trade_unit=100)","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(Exchange.__init__)\nallowed = set(sig.parameters) | {'trade_unit'}\nunknown = {k for k in cfg if k not in allowed and k != 'self'}\nassert not unknown, f\"Unknown Exchange kwargs: {unknown}\"\nexch = Exchange(**cfg)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Diff config keys against Exchange.__init__ signature after every qlib upgrade","Never blind-forward user config dicts into Exchange(**cfg)"],"tags":["qlib","exchange","invalid-argument","value-error"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}