fix: preserve BNFCR in zero-balance filter and emit MiCA warning#74
Merged
Romazes merged 4 commits intoQuantConnect:masterfrom Apr 13, 2026
Merged
Conversation
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)
11 tasks
Martin-Molinero
approved these changes
Apr 10, 2026
Martin-Molinero
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
GetCashBalanceremoved BNFCR whenwalletBalance=0, preventingBinanceCryptoFutureMarginModelin Lean from detecting EU accounts and aggregating supplementary collateral.This PR:
BinanceBaseRestApiClientso BNFCR always passes through to CashBookBinanceFuturesRestApiClient(no longer needed)FutureBalance.Amountto usewalletBalanceonly (availableBalanceincludes unrealized PnL and deducts initial margin, causing double-counting with Lean's TPV tracking)BrokerageMessageEventwarning when BNFCR is detected, so users and logs clearly indicate the account is in MiCA Credits Trading ModeRelated 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?
BinanceCryptoFutureMarginModelunit tests in Lean (all passing)BinanceCryptoFutureBnfcrCollateralRegressionAlgorithmin LeanTypes of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>