Ejemplo n.º 1
0
    def _convert_dataframe_to_dict(strategy: str, pair: str, timeframe: str,
                                   dataframe: DataFrame,
                                   last_analyzed: datetime) -> Dict[str, Any]:
        has_content = len(dataframe) != 0
        buy_signals = 0
        sell_signals = 0
        if has_content:

            dataframe.loc[:, '__date_ts'] = dataframe.loc[:, 'date'].view(
                int64) // 1000 // 1000
            # Move signal close to separate column when signal for easy plotting
            if 'buy' in dataframe.columns:
                buy_mask = (dataframe['buy'] == 1)
                buy_signals = int(buy_mask.sum())
                dataframe.loc[buy_mask,
                              '_buy_signal_close'] = dataframe.loc[buy_mask,
                                                                   'close']
            if 'sell' in dataframe.columns:
                sell_mask = (dataframe['sell'] == 1)
                sell_signals = int(sell_mask.sum())
                dataframe.loc[sell_mask,
                              '_sell_signal_close'] = dataframe.loc[sell_mask,
                                                                    'close']

            # band-aid until this is fixed:
            # https://github.com/pandas-dev/pandas/issues/45836
            datetime_types = ['datetime', 'datetime64', 'datetime64[ns, UTC]']
            date_columns = dataframe.select_dtypes(include=datetime_types)
            for date_column in date_columns:
                # replace NaT with `None`
                dataframe[date_column] = dataframe[date_column].astype(
                    object).replace({NaT: None})

            dataframe = dataframe.replace({inf: None, -inf: None, NAN: None})

        res = {
            'pair': pair,
            'timeframe': timeframe,
            'timeframe_ms': timeframe_to_msecs(timeframe),
            'strategy': strategy,
            'columns': list(dataframe.columns),
            'data': dataframe.values.tolist(),
            'length': len(dataframe),
            'buy_signals': buy_signals,
            'sell_signals': sell_signals,
            'last_analyzed': last_analyzed,
            'last_analyzed_ts': int(last_analyzed.timestamp()),
            'data_start': '',
            'data_start_ts': 0,
            'data_stop': '',
            'data_stop_ts': 0,
        }
        if has_content:
            res.update({
                'data_start': str(dataframe.iloc[0]['date']),
                'data_start_ts': int(dataframe.iloc[0]['__date_ts']),
                'data_stop': str(dataframe.iloc[-1]['date']),
                'data_stop_ts': int(dataframe.iloc[-1]['__date_ts']),
            })
        return res
Ejemplo n.º 2
0
 def _rpc_show_config(config, botstate: Union[State, str]) -> Dict[str, Any]:
     """
     Return a dict of config options.
     Explicitly does NOT return the full config to avoid leakage of sensitive
     information via rpc.
     """
     val = {
         'dry_run': config['dry_run'],
         'stake_currency': config['stake_currency'],
         'stake_amount': config['stake_amount'],
         'max_open_trades': (config['max_open_trades']
                             if config['max_open_trades'] != float('inf') else -1),
         'minimal_roi': config['minimal_roi'].copy() if 'minimal_roi' in config else {},
         'stoploss': config.get('stoploss'),
         'trailing_stop': config.get('trailing_stop'),
         'trailing_stop_positive': config.get('trailing_stop_positive'),
         'trailing_stop_positive_offset': config.get('trailing_stop_positive_offset'),
         'trailing_only_offset_is_reached': config.get('trailing_only_offset_is_reached'),
         'use_custom_stoploss': config.get('use_custom_stoploss'),
         'bot_name': config.get('bot_name', 'freqtrade'),
         'timeframe': config.get('timeframe'),
         'timeframe_ms': timeframe_to_msecs(config['timeframe']
                                            ) if 'timeframe' in config else '',
         'timeframe_min': timeframe_to_minutes(config['timeframe']
                                               ) if 'timeframe' in config else '',
         'exchange': config['exchange']['name'],
         'strategy': config['strategy'],
         'forcebuy_enabled': config.get('forcebuy_enable', False),
         'ask_strategy': config.get('ask_strategy', {}),
         'bid_strategy': config.get('bid_strategy', {}),
         'state': str(botstate),
         'runmode': config['runmode'].value
     }
     return val
Ejemplo n.º 3
0
 def _rpc_show_config(self) -> Dict[str, Any]:
     """
     Return a dict of config options.
     Explicitly does NOT return the full config to avoid leakage of sensitive
     information via rpc.
     """
     config = self._freqtrade.config
     val = {
         'dry_run': config['dry_run'],
         'stake_currency': config['stake_currency'],
         'stake_amount': config['stake_amount'],
         'max_open_trades': config['max_open_trades'],
         'minimal_roi': config['minimal_roi'].copy(),
         'stoploss': config['stoploss'],
         'trailing_stop': config['trailing_stop'],
         'trailing_stop_positive': config.get('trailing_stop_positive'),
         'trailing_stop_positive_offset': config.get('trailing_stop_positive_offset'),
         'trailing_only_offset_is_reached': config.get('trailing_only_offset_is_reached'),
         'ticker_interval': config['timeframe'],  # DEPRECATED
         'timeframe': config['timeframe'],
         'timeframe_ms': timeframe_to_msecs(config['timeframe']),
         'timeframe_min': timeframe_to_minutes(config['timeframe']),
         'exchange': config['exchange']['name'],
         'strategy': config['strategy'],
         'forcebuy_enabled': config.get('forcebuy_enable', False),
         'ask_strategy': config.get('ask_strategy', {}),
         'bid_strategy': config.get('bid_strategy', {}),
         'state': str(self._freqtrade.state)
     }
     return val
Ejemplo n.º 4
0
    def _convert_dataframe_to_dict(strategy: str, pair: str, timeframe: str,
                                   dataframe: DataFrame,
                                   last_analyzed: datetime) -> Dict[str, Any]:
        has_content = len(dataframe) != 0
        buy_signals = 0
        sell_signals = 0
        if has_content:

            dataframe.loc[:, '__date_ts'] = dataframe.loc[:, 'date'].astype(
                int64) // 1000 // 1000
            # Move open to seperate column when signal for easy plotting
            if 'buy' in dataframe.columns:
                buy_mask = (dataframe['buy'] == 1)
                buy_signals = int(buy_mask.sum())
                dataframe.loc[buy_mask,
                              '_buy_signal_open'] = dataframe.loc[buy_mask,
                                                                  'open']
            if 'sell' in dataframe.columns:
                sell_mask = (dataframe['sell'] == 1)
                sell_signals = int(sell_mask.sum())
                dataframe.loc[sell_mask,
                              '_sell_signal_open'] = dataframe.loc[sell_mask,
                                                                   'open']
            dataframe = dataframe.replace([inf, -inf], NAN)
            dataframe = dataframe.replace({NAN: None})

        res = {
            'pair': pair,
            'timeframe': timeframe,
            'timeframe_ms': timeframe_to_msecs(timeframe),
            'strategy': strategy,
            'columns': list(dataframe.columns),
            'data': dataframe.values.tolist(),
            'length': len(dataframe),
            'buy_signals': buy_signals,
            'sell_signals': sell_signals,
            'last_analyzed': last_analyzed,
            'last_analyzed_ts': int(last_analyzed.timestamp()),
            'data_start': '',
            'data_start_ts': 0,
            'data_stop': '',
            'data_stop_ts': 0,
        }
        if has_content:
            res.update({
                'data_start': str(dataframe.iloc[0]['date']),
                'data_start_ts': int(dataframe.iloc[0]['__date_ts']),
                'data_stop': str(dataframe.iloc[-1]['date']),
                'data_stop_ts': int(dataframe.iloc[-1]['__date_ts']),
            })
        return res
Ejemplo n.º 5
0
 def _rpc_show_config(config, botstate: Union[State, str],
                      strategy_version: Optional[str] = None) -> Dict[str, Any]:
     """
     Return a dict of config options.
     Explicitly does NOT return the full config to avoid leakage of sensitive
     information via rpc.
     """
     val = {
         'version': __version__,
         'strategy_version': strategy_version,
         'dry_run': config['dry_run'],
         'trading_mode': config.get('trading_mode', 'spot'),
         'short_allowed': config.get('trading_mode', 'spot') != 'spot',
         'stake_currency': config['stake_currency'],
         'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
         'stake_amount': str(config['stake_amount']),
         'available_capital': config.get('available_capital'),
         'max_open_trades': (config['max_open_trades']
                             if config['max_open_trades'] != float('inf') else -1),
         'minimal_roi': config['minimal_roi'].copy() if 'minimal_roi' in config else {},
         'stoploss': config.get('stoploss'),
         'trailing_stop': config.get('trailing_stop'),
         'trailing_stop_positive': config.get('trailing_stop_positive'),
         'trailing_stop_positive_offset': config.get('trailing_stop_positive_offset'),
         'trailing_only_offset_is_reached': config.get('trailing_only_offset_is_reached'),
         'unfilledtimeout': config.get('unfilledtimeout'),
         'use_custom_stoploss': config.get('use_custom_stoploss'),
         'order_types': config.get('order_types'),
         'bot_name': config.get('bot_name', 'freqtrade'),
         'timeframe': config.get('timeframe'),
         'timeframe_ms': timeframe_to_msecs(config['timeframe']
                                            ) if 'timeframe' in config else 0,
         'timeframe_min': timeframe_to_minutes(config['timeframe']
                                               ) if 'timeframe' in config else 0,
         'exchange': config['exchange']['name'],
         'strategy': config['strategy'],
         'force_entry_enable': config.get('force_entry_enable', False),
         'exit_pricing': config.get('exit_pricing', {}),
         'entry_pricing': config.get('entry_pricing', {}),
         'state': str(botstate),
         'runmode': config['runmode'].value,
         'position_adjustment_enable': config.get('position_adjustment_enable', False),
         'max_entry_position_adjustment': (
             config.get('max_entry_position_adjustment', -1)
             if config.get('max_entry_position_adjustment') != float('inf')
             else -1)
     }
     return val