gurudesh/pytracebugs huggingface dataset:
# Buggy code
def consume(self, event):
    # type: (Mapping[str, Any]) -> None
    mirror_email(
        email.message_from_string(event["message"]),
        rcpt_to=event["rcpt_to"],
        pre_checked=True,
    )


# Traceback (UnicodeEncodeError)
Problem handling data on queue email_mirror
Traceback (most recent call last):
File "/home/zulip/deployments/2016-09-30-12-03-05/zerver/worker/queue_processors.py", line 80, in consume_wrapper
self.consume(data)
File "/home/zulip/deployments/2016-09-30-12-03-05/zerver/worker/queue_processors.py", line 378, in consume
mirror_email(email.message_from_string(event["message"]),
File "/usr/lib/python2.7/email/__init__.py", line 57, in message_from_string
return Parser(*args, **kws).parsestr(s)
File "/usr/lib/python2.7/email/parser.py", line 82, in parsestr
return self.parse(StringIO(text), headersonly=headersonly)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 393: ordinal not in range(128)

# Fixed code
def consume(self, event):
    # type: (Mapping[str, Any]) -> None
    message = force_str(event["message"])
    mirror_email(
        email.message_from_string(message), rcpt_to=event["rcpt_to"], pre_checked=True
    )
# Buggy code
def orderbook(self, pair: str, maximum: int) -> Dict[str, List]:
    """
    fetch latest orderbook data
    :param pair: pair to get the data for
    :param maximum: Maximum number of orderbook entries to query
    :return: dict including bids/asks with a total of `maximum` entries.
    """
    return self._exchange.get_order_book(pair, maximum)


# Traceback (IndexError)
2020-05-23 16:03:03,076 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
worker.run()
File "/freqtrade/freqtrade/worker.py", line 66, in run
state = self._worker(old_state=state)
File "/freqtrade/freqtrade/worker.py", line 104, in _worker
self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
File "/freqtrade/freqtrade/worker.py", line 125, in _throttle
result = func(*args, **kwargs)
File "/freqtrade/freqtrade/worker.py", line 139, in _process_running
self.freqtrade.process()
File "/freqtrade/freqtrade/freqtradebot.py", line 157, in process
self.exit_positions(trades)
File "/freqtrade/freqtrade/freqtradebot.py", line 613, in exit_positions
if trade.open_order_id is None and self.handle_trade(trade):
File "/freqtrade/freqtrade/freqtradebot.py", line 694, in handle_trade
sell_rate = next(order_book)
File "/freqtrade/freqtrade/freqtradebot.py", line 632, in _order_book_gen
yield order_book[side][i - 1][0]
IndexError: list index out of range
2020-05-23 16:03:13,989 - freqtrade.loggers - INFO - Verbosity set to 0

# Fixed code
def orderbook(self, pair: str, maximum: int) -> Dict[str, List]:
    """
    Fetch latest l2 orderbook data
    Warning: Does a network request - so use with common sense.
    :param pair: pair to get the data for
    :param maximum: Maximum number of orderbook entries to query
    :return: dict including bids/asks with a total of `maximum` entries.
    """
    return self._exchange.fetch_l2_order_book(pair, maximum)
# Buggy code
def _order_book_gen(
    self, pair: str, side: str, order_book_max: int = 1, order_book_min: int = 1
):
    """
    Helper generator to query orderbook in loop (used for early sell-order placing)
    """
    order_book = self.exchange.get_order_book(pair, order_book_max)
    for i in range(order_book_min, order_book_max + 1):
        yield order_book[side][i - 1][0]


# Traceback (IndexError)
2020-05-23 16:03:03,076 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
worker.run()
File "/freqtrade/freqtrade/worker.py", line 66, in run
state = self._worker(old_state=state)
File "/freqtrade/freqtrade/worker.py", line 104, in _worker
self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
File "/freqtrade/freqtrade/worker.py", line 125, in _throttle
result = func(*args, **kwargs)
File "/freqtrade/freqtrade/worker.py", line 139, in _process_running
self.freqtrade.process()
File "/freqtrade/freqtrade/freqtradebot.py", line 157, in process
self.exit_positions(trades)
File "/freqtrade/freqtrade/freqtradebot.py", line 613, in exit_positions
if trade.open_order_id is None and self.handle_trade(trade):
File "/freqtrade/freqtrade/freqtradebot.py", line 694, in handle_trade
sell_rate = next(order_book)
File "/freqtrade/freqtrade/freqtradebot.py", line 632, in _order_book_gen
yield order_book[side][i - 1][0]
IndexError: list index out of range
2020-05-23 16:03:13,989 - freqtrade.loggers - INFO - Verbosity set to 0

# Fixed code
def _order_book_gen(
    self, pair: str, side: str, order_book_max: int = 1, order_book_min: int = 1
):
    """
    Helper generator to query orderbook in loop (used for early sell-order placing)
    """
    order_book = self.exchange.fetch_l2_order_book(pair, order_book_max)
    for i in range(order_book_min, order_book_max + 1):
        yield order_book[side][i - 1][0]
# Buggy code
def start_new_strategy(args: Dict[str, Any]) -> None:
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)

    if "strategy" in args and args["strategy"]:
        if args["strategy"] == "DefaultStrategy":
            raise OperationalException("DefaultStrategy is not allowed as name.")

        new_path = (
            config["user_data_dir"] / USERPATH_STRATEGY / (args["strategy"] + ".py")
        )

        if new_path.exists():
            raise OperationalException(
                f"`{new_path}` already exists. Please choose another Strategy Name."
            )

        deploy_new_strategy(args["strategy"], new_path, args["template"])

    else:
        raise OperationalException("`new-strategy` requires --strategy to be set.")


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def start_new_strategy(args: Dict[str, Any]) -> None:
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)

    if "strategy" in args and args["strategy"]:
        if args["strategy"] == "DefaultStrategy":
            raise OperationalException("DefaultStrategy is not allowed as name.")

        new_path = (
            config["user_data_dir"] / USERPATH_STRATEGIES / (args["strategy"] + ".py")
        )

        if new_path.exists():
            raise OperationalException(
                f"`{new_path}` already exists. Please choose another Strategy Name."
            )

        deploy_new_strategy(args["strategy"], new_path, args["template"])

    else:
        raise OperationalException("`new-strategy` requires --strategy to be set.")
# Buggy code
def start_list_strategies(args: Dict[str, Any]) -> None:
    """
    Print Strategies available in a directory
    """
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)

    directory = Path(
        config.get("strategy_path", config["user_data_dir"] / USERPATH_STRATEGY)
    )
    strategies = StrategyResolver.search_all_objects(directory)
    # Sort alphabetically
    strategies = sorted(strategies, key=lambda x: x["name"])
    strats_to_print = [
        {"name": s["name"], "location": s["location"].name} for s in strategies
    ]

    if args["print_one_column"]:
        print("\n".join([s["name"] for s in strategies]))
    else:
        print(tabulate(strats_to_print, headers="keys", tablefmt="pipe"))


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def start_list_strategies(args: Dict[str, Any]) -> None:
    """
    Print files with Strategy custom classes available in the directory
    """
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)

    directory = Path(
        config.get("strategy_path", config["user_data_dir"] / USERPATH_STRATEGIES)
    )
    strategy_objs = StrategyResolver.search_all_objects(
        directory, not args["print_one_column"]
    )
    # Sort alphabetically
    strategy_objs = sorted(strategy_objs, key=lambda x: x["name"])

    if args["print_one_column"]:
        print("\n".join([s["name"] for s in strategy_objs]))
    else:
        _print_objs_tabular(strategy_objs, config.get("print_colorized", False))
# Buggy code
def validate_plot_args(args: Dict[str, Any]):
    if not args.get("datadir") and not args.get("config"):
        raise OperationalException(
            "You need to specify either `--datadir` or `--config` "
            "for plot-profit and plot-dataframe."
        )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def validate_plot_args(args: Dict[str, Any]) -> None:
    if not args.get("datadir") and not args.get("config"):
        raise OperationalException(
            "You need to specify either `--datadir` or `--config` "
            "for plot-profit and plot-dataframe."
        )
# Buggy code
def remove_credentials(config: Dict[str, Any]):
    """
    Removes exchange keys from the configuration and specifies dry-run
    Used for backtesting / hyperopt / edge and utils.
    Modifies the input dict!
    """
    config["exchange"]["key"] = ""
    config["exchange"]["secret"] = ""
    config["exchange"]["password"] = ""
    config["exchange"]["uid"] = ""
    config["dry_run"] = True


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def remove_credentials(config: Dict[str, Any]) -> None:
    """
    Removes exchange keys from the configuration and specifies dry-run
    Used for backtesting / hyperopt / edge and utils.
    Modifies the input dict!
    """
    config["exchange"]["key"] = ""
    config["exchange"]["secret"] = ""
    config["exchange"]["password"] = ""
    config["exchange"]["uid"] = ""
    config["dry_run"] = True
# Buggy code
def check_conflicting_settings(
    config: Dict[str, Any], section1: str, name1: str, section2: str, name2: str
):
    section1_config = config.get(section1, {})
    section2_config = config.get(section2, {})
    if name1 in section1_config and name2 in section2_config:
        raise OperationalException(
            f"Conflicting settings `{section1}.{name1}` and `{section2}.{name2}` "
            "(DEPRECATED) detected in the configuration file. "
            "This deprecated setting will be removed in the next versions of Freqtrade. "
            f"Please delete it from your configuration and use the `{section1}.{name1}` "
            "setting instead."
        )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def check_conflicting_settings(
    config: Dict[str, Any], section1: str, name1: str, section2: str, name2: str
) -> None:
    section1_config = config.get(section1, {})
    section2_config = config.get(section2, {})
    if name1 in section1_config and name2 in section2_config:
        raise OperationalException(
            f"Conflicting settings `{section1}.{name1}` and `{section2}.{name2}` "
            "(DEPRECATED) detected in the configuration file. "
            "This deprecated setting will be removed in the next versions of Freqtrade. "
            f"Please delete it from your configuration and use the `{section1}.{name1}` "
            "setting instead."
        )
# Buggy code
def process_deprecated_setting(
    config: Dict[str, Any], section1: str, name1: str, section2: str, name2: str
):
    section2_config = config.get(section2, {})

    if name2 in section2_config:
        logger.warning(
            "DEPRECATED: "
            f"The `{section2}.{name2}` setting is deprecated and "
            "will be removed in the next versions of Freqtrade. "
            f"Please use the `{section1}.{name1}` setting in your configuration instead."
        )
        section1_config = config.get(section1, {})
        section1_config[name1] = section2_config[name2]


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def process_deprecated_setting(
    config: Dict[str, Any], section1: str, name1: str, section2: str, name2: str
) -> None:
    section2_config = config.get(section2, {})

    if name2 in section2_config:
        logger.warning(
            "DEPRECATED: "
            f"The `{section2}.{name2}` setting is deprecated and "
            "will be removed in the next versions of Freqtrade. "
            f"Please use the `{section1}.{name1}` setting in your configuration instead."
        )
        section1_config = config.get(section1, {})
        section1_config[name1] = section2_config[name2]
# Buggy code
def subtract_start(self, seconds) -> None:
    """
    Subtracts <seconds> from startts if startts is set.
    :param seconds: Seconds to subtract from starttime
    :return: None (Modifies the object in place)
    """
    if self.startts:
        self.startts = self.startts - seconds


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def subtract_start(self, seconds: int) -> None:
    """
    Subtracts <seconds> from startts if startts is set.
    :param seconds: Seconds to subtract from starttime
    :return: None (Modifies the object in place)
    """
    if self.startts:
        self.startts = self.startts - seconds
# Buggy code
def combine_tickers_with_mean(tickers: Dict[str, pd.DataFrame], column: str = "close"):
    """
    Combine multiple dataframes "column"
    :param tickers: Dict of Dataframes, dict key should be pair.
    :param column: Column in the original dataframes to use
    :return: DataFrame with the column renamed to the dict key, and a column
        named mean, containing the mean of all pairs.
    """
    df_comb = pd.concat(
        [
            tickers[pair].set_index("date").rename({column: pair}, axis=1)[pair]
            for pair in tickers
        ],
        axis=1,
    )

    df_comb["mean"] = df_comb.mean(axis=1)

    return df_comb


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def combine_tickers_with_mean(
    tickers: Dict[str, pd.DataFrame], column: str = "close"
) -> pd.DataFrame:
    """
    Combine multiple dataframes "column"
    :param tickers: Dict of Dataframes, dict key should be pair.
    :param column: Column in the original dataframes to use
    :return: DataFrame with the column renamed to the dict key, and a column
        named mean, containing the mean of all pairs.
    """
    df_comb = pd.concat(
        [
            tickers[pair].set_index("date").rename({column: pair}, axis=1)[pair]
            for pair in tickers
        ],
        axis=1,
    )

    df_comb["mean"] = df_comb.mean(axis=1)

    return df_comb
# Buggy code
def klines(self, pair_interval: Tuple[str, str], copy=True) -> DataFrame:
    if pair_interval in self._klines:
        return (
            self._klines[pair_interval].copy() if copy else self._klines[pair_interval]
        )
    else:
        return DataFrame()


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def klines(self, pair_interval: Tuple[str, str], copy: bool = True) -> DataFrame:
    if pair_interval in self._klines:
        return (
            self._klines[pair_interval].copy() if copy else self._klines[pair_interval]
        )
    else:
        return DataFrame()
# Buggy code
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"
            )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def set_sandbox(self, api: ccxt.Exchange, exchange_config: dict, name: str) -> None:
    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"
            )
# Buggy code
def _load_async_markets(self, reload=False) -> None:
    try:
        if self._api_async:
            asyncio.get_event_loop().run_until_complete(
                self._api_async.load_markets(reload=reload)
            )

    except ccxt.BaseError as e:
        logger.warning("Could not load async markets. Reason: %s", e)
        return


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def _load_async_markets(self, reload: bool = False) -> None:
    try:
        if self._api_async:
            asyncio.get_event_loop().run_until_complete(
                self._api_async.load_markets(reload=reload)
            )

    except ccxt.BaseError as e:
        logger.warning("Could not load async markets. Reason: %s", e)
        return
# Buggy code
def validate_stakecurrency(self, stake_currency) -> None:
    """
    Checks stake-currency against available currencies on the exchange.
    :param stake_currency: Stake-currency to validate
    :raise: OperationalException if stake-currency is not available.
    """
    quote_currencies = self.get_quote_currencies()
    if stake_currency not in quote_currencies:
        raise OperationalException(
            f"{stake_currency} is not available as stake on {self.name}. "
            f"Available currencies are: {', '.join(quote_currencies)}"
        )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def validate_stakecurrency(self, stake_currency: str) -> None:
    """
    Checks stake-currency against available currencies on the exchange.
    :param stake_currency: Stake-currency to validate
    :raise: OperationalException if stake-currency is not available.
    """
    quote_currencies = self.get_quote_currencies()
    if stake_currency not in quote_currencies:
        raise OperationalException(
            f"{stake_currency} is not available as stake on {self.name}. "
            f"Available currencies are: {', '.join(quote_currencies)}"
        )
# Buggy code
def get_valid_pair_combination(self, curr_1, curr_2) -> str:
    """
    Get valid pair combination of curr_1 and curr_2 by trying both combinations.
    """
    for pair in [f"{curr_1}/{curr_2}", f"{curr_2}/{curr_1}"]:
        if pair in self.markets and self.markets[pair].get("active"):
            return pair
    raise DependencyException(
        f"Could not combine {curr_1} and {curr_2} to get a valid pair."
    )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def get_valid_pair_combination(self, curr_1: str, curr_2: str) -> str:
    """
    Get valid pair combination of curr_1 and curr_2 by trying both combinations.
    """
    for pair in [f"{curr_1}/{curr_2}", f"{curr_2}/{curr_1}"]:
        if pair in self.markets and self.markets[pair].get("active"):
            return pair
    raise DependencyException(
        f"Could not combine {curr_1} and {curr_2} to get a valid pair."
    )
# Buggy code
def validate_required_startup_candles(self, startup_candles) -> None:
    """
    Checks if required startup_candles is more than ohlcv_candle_limit.
    Requires a grace-period of 5 candles - so a startup-period up to 494 is allowed by default.
    """
    if startup_candles + 5 > self._ft_has["ohlcv_candle_limit"]:
        raise OperationalException(
            f"This strategy requires {startup_candles} candles to start. "
            f"{self.name} only provides {self._ft_has['ohlcv_candle_limit']}."
        )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def validate_required_startup_candles(self, startup_candles: int) -> None:
    """
    Checks if required startup_candles is more than ohlcv_candle_limit.
    Requires a grace-period of 5 candles - so a startup-period up to 494 is allowed by default.
    """
    if startup_candles + 5 > self._ft_has["ohlcv_candle_limit"]:
        raise OperationalException(
            f"This strategy requires {startup_candles} candles to start. "
            f"{self.name} only provides {self._ft_has['ohlcv_candle_limit']}."
        )
# Buggy code
def amount_to_precision(self, pair, amount: float) -> float:
    """
    Returns the amount to buy or sell to a precision the Exchange accepts
    Reimplementation of ccxt internal methods - ensuring we can test the result is correct
    based on our definitions.
    """
    if self.markets[pair]["precision"]["amount"]:
        amount = float(
            decimal_to_precision(
                amount,
                rounding_mode=TRUNCATE,
                precision=self.markets[pair]["precision"]["amount"],
                counting_mode=self.precisionMode,
            )
        )

    return amount


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def amount_to_precision(self, pair: str, amount: float) -> float:
    """
    Returns the amount to buy or sell to a precision the Exchange accepts
    Reimplementation of ccxt internal methods - ensuring we can test the result is correct
    based on our definitions.
    """
    if self.markets[pair]["precision"]["amount"]:
        amount = float(
            decimal_to_precision(
                amount,
                rounding_mode=TRUNCATE,
                precision=self.markets[pair]["precision"]["amount"],
                counting_mode=self.precisionMode,
            )
        )

    return amount
# Buggy code
def buy(
    self, pair: str, ordertype: str, amount: float, rate: float, time_in_force
) -> Dict:
    if self._config["dry_run"]:
        dry_order = self.dry_run_order(pair, ordertype, "buy", amount, rate)
        return dry_order

    params = self._params.copy()
    if time_in_force != "gtc" and ordertype != "market":
        params.update({"timeInForce": time_in_force})

    return self.create_order(pair, ordertype, "buy", amount, rate, params)


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def buy(
    self, pair: str, ordertype: str, amount: float, rate: float, time_in_force: str
) -> Dict:
    if self._config["dry_run"]:
        dry_order = self.dry_run_order(pair, ordertype, "buy", amount, rate)
        return dry_order

    params = self._params.copy()
    if time_in_force != "gtc" and ordertype != "market":
        params.update({"timeInForce": time_in_force})

    return self.create_order(pair, ordertype, "buy", amount, rate, params)