{"record":{"id":"966790de83d859c4","repo":"freqtrade/freqtrade","slug":"freqtrade-only-supports-isolated-futures-for-lever","errorCode":null,"errorMessage":"Freqtrade only supports isolated futures for leverage trading","messagePattern":"Freqtrade only supports isolated futures for leverage trading","errorType":"exception","errorClass":"OperationalException","httpStatus":null,"severity":"error","filePath":"freqtrade/exchange/binance.py","lineNumber":381,"sourceCode":"\n                upnl_ex_1 += trade.amount * mark_price - trade.amount * trade.open_rate\n\n            cross_vars = upnl_ex_1 - mm_ex_1\n\n        side_1 = -1 if is_short else 1\n\n        if maintenance_amt is None:\n            raise OperationalException(\n                \"Parameter maintenance_amt is required by Binance.liquidation_price\"\n                f\"for {self.trading_mode}\"\n            )\n\n        if self.trading_mode == TradingMode.FUTURES:\n            return (\n                (wallet_balance + cross_vars + maintenance_amt) - (side_1 * amount * open_rate)\n            ) / ((amount * mm_ratio) - (side_1 * amount))\n        else:\n            raise OperationalException(\n                \"Freqtrade only supports isolated futures for leverage trading\"\n            )\n\n    def load_leverage_tiers(self) -> dict[str, list[dict]]:\n        if self.trading_mode == TradingMode.FUTURES:\n            if self._config[\"dry_run\"]:\n                leverage_tiers_path = Path(__file__).parent / \"binance_leverage_tiers.json\"\n                with leverage_tiers_path.open() as json_file:\n                    return json_load(json_file)\n            else:\n                return self.get_leverage_tiers()\n        else:\n            return {}\n\n    async def _async_get_trade_history_id_startup(\n        self, pair: str, since: int\n    ) -> tuple[list[list], str]:\n        \"\"\"","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/freqtrade/freqtrade/blob/1c8edfe4d1e8d11bd4b40e8fc3237c26c3a60e15/freqtrade/exchange/binance.py#L363-L399","documentation":"Binance.liquidation_price raises OperationalException('Freqtrade only supports isolated futures for leverage trading') when trading_mode is not FUTURES. After computing the maintenance-amount prerequisites, the method's final branch only implements the futures formula; spot/margin modes have no liquidation-price semantics here.","triggerScenarios":"Calling liquidation_price() on an Exchange (or strategy code path reaching it, e.g. leverage/liquidation callbacks) while config trading_mode is spot or margin on the Binance exchange class.","commonSituations":"A strategy ported from futures to spot that still implements liquidation callbacks or calls exchange.liquidation_price(); misconfigured trading_mode after switching a config from futures back to spot.","solutions":["Set trading_mode: futures and margin_mode: isolated in config if you need liquidation prices","Remove/gate liquidation_price calls and liquidation-related callbacks for spot strategies","Guard strategy code with self.trading_mode == TradingMode.FUTURES (or config check) before touching leverage APIs"],"exampleFix":"# before\ndef custom_stoploss(self, pair, trade, ...):\n    liq = self.exchange.liquidation_price(...)  # crashes on spot\n\n# after\nfrom freqtrade.enums import TradingMode\n\ndef custom_stoploss(self, pair, trade, ...):\n    if self.config['trading_mode'] == TradingMode.FUTURES:\n        liq = self.exchange.liquidation_price(...)","handlingStrategy":"type-guard","validationCode":"from freqtrade.enums import TradingMode\n\nif self.config['trading_mode'] == TradingMode.FUTURES:\n    liq = exchange.liquidation_price(...)","typeGuard":"from freqtrade.enums import TradingMode\n\ndef is_futures(config) -> bool:\n    return config.get('trading_mode') == TradingMode.FUTURES","tryCatchPattern":null,"preventionTips":["Gate all leverage/liquidation logic (callbacks and direct calls) behind a trading_mode futures check","When porting a futures strategy to spot, delete rather than comment out liquidation code","Set trading_mode + margin_mode explicitly in every config to avoid inheriting defaults"],"tags":["binance","trading-mode","futures","liquidation","config"],"backgroundTag":null,"analyzedSha":"1c8edfe4d1e8d11bd4b40e8fc3237c26c3a60e15","analyzedAt":"2026-08-15T05:09:08.096Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}