Refactoring to use strategy based configuration

This commit is contained in:
Reigo Reinmets
2021-12-24 12:38:43 +02:00
parent ac690e9215
commit de79d25caf
13 changed files with 117 additions and 200 deletions

View File

@@ -17,7 +17,6 @@ def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) ->
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
patch_exchange(mocker)
default_conf.update({
"position_adjustment_enable": True,
"stake_amount": 100.0,
"dry_run_wallet": 1000.0,
"strategy": "StrategyTestV2"
@@ -28,6 +27,7 @@ def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) ->
timerange = TimeRange('date', None, 1517227800, 0)
data = history.load_data(datadir=testdatadir, timeframe='5m', pairs=['UNITTEST/BTC'],
timerange=timerange)
backtesting.strategy.position_adjustment_enable = True
processed = backtesting.strategy.advise_all_indicators(data)
min_date, max_date = get_timerange(processed)
result = backtesting.backtest(

View File

@@ -6,6 +6,7 @@ import talib.abstract as ta
from pandas import DataFrame
import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.exceptions import DependencyException
from freqtrade.persistence import Trade
from freqtrade.strategy.interface import IStrategy
@@ -51,6 +52,9 @@ class StrategyTestV2(IStrategy):
'sell': 'gtc',
}
# By default this strategy does not use Position Adjustments
position_adjustment_enable = False
def informative_pairs(self):
"""
Define additional, informative pair/interval combinations to be cached from the exchange.
@@ -162,10 +166,9 @@ class StrategyTestV2(IStrategy):
current_rate: float, current_profit: float, **kwargs):
if current_profit < -0.0075:
for order in trade.orders:
if order.ft_is_open:
return None
return self.wallets.get_trade_stake_amount(pair, None)
try:
return self.wallets.get_trade_stake_amount(pair, None)
except DependencyException:
pass
return None

View File

@@ -121,19 +121,19 @@ def test_get_trade_stake_amount_no_stake_amount(default_conf, mocker) -> None:
freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
@pytest.mark.parametrize("balance_ratio,capital,result1,result2,result3", [
(1, None, 50, 66.66666, 250),
(0.99, None, 49.5, 66.0, 247.5),
(0.50, None, 25, 33.3333, 125),
@pytest.mark.parametrize("balance_ratio,capital,result1,result2", [
(1, None, 50, 66.66666),
(0.99, None, 49.5, 66.0),
(0.50, None, 25, 33.3333),
# Tests with capital ignore balance_ratio
(1, 100, 50, 0.0, 0.0),
(0.99, 200, 50, 66.66666, 50),
(0.99, 150, 50, 50, 37.5),
(0.50, 50, 25, 0.0, 0.0),
(0.50, 10, 5, 0.0, 0.0),
(1, 100, 50, 0.0),
(0.99, 200, 50, 66.66666),
(0.99, 150, 50, 50),
(0.50, 50, 25, 0.0),
(0.50, 10, 5, 0.0),
])
def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_ratio, capital,
result1, result2, result3, limit_buy_order_open,
result1, result2, limit_buy_order_open,
fee, mocker) -> None:
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
@@ -179,14 +179,6 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
result = freqtrade.wallets.get_trade_stake_amount('NEO/USDT')
assert result == 0
freqtrade.config['max_open_trades'] = 2
freqtrade.config['dry_run_wallet'] = 1000
freqtrade.wallets.start_cap = 1000
freqtrade.config['position_adjustment_enable'] = True
freqtrade.config['base_stake_amount_ratio'] = 0.5
result = freqtrade.wallets.get_trade_stake_amount('LTC/USDT')
assert result == result3
@pytest.mark.parametrize('stake_amount,min_stake_amount,max_stake_amount,expected', [
(22, 11, 50, 22),