Add candletypes argument for convert-data

This commit is contained in:
Matthias 2021-12-05 10:26:00 +01:00
parent a80c3f6a1b
commit 9d79501c13
6 changed files with 26 additions and 8 deletions

View File

@ -61,7 +61,9 @@ ARGS_BUILD_CONFIG = ["config"]
ARGS_BUILD_STRATEGY = ["user_data_dir", "strategy", "template"] ARGS_BUILD_STRATEGY = ["user_data_dir", "strategy", "template"]
ARGS_CONVERT_DATA = ["pairs", "format_from", "format_to", "erase"] ARGS_CONVERT_DATA = ["pairs", "format_from", "format_to", "erase"]
ARGS_CONVERT_DATA_OHLCV = ARGS_CONVERT_DATA + ["timeframes"]
ARGS_CONVERT_DATA_OHLCV = ARGS_CONVERT_DATA + ["timeframes", "exchange", "trading_mode",
"candle_types"]
ARGS_CONVERT_TRADES = ["pairs", "timeframes", "exchange", "dataformat_ohlcv", "dataformat_trades"] ARGS_CONVERT_TRADES = ["pairs", "timeframes", "exchange", "dataformat_ohlcv", "dataformat_trades"]

View File

@ -5,6 +5,7 @@ from argparse import SUPPRESS, ArgumentTypeError
from freqtrade import __version__, constants from freqtrade import __version__, constants
from freqtrade.constants import HYPEROPT_LOSS_BUILTIN from freqtrade.constants import HYPEROPT_LOSS_BUILTIN
from freqtrade.enums import CandleType
def check_int_positive(value: str) -> int: def check_int_positive(value: str) -> int:
@ -353,6 +354,12 @@ AVAILABLE_CLI_OPTIONS = {
help='Select Trading mode', help='Select Trading mode',
choices=constants.TRADING_MODES, choices=constants.TRADING_MODES,
), ),
"candle_types": Arg(
'--candle-types',
help='Select Trading mode',
choices=[c.value for c in CandleType],
nargs='+',
),
# Script options # Script options
"pairs": Arg( "pairs": Arg(
'-p', '--pairs', '-p', '--pairs',

View File

@ -8,7 +8,7 @@ from freqtrade.configuration import TimeRange, setup_utils_configuration
from freqtrade.data.converter import convert_ohlcv_format, convert_trades_format from freqtrade.data.converter import convert_ohlcv_format, convert_trades_format
from freqtrade.data.history import (convert_trades_to_ohlcv, refresh_backtest_ohlcv_data, from freqtrade.data.history import (convert_trades_to_ohlcv, refresh_backtest_ohlcv_data,
refresh_backtest_trades_data) refresh_backtest_trades_data)
from freqtrade.enums import RunMode from freqtrade.enums import CandleType, RunMode
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.exchange import timeframe_to_minutes from freqtrade.exchange import timeframe_to_minutes
from freqtrade.exchange.exchange import market_is_active from freqtrade.exchange.exchange import market_is_active
@ -137,9 +137,11 @@ def start_convert_data(args: Dict[str, Any], ohlcv: bool = True) -> None:
""" """
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE) config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
if ohlcv: if ohlcv:
convert_ohlcv_format(config, candle_types = [CandleType.from_string(ct) for ct in config.get('candle_types', ['spot'])]
convert_from=args['format_from'], convert_to=args['format_to'], for candle_type in candle_types:
erase=args['erase']) convert_ohlcv_format(config,
convert_from=args['format_from'], convert_to=args['format_to'],
erase=args['erase'], candle_type=candle_type)
else: else:
convert_trades_format(config, convert_trades_format(config,
convert_from=args['format_from'], convert_to=args['format_to'], convert_from=args['format_from'], convert_to=args['format_to'],

View File

@ -434,6 +434,10 @@ class Configuration:
self._args_to_config(config, argname='trading_mode', self._args_to_config(config, argname='trading_mode',
logstring='Detected --trading-mode: {}') logstring='Detected --trading-mode: {}')
self._args_to_config(config, argname='candle_types',
logstring='Detected --candle-types: {}')
def _process_runmode(self, config: Dict[str, Any]) -> None: def _process_runmode(self, config: Dict[str, Any]) -> None:
self._args_to_config(config, argname='dry_run', self._args_to_config(config, argname='dry_run',

View File

@ -267,7 +267,7 @@ def convert_ohlcv_format(
convert_from: str, convert_from: str,
convert_to: str, convert_to: str,
erase: bool, erase: bool,
candle_type: CandleType = CandleType.SPOT_ candle_type: CandleType
): ):
""" """
Convert OHLCV from one format to another Convert OHLCV from one format to another

View File

@ -12,6 +12,7 @@ from freqtrade.data.converter import (convert_ohlcv_format, convert_trades_forma
trades_to_ohlcv, trim_dataframe) trades_to_ohlcv, trim_dataframe)
from freqtrade.data.history import (get_timerange, load_data, load_pair_history, from freqtrade.data.history import (get_timerange, load_data, load_pair_history,
validate_backtest_data) validate_backtest_data)
from freqtrade.enums import CandleType
from tests.conftest import log_has, log_has_re from tests.conftest import log_has, log_has_re
from tests.data.test_history import _clean_test_file from tests.data.test_history import _clean_test_file
@ -312,7 +313,8 @@ def test_convert_ohlcv_format(default_conf, testdatadir, tmpdir, file_base):
default_conf, default_conf,
convert_from='json', convert_from='json',
convert_to='jsongz', convert_to='jsongz',
erase=False erase=False,
candle_type=CandleType.SPOT
) )
assert file_new.exists() assert file_new.exists()
@ -325,7 +327,8 @@ def test_convert_ohlcv_format(default_conf, testdatadir, tmpdir, file_base):
default_conf, default_conf,
convert_from='jsongz', convert_from='jsongz',
convert_to='json', convert_to='json',
erase=True erase=True,
candle_type=CandleType.SPOT
) )
assert file_temp.exists() assert file_temp.exists()