Merge pull request #2576 from hroff-1902/fix/get_min_pair_stake_amount

Fix _get_min_pair_stake_amount
This commit is contained in:
Matthias 2019-11-27 19:28:52 +01:00 committed by GitHub
commit bcec070ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 14 deletions

View File

@ -266,7 +266,11 @@ class FreqtradeBot:
amount_reserve_percent += self.strategy.stoploss amount_reserve_percent += self.strategy.stoploss
# it should not be more than 50% # it should not be more than 50%
amount_reserve_percent = max(amount_reserve_percent, 0.5) amount_reserve_percent = max(amount_reserve_percent, 0.5)
return min(min_stake_amounts) / amount_reserve_percent
# The value returned should satisfy both limits: for amount (base currency) and
# for cost (quote, stake currency), so max() is used here.
# See also #2575 at github.
return max(min_stake_amounts) / amount_reserve_percent
def create_trades(self) -> bool: def create_trades(self) -> bool:
""" """

View File

@ -325,7 +325,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -351,7 +351,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -376,7 +376,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -401,7 +401,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -426,7 +426,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -451,7 +451,7 @@ def get_markets():
}, },
'price': 500000, 'price': 500000,
'cost': { 'cost': {
'min': 1, 'min': 0.0001,
'max': 500000, 'max': 500000,
}, },
}, },
@ -479,7 +479,7 @@ def get_markets():
'max': None 'max': None
}, },
'cost': { 'cost': {
'min': 0.001, 'min': 0.0001,
'max': None 'max': None
} }
}, },

View File

@ -299,7 +299,7 @@ def test_total_open_trades_stakes(mocker, default_conf, ticker,
limit_buy_order, fee) -> None: limit_buy_order, fee) -> None:
patch_RPCManager(mocker) patch_RPCManager(mocker)
patch_exchange(mocker) patch_exchange(mocker)
default_conf['stake_amount'] = 0.0000098751 default_conf['stake_amount'] = 0.00098751
default_conf['max_open_trades'] = 2 default_conf['max_open_trades'] = 2
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',
@ -313,7 +313,7 @@ def test_total_open_trades_stakes(mocker, default_conf, ticker,
trade = Trade.query.first() trade = Trade.query.first()
assert trade is not None assert trade is not None
assert trade.stake_amount == 0.0000098751 assert trade.stake_amount == 0.00098751
assert trade.is_open assert trade.is_open
assert trade.open_date is not None assert trade.open_date is not None
@ -321,11 +321,11 @@ def test_total_open_trades_stakes(mocker, default_conf, ticker,
trade = Trade.query.order_by(Trade.id.desc()).first() trade = Trade.query.order_by(Trade.id.desc()).first()
assert trade is not None assert trade is not None
assert trade.stake_amount == 0.0000098751 assert trade.stake_amount == 0.00098751
assert trade.is_open assert trade.is_open
assert trade.open_date is not None assert trade.open_date is not None
assert Trade.total_open_trades_stakes() == 1.97502e-05 assert Trade.total_open_trades_stakes() == 1.97502e-03
def test_get_min_pair_stake_amount(mocker, default_conf) -> None: def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
@ -334,6 +334,7 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
freqtrade = FreqtradeBot(default_conf) freqtrade = FreqtradeBot(default_conf)
freqtrade.strategy.stoploss = -0.05 freqtrade.strategy.stoploss = -0.05
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}} markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
# no pair found # no pair found
mocker.patch( mocker.patch(
'freqtrade.exchange.Exchange.markets', 'freqtrade.exchange.Exchange.markets',
@ -425,7 +426,7 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
PropertyMock(return_value=markets) PropertyMock(return_value=markets)
) )
result = freqtrade._get_min_pair_stake_amount('ETH/BTC', 2) result = freqtrade._get_min_pair_stake_amount('ETH/BTC', 2)
assert result == min(2, 2 * 2) / 0.9 assert result == max(2, 2 * 2) / 0.9
# 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"] = {
@ -437,7 +438,27 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
PropertyMock(return_value=markets) PropertyMock(return_value=markets)
) )
result = freqtrade._get_min_pair_stake_amount('ETH/BTC', 2) result = freqtrade._get_min_pair_stake_amount('ETH/BTC', 2)
assert result == min(8, 2 * 2) / 0.9 assert result == max(8, 2 * 2) / 0.9
def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
freqtrade = FreqtradeBot(default_conf)
freqtrade.strategy.stoploss = -0.05
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
# Real Binance data
markets["ETH/BTC"]["limits"] = {
'cost': {'min': 0.0001},
'amount': {'min': 0.001}
}
mocker.patch(
'freqtrade.exchange.Exchange.markets',
PropertyMock(return_value=markets)
)
result = freqtrade._get_min_pair_stake_amount('ETH/BTC', 0.020405)
assert round(result, 8) == round(max(0.0001, 0.001 * 0.020405) / 0.9, 8)
def test_create_trades(default_conf, ticker, limit_buy_order, fee, mocker) -> None: def test_create_trades(default_conf, ticker, limit_buy_order, fee, mocker) -> None: