Skip to content

fix: preserve BNFCR in zero-balance filter and emit MiCA warning#74

Merged
Romazes merged 4 commits intoQuantConnect:masterfrom
Romazes:bug-9339-bnfcr-available-balance
Apr 13, 2026
Merged

fix: preserve BNFCR in zero-balance filter and emit MiCA warning#74
Romazes merged 4 commits intoQuantConnect:masterfrom
Romazes:bug-9339-bnfcr-available-balance

Conversation

@Romazes
Copy link
Copy Markdown
Contributor

@Romazes Romazes commented Apr 9, 2026

Description

For EU/EEA Binance accounts under MiCA Credits Trading Mode, BNFCR is always present in the futures account balance response. Previously, the zero-balance filter in GetCashBalance removed BNFCR when walletBalance=0, preventing BinanceCryptoFutureMarginModel in Lean from detecting EU accounts and aggregating supplementary collateral.

This PR:

  1. Adds a BNFCR exception to the zero-balance filter in BinanceBaseRestApiClient so BNFCR always passes through to CashBook
  2. Removes the manual BNFCR injection in BinanceFuturesRestApiClient (no longer needed)
  3. Reverts FutureBalance.Amount to use walletBalance only (availableBalance includes unrealized PnL and deducts initial margin, causing double-counting with Lean's TPV tracking)
  4. Emits a BrokerageMessageEvent warning when BNFCR is detected, so users and logs clearly indicate the account is in MiCA Credits Trading Mode

Related PR(s)

QuantConnect/Lean#9373

Related Issue

QuantConnect/Lean#9339

Motivation and Context

EU users with BNFCR need supplementary collateral (USDC, BTC, ETH, BNB, etc.) aggregated for USDⓈ-M futures margin. The brokerage must preserve BNFCR in the balance response so the margin model in Lean can detect MiCA mode and iterate all collateral assets.

Requires Documentation Change

No

How Has This Been Tested?

  • Verified against real Binance EU account API response
  • BinanceCryptoFutureMarginModel unit tests in Lean (all passing)
  • Regression algorithm BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm in Lean
  • Warning message:
    image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Romazes added 3 commits April 9, 2026 17:42
For EU/EEA accounts under Binance MiCA Credits Trading Mode, BNFCR
walletBalance can be negative (fees and PnL are charged in BNFCR).
Binance stores the total cross-margin available balance — aggregating
all stablecoins minus used margin — in availableBalance on the BNFCR
asset entry. Using availableBalance as Amount for BNFCR ensures the
BinanceCryptoFutureMarginModel receives the correct collateral figure
and the > 0 guard passes for accounts with sufficient collateral.
- Add BNFCR exception to the zero-balance filter in BinanceBaseRestApiClient
  so BNFCR always passes through even when walletBalance=0
- Remove manual BNFCR injection in BinanceFuturesRestApiClient (no longer needed)
- Revert FutureBalance.Amount to use walletBalance only (availableBalance causes
  double-counting with Lean's own PnL/margin tracking)
@Romazes Romazes changed the title fix: use availableBalance for BNFCR in FutureBalance fix: preserve BNFCR in zero-balance filter and emit MiCA warning Apr 10, 2026
@Romazes Romazes requested a review from Martin-Molinero April 10, 2026 20:51
@Romazes Romazes self-assigned this Apr 10, 2026
@Romazes Romazes added bug Something isn't working and removed bug Something isn't working labels Apr 10, 2026
@Romazes Romazes requested a review from Martin-Molinero April 13, 2026 13:09
@Romazes Romazes merged commit ce3210b into QuantConnect:master Apr 13, 2026
@Romazes Romazes deleted the bug-9339-bnfcr-available-balance branch April 13, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants