Files
Roman Yavnikov 9b2a793709 fix: support BNFCR alternative collateral in CryptoFutureMarginModel for Binance (#9373)
* fix: support BNFCR alternative collateral in CryptoFutureMarginModel for Binance (#9339)

* refactor: use classic switch in BinanceFuturesBrokerageModel.GetBuyingPowerModel

* fix: CryptoFutureMarginModel in BinanceCoinFuturesBrokerageModel

* refactor: simplify BinanceCryptoFutureMarginModel collateral conversion

* fix: restore IsCryptoCoinFuture guard in BinanceCryptoFutureMarginModel

* refactor: simplify BinanceCryptoFutureMarginModel to direct BNFCR lookup

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.

* feat: add regression algorithm for BNFCR as sole collateral on Binance 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.

* refactor: BNFCR presence gate with CashBook iteration for supplementary 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.

* refactor: aggregate all collateral without reference equality check

* fix: shared collateral deduction across quote currencies for EU/MiCA 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

* refactor: remove dead IsCryptoCoinFuture guard from BinanceCryptoFutureMarginModel

- 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)

* refactor: make GetCollateralCash private in CryptoFutureMarginModel

- No longer accessed by subclasses after removing direct collateral checks from BinanceCryptoFutureMarginModel
2026-04-13 23:24:40 +03:00
..
2018-06-22 21:43:55 +02:00
2026-01-14 11:55:29 -03:00
2026-01-14 11:55:29 -03:00