{"record":{"id":"2baf5042141ec09b","repo":"QuantConnect/Lean","slug":"expected-positive-buying-power-from-bnfcr-got-bu","errorCode":null,"errorMessage":"Expected positive buying power from BNFCR, got {buyingPower.Value}","messagePattern":"Expected positive buying power from BNFCR, got (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm.cs","lineNumber":65,"sourceCode":"\n            SetCash(0);\n            SetCash(\"BNFCR\", 200m, 1m);\n            SetCash(\"ETH\", 0, 1600);\n            SetCash(\"USDC\", 0, 1);\n        }\n\n        public override void OnData(Slice slice)\n        {\n            if (_adaUsdt.Price == 0 || _orderPlaced)\n            {\n                return;\n            }\n\n            // 1. BNFCR collateral must produce positive buying power (USDT is zero)\n            var buyingPower = _adaUsdt.BuyingPowerModel.GetBuyingPower(new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));\n            if (buyingPower.Value <= 0)\n            {\n                throw new RegressionTestException($\"Expected positive buying power from BNFCR, got {buyingPower.Value}\");\n            }\n\n            // 2. Order must not be rejected\n            var ticket = Buy(_adaUsdt.Symbol, 1000);\n            _orderPlaced = true;\n            if (ticket.Status == OrderStatus.Invalid)\n            {\n                throw new RegressionTestException(\"Order rejected — BNFCR collateral should cover margin\");\n            }\n\n            // 3. Margin must be tracked\n            if (Portfolio.TotalMarginUsed <= 0)\n            {\n                throw new RegressionTestException($\"Expected positive TotalMarginUsed, got {Portfolio.TotalMarginUsed}\");\n            }\n\n            // 4. Shared collateral: ETHUSDC (different quote currency) must deduct ADAUSDT margin\n            _ethUsdc.SetMarketPrice(new TradeBar { Time = Time, Symbol = _ethUsdc.Symbol, Close = 1600 });","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm.cs#L47-L83","documentation":"Thrown in OnData when the buying power computed by _adaUsdt.BuyingPowerModel.GetBuyingPower for ADAUSDT returns a value of zero or less. BNFCR (Binance Fiat Stablecoins Acceptable for collateral) is configured as margin collateral with SetCash('BNFCR', 200, 1). The assertion verifies the buying-power model recognizes BNFCR as valid collateral and produces a positive purchasing power for a crypto future.","triggerScenarios":"The BNFCR collateral is not registered in the buying-power model, the collateral conversion rate is zero, the BinanceFutures brokerage model does not include BNFCR in its collateral list, or the margin model configuration is incorrect for AccountType.Margin.","commonSituations":"New collateral asset types not yet supported by the CryptoFutureBuyingPowerModel, brokerage model updates that remove BNFCR from acceptable collateral, conversion-rate table changes, or SetCash configuration errors.","solutions":["Verify SetCash('BNFCR', 200m, 1m) is called in Initialize with the correct conversion rate.","Check the BinanceFuturesBrokerageModel for BNFCR collateral registration.","Inspect the CryptoFutureBuyingPowerModel to confirm it includes BNFCR in the collateral pool calculation.","Log Portfolio.CashBook entries to confirm BNFCR is present with the correct amount.","Verify AccountType.Margin is set via SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin)."],"exampleFix":"// before — BNFCR not set or wrong brokerage\nSetBrokerageModel(BrokerageName.BinanceFutures);\n// SetCash('BNFCR', ...) missing\n\n// after\nSetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);\nSetCash(\"BNFCR\", 200m, 1m);","handlingStrategy":"validation","validationCode":"// Validate BNFCR collateral and buying power before asserting\nvar bnfcr = Portfolio.CashBook.ContainsKey(\"BNFCR\") ? Portfolio.CashBook[\"BNFCR\"].Amount : 0;\nLog($\"BNFCR collateral: {bnfcr}\");\nvar bp = _adaUsdt.BuyingPowerModel.GetBuyingPower(\n    new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));\nif (bp.Value <= 0)\n{\n    Log($\"Buying power is {bp.Value} — BNFCR collateral may not be recognized\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify SetCash('BNFCR', amount, conversionRate) is called in Initialize.","Confirm BinanceFuturesBrokerageModel includes BNFCR in its collateral list.","Check CryptoFutureBuyingPowerModel recognizes BNFCR as margin collateral.","Log Portfolio.CashBook entries after Initialize to confirm BNFCR registration."],"tags":["quantconnect","binance","crypto-futures","bnfcr","buying-power","margin","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}