Initial attempt at is_short_strategy block
This commit is contained in:
parent
f6c263882d
commit
1c9dbb512a
@ -12,6 +12,7 @@ from typing import Any, Dict, Optional
|
|||||||
|
|
||||||
from freqtrade.configuration.config_validation import validate_migrated_strategy_settings
|
from freqtrade.configuration.config_validation import validate_migrated_strategy_settings
|
||||||
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES
|
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES
|
||||||
|
from freqtrade.enums import TradingMode
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.resolvers import IResolver
|
from freqtrade.resolvers import IResolver
|
||||||
from freqtrade.strategy.interface import IStrategy
|
from freqtrade.strategy.interface import IStrategy
|
||||||
@ -160,7 +161,7 @@ class StrategyResolver(IResolver):
|
|||||||
return strategy
|
return strategy
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _strategy_sanity_validations(strategy):
|
def _strategy_sanity_validations(strategy: IStrategy):
|
||||||
# Ensure necessary migrations are performed first.
|
# Ensure necessary migrations are performed first.
|
||||||
validate_migrated_strategy_settings(strategy.config)
|
validate_migrated_strategy_settings(strategy.config)
|
||||||
|
|
||||||
@ -170,6 +171,14 @@ class StrategyResolver(IResolver):
|
|||||||
if not all(k in strategy.order_time_in_force for k in REQUIRED_ORDERTIF):
|
if not all(k in strategy.order_time_in_force for k in REQUIRED_ORDERTIF):
|
||||||
raise ImportError(f"Impossible to load Strategy '{strategy.__class__.__name__}'. "
|
raise ImportError(f"Impossible to load Strategy '{strategy.__class__.__name__}'. "
|
||||||
f"Order-time-in-force mapping is incomplete.")
|
f"Order-time-in-force mapping is incomplete.")
|
||||||
|
trading_mode = strategy.config.get('trading_mode', TradingMode.SPOT)
|
||||||
|
|
||||||
|
if (strategy.can_short and trading_mode == TradingMode.SPOT):
|
||||||
|
raise ImportError(
|
||||||
|
"Short strategies cannot run in spot markets. Please make sure that this "
|
||||||
|
"is the correct strategy and that your trading mode configuration is correct. "
|
||||||
|
"You can run this strategy by setting `can_short=False` in your strategy."
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _load_strategy(strategy_name: str,
|
def _load_strategy(strategy_name: str,
|
||||||
|
@ -81,6 +81,8 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
trailing_only_offset_is_reached = False
|
trailing_only_offset_is_reached = False
|
||||||
use_custom_stoploss: bool = False
|
use_custom_stoploss: bool = False
|
||||||
|
|
||||||
|
can_short: bool = False
|
||||||
|
|
||||||
# associated timeframe
|
# associated timeframe
|
||||||
ticker_interval: str # DEPRECATED
|
ticker_interval: str # DEPRECATED
|
||||||
timeframe: str
|
timeframe: str
|
||||||
|
Loading…
Reference in New Issue
Block a user