QuantConnect/Lean · error · RegressionTestException
ETHUSDC buying power ({ethBuyingPower.Value}) must be less t
Error message
ETHUSDC buying power ({ethBuyingPower.Value}) must be less than ADAUSDT ({adaBuyingPower.Value}) — shared BNFCR pool must deduct ADAUSDT maintenance margin What it means
Thrown when ETHUSDC's buying power is not less than ADAUSDT's after the ADAUSDT position opens. The test verifies that the shared BNFCR collateral pool correctly deducts ADAUSDT's maintenance margin from the buying power available to other instruments (ETHUSDC, which uses a different quote currency). ADAUSDT skips its own maintenance margin in its own buying-power calc, so ADAUSDT should report more available power than ETHUSDC.
Source
Thrown at Algorithm.CSharp/BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm.cs:92
}
// 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 });
var ethBuyingPower = _ethUsdc.BuyingPowerModel.GetBuyingPower(new BuyingPowerParameters(Portfolio, _ethUsdc, OrderDirection.Buy));
var adaBuyingPower = _adaUsdt.BuyingPowerModel.GetBuyingPower(new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));
// ETHUSDC must see less buying power than ADAUSDT - ADAUSDT maintenance margin
// is deducted from ETHUSDC's shared pool, but ADAUSDT skips itself.
if (ethBuyingPower.Value >= adaBuyingPower.Value)
{
throw new RegressionTestException(
$"ETHUSDC buying power ({ethBuyingPower.Value}) must be less than ADAUSDT ({adaBuyingPower.Value}) " +
$"— shared BNFCR pool must deduct ADAUSDT maintenance margin");
}
}
public override void OnEndOfAlgorithm()
{
if (!Portfolio.Invested)
{
throw new RegressionTestException("Expected an open position at end of algorithm");
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug($"{Time} {orderEvent}");
}
View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect CryptoFutureBuyingPowerModel.GetBuyingPower to verify it deducts other positions' maintenance margin from the shared BNFCR pool but skips the querying security's own.
- Confirm both ADAUSDT and ETHUSDC share the same BNFCR collateral pool (check Portfolio.CashBook and margin configuration).
- Log the maintenance margin deducted for ADAUSDT in both calculations to identify where the deduction is missing.
- Verify SetMarketPrice for ETHUSDC provides a valid price so its buying power is computed correctly.
- Check that the collateral-pool key includes BNFCR across different quote currency pairs.
Example fix
// before
if (ethBuyingPower.Value >= adaBuyingPower.Value)
{
throw new RegressionTestException(
$"ETHUSDC buying power ({ethBuyingPower.Value}) must be less than ADAUSDT ({adaBuyingPower.Value})");
}
// after — diagnostic detail
if (ethBuyingPower.Value >= adaBuyingPower.Value)
{
Log($"ETH bp={ethBuyingPower.Value}, ADA bp={adaBuyingPower.Value}");
Log($"ADA maintenance margin={Securities[_adaUsdt.Symbol].MarginModel.GetMaintenanceMargin(...)}");
throw new RegressionTestException(
$"ETHUSDC bp ({ethBuyingPower.Value}) >= ADAUSDT bp ({adaBuyingPower.Value}) — " +
$"shared BNFCR deduction broken");
} Defensive patterns
Strategy: validation
Validate before calling
// Log buying power components before asserting
var ethBp = _ethUsdc.BuyingPowerModel.GetBuyingPower(
new BuyingPowerParameters(Portfolio, _ethUsdc, OrderDirection.Buy));
var adaBp = _adaUsdt.BuyingPowerModel.GetBuyingPower(
new BuyingPowerParameters(Portfolio, _adaUsdt, OrderDirection.Buy));
Log($"ETHUSDC bp={ethBp.Value}, ADAUSDT bp={adaBp.Value}");
if (ethBp.Value >= adaBp.Value)
{
Log("Shared BNFCR collateral deduction may be broken between quote currencies");
} Prevention
- Verify the shared BNFCR collateral pool spans different quote currency pairs.
- Check that the buying-power model skips the querying security's own maintenance margin.
- Log maintenance margin deductions for each security in the portfolio.
- Ensure ETHUSDC has a valid market price before computing buying power.
When it happens
Trigger: The shared-collateral deduction logic in CryptoFutureBuyingPowerModel does not cross-deduct maintenance margin between different quote currencies, the BNFCR pool is not shared across ADAUSDT and ETHUSDC, or the deduction is applied symmetrically instead of skipping the querying instrument's own margin.
Common situations: Buying-power model refactoring that breaks shared collateral pools, changes to how maintenance margin is excluded from the querying security's own calculation, new quote-currency handling that isolates collateral pools, or BNFCR collateral assignment per-security instead of portfolio-wide.
Related errors
- Expected positive buying power from BNFCR, got {buyingPower.
- 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/2364347d1cc09e37.
Report an issue: GitHub.