How to use the backtesting.collector.data_file_manager.interpret_file_name function in Backtesting

To help you get started, weโ€™ve selected a few Backtesting 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 Drakkar-Software / OctoBot / backtesting / backtesting_util.py View on Github external
def get_standalone_backtesting_bot(config, data_files):
    config_to_use = create_blank_config_using_loaded_one(config)
    config_to_use[CONFIG_CRYPTO_CURRENCIES] = {}
    config_to_use[CONFIG_BACKTESTING][CONFIG_BACKTESTING_DATA_FILES] = []
    # do not activate web interface on standalone backtesting bot
    WebService.enable(config_to_use, False)
    ignored_files = []
    reference_market = _get_reference_market(data_files)
    if DEFAULT_REFERENCE_MARKET != reference_market:
        _switch_reference_market(config_to_use, reference_market)
    if data_files:
        for data_file_to_use in data_files:
            _, file_symbol, _, _ = interpret_file_name(data_file_to_use)
            currency, _ = split_symbol(file_symbol)
            full_file_path = CONFIG_DATA_COLLECTOR_PATH + data_file_to_use
            ending = f".{full_file_path.split('.')[-1]}"
            full_file_path += full_file_path if not is_valid_ending(ending) else ""
            if currency not in config_to_use[CONFIG_CRYPTO_CURRENCIES]:
                config_to_use[CONFIG_CRYPTO_CURRENCIES][currency] = {CONFIG_CRYPTO_PAIRS: []}
            if file_symbol not in config_to_use[CONFIG_CRYPTO_CURRENCIES][currency][CONFIG_CRYPTO_PAIRS]:
                config_to_use[CONFIG_CRYPTO_CURRENCIES][currency][CONFIG_CRYPTO_PAIRS].append(file_symbol)
                config_to_use[CONFIG_BACKTESTING][CONFIG_BACKTESTING_DATA_FILES].append(full_file_path)
            else:
                ignored_files.append(data_file_to_use)

    return create_backtesting_bot(config_to_use), ignored_files
github Drakkar-Software / OctoBot / backtesting / backtesting_util.py View on Github external
def _get_reference_market(data_files):
    reference_market = None
    for data_file in data_files:
        _, file_symbol, _, _ = interpret_file_name(data_file)
        currency, market = split_symbol(file_symbol)
        if reference_market is None:
            reference_market = market
        elif not reference_market == market:
            # more than one reference market in data_files: use first reference market
            return reference_market
    return reference_market if reference_market is not None else DEFAULT_REFERENCE_MARKET
github Drakkar-Software / OctoBot / backtesting / strategy_optimizer / strategy_test_suite.py View on Github external
async def _run_backtesting_with_current_config(self, symbol, data_file_to_use=None):
        config_to_use = copy.deepcopy(self.config)
        config_to_use[CONFIG_BACKTESTING][CONFIG_BACKTESTING_DATA_FILES] = copy.copy(DATA_FILES)
        # remove unused symbols
        symbols = {}
        for currency, details in copy.deepcopy(SYMBOLS).items():
            if symbol in details[CONFIG_CRYPTO_PAIRS]:
                symbols[currency] = details
        config_to_use[CONFIG_CRYPTO_CURRENCIES] = symbols
        if data_file_to_use is not None:
            for index, datafile in enumerate(DATA_FILES):
                _, file_symbol, _, _ = interpret_file_name(datafile)
                if symbol == file_symbol:
                    config_to_use[CONFIG_BACKTESTING][CONFIG_BACKTESTING_DATA_FILES][index] = \
                        DATA_FILE_PATH + data_file_to_use + DATA_FILE_EXT

        # do not activate web interface on standalone backtesting bot
        WebService.enable(config_to_use, False)
        filter_wanted_symbols(config_to_use, [symbol])
        bot = create_backtesting_bot(config_to_use)
        # debug set to False to improve performances
        return await start_backtesting_bot(bot), bot
github Drakkar-Software / OctoBot / trading / exchanges / exchange_simulator / exchange_simulator.py View on Github external
def _get_symbol_list(self):
        self.symbols = []
        self.data = {}
        symbols_appended = {}
        relevant_symbols = set(ConfigManager.get_symbols(self.config))

        # parse files
        for file in self.config[CONFIG_BACKTESTING][CONFIG_BACKTESTING_DATA_FILES]:
            exchange_name, symbol, timestamp, data_type = interpret_file_name(file)
            if symbol is not None and symbol in relevant_symbols:
                if exchange_name is not None and timestamp is not None and data_type is not None:

                    # check if symbol data already in symbols
                    # TODO check exchanges ?
                    if symbol not in symbols_appended:
                        symbols_appended[symbol] = 0
                        if symbols_appended[symbol] < int(timestamp):
                            symbols_appended[symbol] = int(timestamp)
                            self.symbols.append(symbol)
                            data = DataCollectorParser.parse(file)
                            self.data[symbol] = self.fix_timestamps(data)