QuantConnect/Lean · error · RegressionTestException
Expected positive buying power from BNFCR, got {buyingPower.
Error message
Expected positive buying power from BNFCR, got {buyingPower.Value} What it means
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.
Source
Thrown at Algorithm.CSharp/BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm.cs:65
SetCash(0);
SetCash("BNFCR", 200m, 1m);
SetCash("ETH", 0, 1600);
SetCash("USDC", 0, 1);
}
public override void OnData(Slice slice)
{
if (_adaUsdt.Price == 0 || _orderPlaced)
{
return;
}
// 1. BNFCR collateral must produce positive buying power (USDT is zero)
var buyingPower = _adaUsdt.BuyingPowerModel.GetBuyingPower(new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));
if (buyingPower.Value <= 0)
{
throw new RegressionTestException($"Expected positive buying power from BNFCR, got {buyingPower.Value}");
}
// 2. Order must not be rejected
var ticket = Buy(_adaUsdt.Symbol, 1000);
_orderPlaced = true;
if (ticket.Status == OrderStatus.Invalid)
{
throw new RegressionTestException("Order rejected — BNFCR collateral should cover margin");
}
// 3. Margin must be tracked
if (Portfolio.TotalMarginUsed <= 0)
{
throw new RegressionTestException($"Expected positive TotalMarginUsed, got {Portfolio.TotalMarginUsed}");
}
// 4. Shared collateral: ETHUSDC (different quote currency) must deduct ADAUSDT margin
_ethUsdc.SetMarketPrice(new TradeBar { Time = Time, Symbol = _ethUsdc.Symbol, Close = 1600 });View on GitHub (pinned to d2c3659f87)
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).
Example fix
// before — BNFCR not set or wrong brokerage
SetBrokerageModel(BrokerageName.BinanceFutures);
// SetCash('BNFCR', ...) missing
// after
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);
SetCash("BNFCR", 200m, 1m); Defensive patterns
Strategy: validation
Validate before calling
// Validate BNFCR collateral and buying power before asserting
var bnfcr = Portfolio.CashBook.ContainsKey("BNFCR") ? Portfolio.CashBook["BNFCR"].Amount : 0;
Log($"BNFCR collateral: {bnfcr}");
var bp = _adaUsdt.BuyingPowerModel.GetBuyingPower(
new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));
if (bp.Value <= 0)
{
Log($"Buying power is {bp.Value} — BNFCR collateral may not be recognized");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ETHUSDC buying power ({ethBuyingPower.Value}) must be less t
- Order rejected — BNFCR collateral should cover margin
- Expected positive TotalMarginUsed, got {Portfolio.TotalMargi
- Expected an open position at end of algorithm
- Invalid buying power model. Found: {buyingPowerModel.GetType
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/2baf5042141ec09b.
Report an issue: GitHub.