How to use the freqtrade.OperationalException function in freqtrade

To help you get started, we’ve selected a few freqtrade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freqtrade / freqtrade / tests / test_plotting.py View on Github external
def test_start_plot_profit_error(mocker):

    args = [
        "plot-profit",
        "--pairs", "ETH/BTC"
    ]
    argsp = get_args(args)
    # Make sure we use no config. Details: #2241
    # not resetting config causes random failures if config.json exists
    argsp["config"] = []
    with pytest.raises(OperationalException):
        start_plot_profit(argsp)
github freqtrade / freqtrade / tests / pairlist / test_pairlist.py View on Github external
def test_pairlistmanager_no_pairlist(mocker, markets, whitelist_conf, caplog):
    mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))

    whitelist_conf['pairlists'] = []

    with pytest.raises(OperationalException,
                       match=r"No Pairlist defined!"):
        get_patched_freqtradebot(mocker, whitelist_conf)
github freqtrade / freqtrade / freqtrade / configuration / config_validation.py View on Github external
tsl_offset = float(conf.get('trailing_stop_positive_offset', 0))
    tsl_only_offset = conf.get('trailing_only_offset_is_reached', False)

    if tsl_only_offset:
        if tsl_positive == 0.0:
            raise OperationalException(
                'The config trailing_only_offset_is_reached needs '
                'trailing_stop_positive_offset to be more than 0 in your config.')
    if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive:
        raise OperationalException(
            'The config trailing_stop_positive_offset needs '
            'to be greater than trailing_stop_positive in your config.')

    # Fetch again without default
    if 'trailing_stop_positive' in conf and float(conf['trailing_stop_positive']) == 0.0:
        raise OperationalException(
            'The config trailing_stop_positive needs to be different from 0 '
            'to avoid problems with sell orders.'
github freqtrade / freqtrade / freqtrade / resolvers / strategy_resolver.py View on Github external
def load_strategy(config: Optional[Dict] = None) -> IStrategy:
        """
        Load the custom class from config parameter
        :param config: configuration dictionary or None
        """
        config = config or {}

        if not config.get('strategy'):
            raise OperationalException("No strategy set. Please use `--strategy` to specify "
                                       "the strategy class to use.")

        strategy_name = config['strategy']
        strategy: IStrategy = StrategyResolver._load_strategy(
            strategy_name, config=config,
            extra_dir=config.get('strategy_path'))

        # make sure ask_strategy dict is available
        if 'ask_strategy' not in config:
            config['ask_strategy'] = {}

        # Set attributes
        # Check if we need to override configuration
        #             (Attribute name,                    default,     ask_strategy)
        attributes = [("minimal_roi",                     {"0": 10.0}, False),
                      ("ticker_interval",                 None,        False),
github freqtrade / freqtrade / freqtrade / pairlist / VolumePairList.py View on Github external
self._whitelistconf = self._config.get('pairlist', {}).get('config')
        if 'number_assets' not in self._whitelistconf:
            raise OperationalException(
                f'`number_assets` not specified. Please check your configuration '
                'for "pairlist.config.number_assets"')
        self._number_pairs = self._whitelistconf['number_assets']
        self._sort_key = self._whitelistconf.get('sort_key', 'quoteVolume')
        self._precision_filter = self._whitelistconf.get('precision_filter', False)

        if not self._freqtrade.exchange.exchange_has('fetchTickers'):
            raise OperationalException(
                'Exchange does not support dynamic whitelist.'
                'Please edit your config and restart the bot'
            )
        if not self._validate_keys(self._sort_key):
            raise OperationalException(
                f'key {self._sort_key} not in {SORT_VALUES}')
github freqtrade / freqtrade / freqtrade / configuration / configuration.py View on Github external
Takes first found:
        * -p (pairs argument)
        * --pairs-file
        * whitelist from config
        """

        if "pairs" in config:
            return

        if "pairs_file" in self.args and self.args["pairs_file"]:
            pairs_file = Path(self.args["pairs_file"])
            logger.info(f'Reading pairs file "{pairs_file}".')
            # Download pairs from the pairs file if no config is specified
            # or if pairs file is specified explicitely
            if not pairs_file.exists():
                raise OperationalException(f'No pairs file found with path "{pairs_file}".')
            with pairs_file.open('r') as f:
                config['pairs'] = json_load(f)
                config['pairs'].sort()
            return

        if "config" in self.args and self.args["config"]:
            logger.info("Using pairlist from configuration.")
            config['pairs'] = config.get('exchange', {}).get('pair_whitelist')
        else:
            # Fall back to /dl_path/pairs.json
            pairs_file = Path(config['datadir']) / "pairs.json"
            if pairs_file.exists():
                with pairs_file.open('r') as f:
                    config['pairs'] = json_load(f)
                if 'pairs' in config:
                    config['pairs'].sort()
github freqtrade / freqtrade / freqtrade / exchange / exchange.py View on Github external
def set_sandbox(self, api, exchange_config: dict, name: str):
        if exchange_config.get('sandbox'):
            if api.urls.get('test'):
                api.urls['api'] = api.urls['test']
                logger.info("Enabled Sandbox API on %s", name)
            else:
                logger.warning(name, "No Sandbox URL in CCXT, exiting. "
                                     "Please check your config.json")
                raise OperationalException(f'Exchange {name} does not provide a sandbox api')
github freqtrade / freqtrade / freqtrade / exchange / bittrex.py View on Github external
def get_order(self, order_id: str) -> Dict:
        data = _API.get_order(order_id)
        if not data['success']:
            Bittrex._validate_response(data)
            raise OperationalException('{message} params=({order_id})'.format(
                message=data['message'],
                order_id=order_id))
        data = data['result']
        return {
            'id': data['OrderUuid'],
            'type': data['Type'],
            'pair': data['Exchange'].replace('-', '_'),
            'opened': data['Opened'],
            'rate': data['PricePerUnit'],
            'amount': data['Quantity'],
            'remaining': data['QuantityRemaining'],
            'closed': data['Closed'],
        }
github freqtrade / freqtrade / freqtrade / pairlist / VolumePrecisionPairList.py View on Github external
def __init__(self, freqtrade, config: dict) -> None:
        super().__init__(freqtrade, config)
        self._whitelistconf = self._config.get('pairlist', {}).get('config')
        if 'number_assets' not in self._whitelistconf:
            raise OperationalException(
                f'`number_assets` not specified. Please check your configuration '
                'for "pairlist.config.number_assets"')
        self._number_pairs = self._whitelistconf['number_assets']
        self._sort_key = self._whitelistconf.get('sort_key', 'quoteVolume')

        if not self._freqtrade.exchange.exchange_has('fetchTickers'):
            raise OperationalException(
                'Exchange does not support dynamic whitelist.'
                'Please edit your config and restart the bot'
            )
        if not self._validate_keys(self._sort_key):
            raise OperationalException(
                f'key {self._sort_key} not in {SORT_VALUES}')
github freqtrade / freqtrade / freqtrade / exchange / bittrex.py View on Github external
def cancel_order(self, order_id: str) -> None:
        data = _API.cancel(order_id)
        if not data['success']:
            Bittrex._validate_response(data)
            raise OperationalException('{message} params=({order_id})'.format(
                message=data['message'],
                order_id=order_id))