Implement order_types validation

This commit is contained in:
Matthias
2022-03-08 06:59:14 +01:00
parent e492bf3159
commit 5d4386f037
9 changed files with 63 additions and 32 deletions

View File

@@ -951,8 +951,8 @@ def test_validate_order_types(default_conf, mocker):
mocker.patch('freqtrade.exchange.Exchange.name', 'Bittrex')
default_conf['order_types'] = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'market',
'stoploss_on_exchange': False
}
@@ -962,8 +962,8 @@ def test_validate_order_types(default_conf, mocker):
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
default_conf['order_types'] = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'market',
'stoploss_on_exchange': False
}
@@ -972,8 +972,8 @@ def test_validate_order_types(default_conf, mocker):
Exchange(default_conf)
default_conf['order_types'] = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': True
}

View File

@@ -34,8 +34,8 @@ class HyperoptableStrategy(IStrategy):
# Optional order type mapping
order_types = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': False
}

View File

@@ -36,8 +36,8 @@ class StrategyTestV2(IStrategy):
# Optional order type mapping
order_types = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': False
}

View File

@@ -37,8 +37,8 @@ class StrategyTestV3(IStrategy):
# Optional order type mapping
order_types = {
'buy': 'limit',
'sell': 'limit',
'entry': 'limit',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': False
}

View File

@@ -223,8 +223,8 @@ def test_strategy_override_order_types(caplog, default_conf):
caplog.set_level(logging.INFO)
order_types = {
'buy': 'market',
'sell': 'limit',
'entry': 'market',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': True,
}
@@ -235,16 +235,16 @@ def test_strategy_override_order_types(caplog, default_conf):
strategy = StrategyResolver.load_strategy(default_conf)
assert strategy.order_types
for method in ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']:
for method in ['entry', 'exit', 'stoploss', 'stoploss_on_exchange']:
assert strategy.order_types[method] == order_types[method]
assert log_has("Override strategy 'order_types' with value in config file:"
" {'buy': 'market', 'sell': 'limit', 'stoploss': 'limit',"
" {'entry': 'market', 'exit': 'limit', 'stoploss': 'limit',"
" 'stoploss_on_exchange': True}.", caplog)
default_conf.update({
'strategy': CURRENT_TEST_STRATEGY,
'order_types': {'buy': 'market'}
'order_types': {'exit': 'market'}
})
# Raise error for invalid configuration
with pytest.raises(ImportError,

View File

@@ -798,8 +798,8 @@ def test_validate_max_open_trades(default_conf):
def test_validate_price_side(default_conf):
default_conf['order_types'] = {
"buy": "limit",
"sell": "limit",
"entry": "limit",
"exit": "limit",
"stoploss": "limit",
"stoploss_on_exchange": False,
}
@@ -807,21 +807,21 @@ def test_validate_price_side(default_conf):
validate_config_consistency(default_conf)
conf = deepcopy(default_conf)
conf['order_types']['buy'] = 'market'
conf['order_types']['entry'] = 'market'
with pytest.raises(OperationalException,
match='Market buy orders require bid_strategy.price_side = "ask".'):
validate_config_consistency(conf)
conf = deepcopy(default_conf)
conf['order_types']['sell'] = 'market'
conf['order_types']['exit'] = 'market'
with pytest.raises(OperationalException,
match='Market sell orders require ask_strategy.price_side = "bid".'):
validate_config_consistency(conf)
# Validate inversed case
conf = deepcopy(default_conf)
conf['order_types']['sell'] = 'market'
conf['order_types']['buy'] = 'market'
conf['order_types']['exit'] = 'market'
conf['order_types']['entry'] = 'market'
conf['ask_strategy']['price_side'] = 'bid'
conf['bid_strategy']['price_side'] = 'ask'

View File

@@ -91,8 +91,8 @@ def test_order_dict(default_conf_usdt, mocker, runmode, caplog) -> None:
conf = default_conf_usdt.copy()
conf['runmode'] = runmode
conf['order_types'] = {
'buy': 'market',
'sell': 'limit',
'entry': 'market',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': True,
}
@@ -108,8 +108,8 @@ def test_order_dict(default_conf_usdt, mocker, runmode, caplog) -> None:
conf = default_conf_usdt.copy()
conf['runmode'] = runmode
conf['order_types'] = {
'buy': 'market',
'sell': 'limit',
'entry': 'market',
'exit': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': False,
}
@@ -3490,7 +3490,7 @@ def test_execute_trade_exit_market_order(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker_usdt_sell_up
)
freqtrade.config['order_types']['sell'] = 'market'
freqtrade.config['order_types']['exit'] = 'market'
freqtrade.execute_trade_exit(
trade=trade,

View File

@@ -80,7 +80,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
freqtrade = get_patched_freqtradebot(mocker, default_conf)
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
# Switch ordertype to market to close trade immediately
freqtrade.strategy.order_types['sell'] = 'market'
freqtrade.strategy.order_types['exit'] = 'market'
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
freqtrade.strategy.confirm_trade_exit = MagicMock(return_value=True)
patch_get_signal(freqtrade)
@@ -173,7 +173,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, mocker, balance_rati
rpc = RPC(freqtrade)
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
# Switch ordertype to market to close trade immediately
freqtrade.strategy.order_types['sell'] = 'market'
freqtrade.strategy.order_types['exit'] = 'market'
patch_get_signal(freqtrade)
# Create 4 trades