Implemented fill_leverage_brackets get_max_leverage and set_leverage for binance, kraken and ftx. Wrote tests test_apply_leverage_to_stake_amount and test_get_max_leverage
This commit is contained in:
@@ -106,3 +106,48 @@ def test_stoploss_adjust_binance(mocker, default_conf):
|
||||
# Test with invalid order case
|
||||
order['type'] = 'stop_loss'
|
||||
assert not exchange.stoploss_adjust(1501, order, side="sell")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pair,nominal_value,max_lev', [
|
||||
("BNB/BUSD", 0.0, 40.0),
|
||||
("BNB/USDT", 100.0, 153.84615384615384),
|
||||
("BTC/USDT", 170.30, 250.0),
|
||||
("BNB/BUSD", 999999.9, 10.0),
|
||||
("BNB/USDT", 5000000.0, 6.666666666666667),
|
||||
("BTC/USDT", 300000000.1, 2.0),
|
||||
])
|
||||
def test_get_max_leverage_binance(
|
||||
default_conf,
|
||||
mocker,
|
||||
pair,
|
||||
nominal_value,
|
||||
max_lev
|
||||
):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||
exchange._leverage_brackets = {
|
||||
'BNB/BUSD': [[0.0, 0.025],
|
||||
[100000.0, 0.05],
|
||||
[500000.0, 0.1],
|
||||
[1000000.0, 0.15],
|
||||
[2000000.0, 0.25],
|
||||
[5000000.0, 0.5]],
|
||||
'BNB/USDT': [[0.0, 0.0065],
|
||||
[10000.0, 0.01],
|
||||
[50000.0, 0.02],
|
||||
[250000.0, 0.05],
|
||||
[1000000.0, 0.1],
|
||||
[2000000.0, 0.125],
|
||||
[5000000.0, 0.15],
|
||||
[10000000.0, 0.25]],
|
||||
'BTC/USDT': [[0.0, 0.004],
|
||||
[50000.0, 0.005],
|
||||
[250000.0, 0.01],
|
||||
[1000000.0, 0.025],
|
||||
[5000000.0, 0.05],
|
||||
[20000000.0, 0.1],
|
||||
[50000000.0, 0.125],
|
||||
[100000000.0, 0.15],
|
||||
[200000000.0, 0.25],
|
||||
[300000000.0, 0.5]],
|
||||
}
|
||||
assert exchange.get_max_leverage(pair, nominal_value) == max_lev
|
||||
|
@@ -442,11 +442,6 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
||||
)
|
||||
|
||||
|
||||
def apply_leverage_to_stake_amount():
|
||||
# TODO-lev
|
||||
return
|
||||
|
||||
|
||||
def test_set_sandbox(default_conf, mocker):
|
||||
"""
|
||||
Test working scenario
|
||||
@@ -2893,7 +2888,61 @@ def test_calculate_backoff(retrycount, max_retries, expected):
|
||||
assert calculate_backoff(retrycount, max_retries) == expected
|
||||
|
||||
|
||||
def test_get_max_leverage():
|
||||
@pytest.mark.parametrize('exchange,stake_amount,leverage,min_stake_with_lev', [
|
||||
('binance', 9.0, 3.0, 3.0),
|
||||
('binance', 20.0, 5.0, 4.0),
|
||||
('binance', 100.0, 100.0, 1.0),
|
||||
# Kraken
|
||||
('kraken', 9.0, 3.0, 9.0),
|
||||
('kraken', 20.0, 5.0, 20.0),
|
||||
('kraken', 100.0, 100.0, 100.0),
|
||||
# FTX
|
||||
# TODO-lev: - implement FTX tests
|
||||
# ('ftx', 9.0, 3.0, 10.0),
|
||||
# ('ftx', 20.0, 5.0, 20.0),
|
||||
# ('ftx', 100.0, 100.0, 100.0),
|
||||
])
|
||||
def test_apply_leverage_to_stake_amount(
|
||||
exchange,
|
||||
stake_amount,
|
||||
leverage,
|
||||
min_stake_with_lev,
|
||||
mocker,
|
||||
default_conf
|
||||
):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange)
|
||||
assert exchange._apply_leverage_to_stake_amount(stake_amount, leverage) == min_stake_with_lev
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange_name,pair,nominal_value,max_lev', [
|
||||
# Kraken
|
||||
("kraken", "ADA/BTC", 0.0, 3.0),
|
||||
("kraken", "BTC/EUR", 100.0, 5.0),
|
||||
("kraken", "ZEC/USD", 173.31, 2.0),
|
||||
# FTX
|
||||
("ftx", "ADA/BTC", 0.0, 20.0),
|
||||
("ftx", "BTC/EUR", 100.0, 20.0),
|
||||
("ftx", "ZEC/USD", 173.31, 20.0),
|
||||
# Binance tests this method inside it's own test file
|
||||
])
|
||||
def test_get_max_leverage(
|
||||
default_conf,
|
||||
mocker,
|
||||
exchange_name,
|
||||
pair,
|
||||
nominal_value,
|
||||
max_lev
|
||||
):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||
exchange._leverage_brackets = {
|
||||
'ADA/BTC': ['2', '3'],
|
||||
'BTC/EUR': ['2', '3', '4', '5'],
|
||||
'ZEC/USD': ['2']
|
||||
}
|
||||
assert exchange.get_max_leverage(pair, nominal_value) == max_lev
|
||||
|
||||
|
||||
def test_fill_leverage_brackets():
|
||||
# TODO-lev
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user