test: switch futures position to ADA
This commit is contained in:
+24
-16
@@ -609,6 +609,8 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
"used": 5.0,
|
"used": 5.0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
# Fake ADA response
|
||||||
|
tickers.return_value["ADA/USDT"] = tickers.return_value["ETH/USDT"]
|
||||||
if proxy_coin:
|
if proxy_coin:
|
||||||
default_conf_usdt["proxy_coin"] = proxy_coin
|
default_conf_usdt["proxy_coin"] = proxy_coin
|
||||||
mock_balance[proxy_coin] = {
|
mock_balance[proxy_coin] = {
|
||||||
@@ -617,12 +619,13 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
"used": 0.0,
|
"used": 0.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Current ADA price based on Tickers is 530.21 USDT
|
||||||
mock_pos = [
|
mock_pos = [
|
||||||
{
|
{
|
||||||
"symbol": "ETH/USDT:USDT",
|
"symbol": "ADA/USDT:USDT",
|
||||||
"timestamp": None,
|
"timestamp": None,
|
||||||
"datetime": None,
|
"datetime": None,
|
||||||
"initialMargin": 20,
|
"initialMargin": 50,
|
||||||
"initialMarginPercentage": None,
|
"initialMarginPercentage": None,
|
||||||
"maintenanceMargin": 0.0,
|
"maintenanceMargin": 0.0,
|
||||||
"maintenanceMarginPercentage": 0.005,
|
"maintenanceMarginPercentage": 0.005,
|
||||||
@@ -630,13 +633,13 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
"notional": 10.0,
|
"notional": 10.0,
|
||||||
"leverage": 5.0,
|
"leverage": 5.0,
|
||||||
"unrealizedPnl": 0.0,
|
"unrealizedPnl": 0.0,
|
||||||
"contracts": 1.0,
|
"contracts": 0.48,
|
||||||
"contractSize": 1,
|
"contractSize": 1,
|
||||||
"marginRatio": None,
|
"marginRatio": None,
|
||||||
"liquidationPrice": 0.0,
|
"liquidationPrice": 0.0,
|
||||||
"markPrice": 2896.41,
|
"markPrice": 520, # Entry price ...
|
||||||
# Collateral is in USDT - and can be higher than position size in cross mode
|
# Collateral is in USDT - and can be higher than position size in cross mode
|
||||||
"collateral": 50,
|
"collateral": 100,
|
||||||
"marginType": "cross",
|
"marginType": "cross",
|
||||||
"side": "short" if is_short else "long",
|
"side": "short" if is_short else "long",
|
||||||
"percentage": None,
|
"percentage": None,
|
||||||
@@ -653,6 +656,7 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
get_valid_pair_combination=MagicMock(
|
get_valid_pair_combination=MagicMock(
|
||||||
side_effect=lambda a, b: [f"{b}/{a}" if a == "USDT" else f"{a}/{b}"]
|
side_effect=lambda a, b: [f"{b}/{a}" if a == "USDT" else f"{a}/{b}"]
|
||||||
),
|
),
|
||||||
|
_contracts_to_amount=MagicMock(side_effect=lambda c, cs: cs),
|
||||||
)
|
)
|
||||||
default_conf_usdt["dry_run"] = False
|
default_conf_usdt["dry_run"] = False
|
||||||
default_conf_usdt["trading_mode"] = "futures"
|
default_conf_usdt["trading_mode"] = "futures"
|
||||||
@@ -665,7 +669,7 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
mocker.patch(
|
mocker.patch(
|
||||||
"freqtrade.persistence.trade_model.Trade.get_open_trades",
|
"freqtrade.persistence.trade_model.Trade.get_open_trades",
|
||||||
return_value=[
|
return_value=[
|
||||||
MagicMock(pair="ETH/USDT:USDT", safe_base_currency="ETH"),
|
MagicMock(pair="ADA/USDT:USDT", safe_base_currency="ADA"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
result = rpc._rpc_balance(
|
result = rpc._rpc_balance(
|
||||||
@@ -735,13 +739,13 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
"is_position": False,
|
"is_position": False,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"currency": "ETH/USDT:USDT",
|
"currency": "ADA/USDT:USDT",
|
||||||
"free": 0,
|
"free": 0,
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
"used": 0,
|
"used": 0,
|
||||||
"position": 10.0,
|
"position": 0.48,
|
||||||
"est_stake": 5222.1,
|
"est_stake": pytest.approx(45.4992 if is_short else 54.5008),
|
||||||
"est_stake_bot": 5222.1,
|
"est_stake_bot": pytest.approx(45.4992 if is_short else 54.5008),
|
||||||
"stake": "USDT",
|
"stake": "USDT",
|
||||||
"side": "short" if is_short else "long",
|
"side": "short" if is_short else "long",
|
||||||
"is_bot_managed": True,
|
"is_bot_managed": True,
|
||||||
@@ -803,15 +807,19 @@ def test_rpc_balance_handle(default_conf_usdt, mocker, tickers, proxy_coin, marg
|
|||||||
|
|
||||||
assert result["currencies"] == expected_curr
|
assert result["currencies"] == expected_curr
|
||||||
if proxy_coin and margin_mode == "cross":
|
if proxy_coin and margin_mode == "cross":
|
||||||
assert pytest.approx(result["total_bot"]) == 6707.1
|
# only USDT and ADA position are bot-managed
|
||||||
assert pytest.approx(result["total"]) == 7388.7972 # ETH stake is missing.
|
assert pytest.approx(result["total_bot"]) == (1530.4992 if is_short else 1539.5008)
|
||||||
|
assert pytest.approx(result["total"]) == (2212.19640 if is_short else 2221.198)
|
||||||
assert result["starting_capital"] == 1500 * default_conf_usdt["tradable_balance_ratio"]
|
assert result["starting_capital"] == 1500 * default_conf_usdt["tradable_balance_ratio"]
|
||||||
assert result["starting_capital_ratio"] == pytest.approx(3.5165656)
|
assert result["starting_capital_ratio"] == pytest.approx(
|
||||||
|
0.03063919 if is_short else 0.03670087
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
assert pytest.approx(result["total_bot"]) == 5271.6
|
# only USDT and ADA position are bot-managed
|
||||||
assert pytest.approx(result["total"]) == 5888.7972 # ETH stake is missing.
|
assert pytest.approx(result["total_bot"]) == (94.9992 if is_short else 104.0008)
|
||||||
|
assert pytest.approx(result["total"]) == (712.1964 if is_short else 721.1980)
|
||||||
assert result["starting_capital"] == 50 * default_conf_usdt["tradable_balance_ratio"]
|
assert result["starting_capital"] == 50 * default_conf_usdt["tradable_balance_ratio"]
|
||||||
assert result["starting_capital_ratio"] == pytest.approx(105.496969)
|
assert result["starting_capital_ratio"] == pytest.approx(0.919175 if is_short else 1.101026)
|
||||||
assert pytest.approx(result["value"]) == result["total"] * 1.2
|
assert pytest.approx(result["value"]) == result["total"] * 1.2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user