test: update binance test

This commit is contained in:
Matthias
2024-08-31 08:20:51 +02:00
parent 1473abf19a
commit 0d5919392e
+35 -10
View File
@@ -171,11 +171,12 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"is_short, trading_mode, margin_mode, wallet_balance, " "pair, is_short, trading_mode, margin_mode, wallet_balance, "
"maintenance_amt, amount, open_rate, mark_price, other_contracts," "maintenance_amt, amount, open_rate, mark_price, open_trades,"
"mm_ratio, expected", "mm_ratio, expected",
[ [
( (
"ETH/USDT:USDT",
False, False,
"futures", "futures",
"isolated", "isolated",
@@ -189,6 +190,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
1114.78, 1114.78,
), ),
( (
"ETH/USDT:USDT",
False, False,
"futures", "futures",
"isolated", "isolated",
@@ -202,6 +204,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
18778.73, 18778.73,
), ),
( (
"ETH/USDT:USDT",
False, False,
"futures", "futures",
"cross", "cross",
@@ -222,12 +225,23 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
"mark_price": 31967.27, "mark_price": 31967.27,
"mm_ratio": 0.025, "mm_ratio": 0.025,
"maintenance_amt": 16300.0, "maintenance_amt": 16300.0,
} },
{
# From calc example
"pair": "ETH/USDT:USDT",
"open_rate": 1456.84,
"amount": 3683.979,
"stake_amount": 5366967.96,
"mark_price": 1335.18,
"mm_ratio": 0.10,
"maintenance_amt": 135365.00,
},
], ],
0.10, 0.10,
1153.26, 1153.26,
), ),
( (
"BTC/USDT:USDT",
False, False,
"futures", "futures",
"cross", "cross",
@@ -239,6 +253,16 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
32481.980, # open_rate 32481.980, # open_rate
31967.27, # mark_price 31967.27, # mark_price
[ [
{
# From calc example
"pair": "BTC/USDT:USDT",
"open_rate": 32481.98,
"amount": 109.488,
"stake_amount": 3556387.02624, # open_rate * amount
"mark_price": 31967.27,
"mm_ratio": 0.025,
"maintenance_amt": 16300.0,
},
{ {
# From calc example # From calc example
"pair": "ETH/USDT:USDT", "pair": "ETH/USDT:USDT",
@@ -248,7 +272,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
"mark_price": 1335.18, "mark_price": 1335.18,
"mm_ratio": 0.10, "mm_ratio": 0.10,
"maintenance_amt": 135365.00, "maintenance_amt": 135365.00,
} },
], ],
0.025, 0.025,
26316.89, 26316.89,
@@ -258,6 +282,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
def test_liquidation_price_binance( def test_liquidation_price_binance(
mocker, mocker,
default_conf, default_conf,
pair,
is_short, is_short,
trading_mode, trading_mode,
margin_mode, margin_mode,
@@ -266,7 +291,7 @@ def test_liquidation_price_binance(
amount, amount,
open_rate, open_rate,
mark_price, mark_price,
other_contracts, open_trades,
mm_ratio, mm_ratio,
expected, expected,
): ):
@@ -275,9 +300,9 @@ def test_liquidation_price_binance(
default_conf["liquidation_buffer"] = 0.0 default_conf["liquidation_buffer"] = 0.0
exchange = get_patched_exchange(mocker, default_conf, exchange="binance") exchange = get_patched_exchange(mocker, default_conf, exchange="binance")
def get_maint_ratio(pair, stake_amount): def get_maint_ratio(pair_, stake_amount):
if pair != "DOGE/USDT": if pair_ != pair:
oc = [c for c in other_contracts if c["pair"] == pair][0] oc = [c for c in open_trades if c["pair"] == pair_][0]
return oc["mm_ratio"], oc["maintenance_amt"] return oc["mm_ratio"], oc["maintenance_amt"]
return mm_ratio, maintenance_amt return mm_ratio, maintenance_amt
@@ -286,14 +311,14 @@ def test_liquidation_price_binance(
pytest.approx( pytest.approx(
round( round(
exchange.get_liquidation_price( exchange.get_liquidation_price(
pair="DOGE/USDT", pair=pair,
open_rate=open_rate, open_rate=open_rate,
is_short=is_short, is_short=is_short,
wallet_balance=wallet_balance, wallet_balance=wallet_balance,
amount=amount, amount=amount,
stake_amount=open_rate * amount, stake_amount=open_rate * amount,
leverage=5, leverage=5,
other_trades=other_contracts, open_trades=open_trades,
), ),
2, 2,
) )