Skip to content

fix: support BNFCR alternative collateral in CryptoFutureMarginModel for Binance#9373

Merged
Romazes merged 12 commits intoQuantConnect:masterfrom
Romazes:bug-9339-crypto-future-margin-alternative-collateral
Apr 13, 2026
Merged

fix: support BNFCR alternative collateral in CryptoFutureMarginModel for Binance#9373
Romazes merged 12 commits intoQuantConnect:masterfrom
Romazes:bug-9339-crypto-future-margin-alternative-collateral

Conversation

@Romazes
Copy link
Copy Markdown
Collaborator

@Romazes Romazes commented Apr 6, 2026

Description

Add BinanceCryptoFutureMarginModel that aggregates all supplementary collateral assets for USDⓈ-M futures when BNFCR is present (EU/EEA MiCA Credits Trading Mode). BNFCR presence in CashBook gates the collateral loop - non-EU accounts skip entirely. All non-zero walletBalance assets are summed as collateral (Binance specifies marginAvailable: true for each eligible asset in the API response).

Related PR(s)

Related Issue

Fixes #9339

Motivation and Context

EU/EEA Binance Futures users under MiCA Credits Trading Mode use BNFCR as the cross-margin
accounting currency. GetMarginRemaining() only checked the quote currency (e.g. USDT),
returning zero buying power for EU users. Binance aggregates all collateral into BNFCR
(from the MiCA FAQ: 1,000 USDC + 0.3 BTC×$60k + 12 BNB×$600 = 26,200 BNFCR).

All 12 asset types in the EU account API response have marginAvailable: true -
including stablecoins (USDC, FDUSD, USD1), crypto (BTC, ETH, BNB, U), and internal
products (BNFCR, LDUSDT, BFUSD, RWUSD). Binance adds new collateral types regularly,
so a hardcoded list would be outdated quickly. Instead we iterate CashBook and sum all
non-zero, non-primary collateral when BNFCR is present.

MiCA FAQ

Requires Documentation Change

No

How Has This Been Tested?

Unit tests (CryptoFutureMarginModelTests):

  • MarginRemainingWithBnfcrOnlyCollateral - BNFCR as sole collateral
  • MarginRemainingWithMixedCollateral - USDT + BNFCR
  • MarginRemainingWithUsdtOnlyCollateral - non-EU backward compatibility
  • CoinFutureDoesNotIncludeBnfcrAsCollateral - coin futures skip BNFCR
  • BnfcrZeroBalanceIncludesSupplementaryCollateral - BNFCR=0, USDC=100
  • BtcCollateralConvertedToQuoteCurrency - BTC collateral converted via market price
  • DefaultMarginModelDoesNotIncludeSupplementaryCollateral - non-Binance brokerage

Regression algorithm: BinanceCryptoFutureBnfcrCollateralRegressionAlgorithm

Live tested with Binance EU account (Credits Trading Mode, multiAssetsMargin: true).

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 7 commits April 9, 2026 17:46
Replace IsStableCoinWithoutPair foreach loop with a single TryGetValue
check for BNFCR. BNFCR is EU/EEA-only (MiCA Credits Trading Mode) so
the lookup is a no-op for all other users. Amount reflects availableBalance
from the Binance API — the total cross-margin pool already aggregated by
Binance — making the > 0 guard correct and avoiding CashBook iteration.
…e USDⓈ-M futures

Asserts end-to-end that EU/MiCA accounts with zero USDT and BNFCR as
the only collateral can open ADAUSDT positions. Verifies buying power,
holdings AbsoluteHoldingsCost, TotalSaleVolume, TotalMarginUsed,
maintenance margin consistency and TotalUnrealizedProfit accuracy.
…ry collateral

Replace IsStableCoinWithoutPair and hardcoded asset list with CashBook
iteration gated by BNFCR presence. Binance controls which assets are in
the account — all with non-zero walletBalance are valid collateral.
Add tests for BNFCR zero balance and BTC collateral conversion.
…BNFCR mode

- Extract virtual SharesCollateral in CryptoFutureMarginModel
- Override in BinanceCryptoFutureMarginModel: BNFCR present → all USDⓈ-M share pool
- Add BNFCRCurrency const
- Add SharedCollateralDeductsMaintenanceMarginAcrossQuoteCurrencies unit test
- Refactor regression algorithm to assert shared collateral across ADAUSDT/ETHUSDC
…reMarginModel

- Remove IsCryptoCoinFuture() check (coin futures use BinanceCoinFuturesBrokerageModel, not this model)
- Call base.GetTotalCollateralAmount() instead of duplicating primaryCollateral.Amount
- Remove CoinFutureDoesNotIncludeBnfcrAsCollateral test (tested wrong margin model)
- No longer accessed by subclasses after removing direct collateral checks from BinanceCryptoFutureMarginModel
@Romazes Romazes merged commit 9b2a793 into QuantConnect:master Apr 13, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

critical BUG, market order in QC is only submitted , but in Binance is FILLED

2 participants