get_max_pair_stake_amount_tests
This commit is contained in:
parent
8c680d75b9
commit
c5cfd971f5
@ -342,7 +342,7 @@ def test_price_get_one_pip(default_conf, mocker, price, precision_mode, precisio
|
|||||||
assert pytest.approx(exchange.price_get_one_pip(pair, price)) == expected
|
assert pytest.approx(exchange.price_get_one_pip(pair, price)) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
stoploss = -0.05
|
stoploss = -0.05
|
||||||
@ -356,7 +356,7 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
with pytest.raises(ValueError, match=r'.*get market information.*'):
|
with pytest.raises(ValueError, match=r'.*get market information.*'):
|
||||||
exchange.get_min_pair_stake_amount('BNB/BTC', 1, stoploss)
|
exchange.get_min_pair_stake_amount('BNB/BTC', 1, stoploss)
|
||||||
|
|
||||||
# no cost Min
|
# no cost/amount Min
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
'cost': {'min': None, 'max': None},
|
'cost': {'min': None, 'max': None},
|
||||||
'amount': {'min': None, 'max': None},
|
'amount': {'min': None, 'max': None},
|
||||||
@ -367,51 +367,33 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
)
|
)
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||||
assert result is None
|
assert result is None
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||||
|
assert result == float('inf')
|
||||||
|
|
||||||
# no amount Min
|
# min/max cost is set
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
'cost': {'min': None, 'max': None},
|
'cost': {'min': 2, 'max': 10000},
|
||||||
'amount': {'min': None, 'max': None},
|
|
||||||
}
|
|
||||||
mocker.patch(
|
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
|
||||||
assert result is None
|
|
||||||
|
|
||||||
# empty 'cost'/'amount' section
|
|
||||||
markets["ETH/BTC"]["limits"] = {
|
|
||||||
'cost': {'min': None, 'max': None},
|
|
||||||
'amount': {'min': None, 'max': None},
|
|
||||||
}
|
|
||||||
mocker.patch(
|
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
|
||||||
assert result is None
|
|
||||||
|
|
||||||
# min cost is set
|
|
||||||
markets["ETH/BTC"]["limits"] = {
|
|
||||||
'cost': {'min': 2, 'max': None},
|
|
||||||
'amount': {'min': None, 'max': None},
|
'amount': {'min': None, 'max': None},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.markets',
|
'freqtrade.exchange.Exchange.markets',
|
||||||
PropertyMock(return_value=markets)
|
PropertyMock(return_value=markets)
|
||||||
)
|
)
|
||||||
|
# min
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||||
expected_result = 2 * (1+0.05) / (1-abs(stoploss))
|
expected_result = 2 * (1+0.05) / (1-abs(stoploss))
|
||||||
assert isclose(result, expected_result)
|
assert isclose(result, expected_result)
|
||||||
# With Leverage
|
# With Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss, 3.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss, 3.0)
|
||||||
assert isclose(result, expected_result/3)
|
assert isclose(result, expected_result/3)
|
||||||
|
# max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
|
assert result == 10000
|
||||||
|
|
||||||
# min amount is set
|
# min amount is set
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
'cost': {'min': None, 'max': None},
|
'cost': {'min': None, 'max': None},
|
||||||
'amount': {'min': 2, 'max': None},
|
'amount': {'min': 2, 'max': 10000},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.markets',
|
'freqtrade.exchange.Exchange.markets',
|
||||||
@ -423,6 +405,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# With Leverage
|
# With Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 5.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 5.0)
|
||||||
assert isclose(result, expected_result/5)
|
assert isclose(result, expected_result/5)
|
||||||
|
# max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
|
assert result == 20000
|
||||||
|
|
||||||
# min amount and cost are set (cost is minimal)
|
# min amount and cost are set (cost is minimal)
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
@ -442,8 +427,8 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
|
|
||||||
# min amount and cost are set (amount is minial)
|
# min amount and cost are set (amount is minial)
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
'cost': {'min': 8, 'max': None},
|
'cost': {'min': 8, 'max': 10000},
|
||||||
'amount': {'min': 2, 'max': None},
|
'amount': {'min': 2, 'max': 500},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.markets',
|
'freqtrade.exchange.Exchange.markets',
|
||||||
@ -455,6 +440,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# With Leverage
|
# With Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 7.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 7.0)
|
||||||
assert isclose(result, expected_result/7.0)
|
assert isclose(result, expected_result/7.0)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
|
assert result == 1000
|
||||||
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4)
|
||||||
expected_result = max(8, 2 * 2) * 1.5
|
expected_result = max(8, 2 * 2) * 1.5
|
||||||
@ -462,6 +450,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# With Leverage
|
# With Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4, 8.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4, 8.0)
|
||||||
assert isclose(result, expected_result/8.0)
|
assert isclose(result, expected_result/8.0)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
|
assert result == 1000
|
||||||
|
|
||||||
# Really big stoploss
|
# Really big stoploss
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
||||||
@ -470,6 +461,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# With Leverage
|
# With Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
||||||
assert isclose(result, expected_result/12)
|
assert isclose(result, expected_result/12)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
|
assert result == 1000
|
||||||
|
|
||||||
markets["ETH/BTC"]["contractSize"] = '0.01'
|
markets["ETH/BTC"]["contractSize"] = '0.01'
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
@ -483,6 +477,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# Contract size 0.01
|
# Contract size 0.01
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
||||||
assert isclose(result, expected_result * 0.01)
|
assert isclose(result, expected_result * 0.01)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, -1)
|
||||||
|
assert result == 10
|
||||||
|
|
||||||
markets["ETH/BTC"]["contractSize"] = '10'
|
markets["ETH/BTC"]["contractSize"] = '10'
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
@ -492,6 +489,9 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
|
|||||||
# With Leverage, Contract size 10
|
# With Leverage, Contract size 10
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
||||||
assert isclose(result, (expected_result/12) * 10.0)
|
assert isclose(result, (expected_result/12) * 10.0)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, -1)
|
||||||
|
assert result == 10000
|
||||||
|
|
||||||
|
|
||||||
def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
||||||
@ -499,10 +499,10 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
|||||||
stoploss = -0.05
|
stoploss = -0.05
|
||||||
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
|
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
|
||||||
|
|
||||||
# Real Binance data
|
# ~Real Binance data
|
||||||
markets["ETH/BTC"]["limits"] = {
|
markets["ETH/BTC"]["limits"] = {
|
||||||
'cost': {'min': 0.0001},
|
'cost': {'min': 0.0001, 'max': 4000},
|
||||||
'amount': {'min': 0.001}
|
'amount': {'min': 0.001, 'max': 10000},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.markets',
|
'freqtrade.exchange.Exchange.markets',
|
||||||
@ -511,9 +511,23 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
|||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss)
|
||||||
expected_result = max(0.0001, 0.001 * 0.020405) * (1+0.05) / (1-abs(stoploss))
|
expected_result = max(0.0001, 0.001 * 0.020405) * (1+0.05) / (1-abs(stoploss))
|
||||||
assert round(result, 8) == round(expected_result, 8)
|
assert round(result, 8) == round(expected_result, 8)
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2.0, stoploss)
|
||||||
|
assert result == 4000
|
||||||
|
|
||||||
|
# Leverage
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss, 3.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss, 3.0)
|
||||||
assert round(result, 8) == round(expected_result/3, 8)
|
assert round(result, 8) == round(expected_result/3, 8)
|
||||||
|
|
||||||
|
# Contract_size
|
||||||
|
markets["ETH/BTC"]["contractSize"] = 0.1
|
||||||
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss, 3.0)
|
||||||
|
assert round(result, 8) == round((expected_result/3), 8)
|
||||||
|
|
||||||
|
# Max
|
||||||
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 12.0, stoploss)
|
||||||
|
assert result == 4000
|
||||||
|
|
||||||
|
|
||||||
def test_set_sandbox(default_conf, mocker):
|
def test_set_sandbox(default_conf, mocker):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user