Skip to content

Commit

Permalink
refactor: move test_liquidation_price_binance to binance test file
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Aug 24, 2024
1 parent d1bc519 commit 1b70568
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 105 deletions.
105 changes: 105 additions & 0 deletions tests/exchange/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,111 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
assert not exchange.stoploss_adjust(sl2, order, side=side)


@pytest.mark.parametrize(
"exchange_name, is_short, trading_mode, margin_mode, wallet_balance, "
"mm_ex_1, upnl_ex_1, maintenance_amt, amount, open_rate, "
"mm_ratio, expected",
[
(
"binance",
False,
"futures",
"isolated",
1535443.01,
0.0,
0.0,
135365.00,
3683.979,
1456.84,
0.10,
1114.78,
),
(
"binance",
False,
"futures",
"isolated",
1535443.01,
0.0,
0.0,
16300.000,
109.488,
32481.980,
0.025,
18778.73,
),
(
"binance",
False,
"futures",
"cross",
1535443.01,
71200.81144,
-56354.57,
135365.00,
3683.979,
1456.84,
0.10,
1153.26,
),
(
"binance",
False,
"futures",
"cross",
1535443.01,
356512.508,
-448192.89,
16300.000,
109.488,
32481.980,
0.025,
26316.89,
),
],
)
def test_liquidation_price_binance(
mocker,
default_conf,
exchange_name,
open_rate,
is_short,
trading_mode,
margin_mode,
wallet_balance,
mm_ex_1,
upnl_ex_1,
maintenance_amt,
amount,
mm_ratio,
expected,
):
default_conf["trading_mode"] = trading_mode
default_conf["margin_mode"] = margin_mode
default_conf["liquidation_buffer"] = 0.0
exchange = get_patched_exchange(mocker, default_conf, exchange=exchange_name)
exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(mm_ratio, maintenance_amt))
assert (
pytest.approx(
round(
exchange.get_liquidation_price(
pair="DOGE/USDT",
open_rate=open_rate,
is_short=is_short,
wallet_balance=wallet_balance,
mm_ex_1=mm_ex_1,
upnl_ex_1=upnl_ex_1,
amount=amount,
stake_amount=open_rate * amount,
leverage=5,
),
2,
)
)
== expected
)


def test_fill_leverage_tiers_binance(default_conf, mocker):
api_mock = MagicMock()
api_mock.fetch_leverage_tiers = MagicMock(
Expand Down
105 changes: 0 additions & 105 deletions tests/exchange/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -5667,111 +5667,6 @@ def test_liquidation_price_is_none(
)


@pytest.mark.parametrize(
"exchange_name, is_short, trading_mode, margin_mode, wallet_balance, "
"mm_ex_1, upnl_ex_1, maintenance_amt, amount, open_rate, "
"mm_ratio, expected",
[
(
"binance",
False,
"futures",
"isolated",
1535443.01,
0.0,
0.0,
135365.00,
3683.979,
1456.84,
0.10,
1114.78,
),
(
"binance",
False,
"futures",
"isolated",
1535443.01,
0.0,
0.0,
16300.000,
109.488,
32481.980,
0.025,
18778.73,
),
(
"binance",
False,
"futures",
"cross",
1535443.01,
71200.81144,
-56354.57,
135365.00,
3683.979,
1456.84,
0.10,
1153.26,
),
(
"binance",
False,
"futures",
"cross",
1535443.01,
356512.508,
-448192.89,
16300.000,
109.488,
32481.980,
0.025,
26316.89,
),
],
)
def test_liquidation_price_binance(
mocker,
default_conf,
exchange_name,
open_rate,
is_short,
trading_mode,
margin_mode,
wallet_balance,
mm_ex_1,
upnl_ex_1,
maintenance_amt,
amount,
mm_ratio,
expected,
):
default_conf["trading_mode"] = trading_mode
default_conf["margin_mode"] = margin_mode
default_conf["liquidation_buffer"] = 0.0
exchange = get_patched_exchange(mocker, default_conf, exchange=exchange_name)
exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(mm_ratio, maintenance_amt))
assert (
pytest.approx(
round(
exchange.get_liquidation_price(
pair="DOGE/USDT",
open_rate=open_rate,
is_short=is_short,
wallet_balance=wallet_balance,
mm_ex_1=mm_ex_1,
upnl_ex_1=upnl_ex_1,
amount=amount,
stake_amount=open_rate * amount,
leverage=5,
),
2,
)
)
== expected
)


def test_get_max_pair_stake_amount(
mocker,
default_conf,
Expand Down

0 comments on commit 1b70568

Please sign in to comment.