From 13e9f8a98e9b023435b6ed4b57040c641379e64d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 2 Mar 2025 14:17:12 +0100 Subject: [PATCH] fix: use initialMargin over collateral for position wallet closes #11415 --- freqtrade/wallets.py | 2 +- tests/rpc/test_rpc.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index c77b27147..cb0887415 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -197,7 +197,7 @@ class Wallets: # Position is not open ... continue size = self._exchange._contracts_to_amount(symbol, position["contracts"]) - collateral = safe_value_fallback(position, "collateral", "initialMargin", 0.0) + collateral = safe_value_fallback(position, "initialMargin", "collateral", 0.0) leverage = position.get("leverage") _parsed_positions[symbol] = PositionWallet( symbol, diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 71eaa3bfd..cb67d089e 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -577,7 +577,7 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg "symbol": "ETH/USDT:USDT", "timestamp": None, "datetime": None, - "initialMargin": 0.0, + "initialMargin": 20, "initialMarginPercentage": None, "maintenanceMargin": 0.0, "maintenanceMarginPercentage": 0.005, @@ -590,8 +590,9 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg "marginRatio": None, "liquidationPrice": 0.0, "markPrice": 2896.41, - "collateral": 20, - "marginType": "isolated", + # Collateral is in USDT - and can be higher than position size in cross mode + "collateral": 50, + "marginType": "cross", "side": "short", "percentage": None, }