# Buggy code
def execute_buy(
    self, pair: str, stake_amount: float, price: Optional[float] = None
) -> bool:
    """
    Executes a limit buy for the given pair
    :param pair: pair for which we want to create a LIMIT_BUY
    :return: None
    """
    time_in_force = self.strategy.order_time_in_force["buy"]

    if price:
        buy_limit_requested = price
    else:
        # Calculate price
        buy_limit_requested = self.get_buy_rate(pair)

    min_stake_amount = self._get_min_pair_stake_amount(pair, buy_limit_requested)
    if min_stake_amount is not None and min_stake_amount > stake_amount:
        logger.warning(
            f"Can't open a new trade for {pair}: stake amount "
            f"is too small ({stake_amount} < {min_stake_amount})"
        )
        return False

    amount = stake_amount / buy_limit_requested
    order_type = self.strategy.order_types["buy"]
    order = self.exchange.buy(
        pair=pair,
        ordertype=order_type,
        amount=amount,
        rate=buy_limit_requested,
        time_in_force=time_in_force,
    )
    order_id = order["id"]
    order_status = order.get("status", None)

    # we assume the order is executed at the price requested
    buy_limit_filled_price = buy_limit_requested

    if order_status == "expired" or order_status == "rejected":
        order_tif = self.strategy.order_time_in_force["buy"]

        # return false if the order is not filled
        if float(order["filled"]) == 0:
            logger.warning(
                "Buy %s order with time in force %s for %s is %s by %s."
                " zero amount is fulfilled.",
                order_tif,
                order_type,
                pair,
                order_status,
                self.exchange.name,
            )
            return False
        else:
            # the order is partially fulfilled
            # in case of IOC orders we can check immediately
            # if the order is fulfilled fully or partially
            logger.warning(
                "Buy %s order with time in force %s for %s is %s by %s."
                " %s amount fulfilled out of %s (%s remaining which is canceled).",
                order_tif,
                order_type,
                pair,
                order_status,
                self.exchange.name,
                order["filled"],
                order["amount"],
                order["remaining"],
            )
            stake_amount = order["cost"]
            amount = order["amount"]
            buy_limit_filled_price = order["price"]
            order_id = None

    # in case of FOK the order may be filled immediately and fully
    elif order_status == "closed":
        stake_amount = order["cost"]
        amount = order["amount"]
        buy_limit_filled_price = order["price"]

    # Fee is applied twice because we make a LIMIT_BUY and LIMIT_SELL
    fee = self.exchange.get_fee(symbol=pair, taker_or_maker="maker")
    trade = Trade(
        pair=pair,
        stake_amount=stake_amount,
        amount=amount,
        fee_open=fee,
        fee_close=fee,
        open_rate=buy_limit_filled_price,
        open_rate_requested=buy_limit_requested,
        open_date=datetime.utcnow(),
        exchange=self.exchange.id,
        open_order_id=order_id,
        strategy=self.strategy.get_strategy_name(),
        ticker_interval=timeframe_to_minutes(self.config["ticker_interval"]),
    )

    self._notify_buy(trade, order_type)

    # Update fees if order is closed
    if order_status == "closed":
        self.update_trade_state(trade, order)

    Trade.session.add(trade)
    Trade.session.flush()

    # Updating wallets
    self.wallets.update()

    return 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 execute_buy(
    self, pair: str, stake_amount: float, price: Optional[float] = None
) -> bool:
    """
    Executes a limit buy for the given pair
    :param pair: pair for which we want to create a LIMIT_BUY
    :return: True if a buy order is created, false if it fails.
    """
    time_in_force = self.strategy.order_time_in_force["buy"]

    if price:
        buy_limit_requested = price
    else:
        # Calculate price
        buy_limit_requested = self.get_buy_rate(pair, True)

    min_stake_amount = self._get_min_pair_stake_amount(pair, buy_limit_requested)
    if min_stake_amount is not None and min_stake_amount > stake_amount:
        logger.warning(
            f"Can't open a new trade for {pair}: stake amount "
            f"is too small ({stake_amount} < {min_stake_amount})"
        )
        return False

    amount = stake_amount / buy_limit_requested
    order_type = self.strategy.order_types["buy"]
    order = self.exchange.buy(
        pair=pair,
        ordertype=order_type,
        amount=amount,
        rate=buy_limit_requested,
        time_in_force=time_in_force,
    )
    order_id = order["id"]
    order_status = order.get("status", None)

    # we assume the order is executed at the price requested
    buy_limit_filled_price = buy_limit_requested

    if order_status == "expired" or order_status == "rejected":
        order_tif = self.strategy.order_time_in_force["buy"]

        # return false if the order is not filled
        if float(order["filled"]) == 0:
            logger.warning(
                "Buy %s order with time in force %s for %s is %s by %s."
                " zero amount is fulfilled.",
                order_tif,
                order_type,
                pair,
                order_status,
                self.exchange.name,
            )
            return False
        else:
            # the order is partially fulfilled
            # in case of IOC orders we can check immediately
            # if the order is fulfilled fully or partially
            logger.warning(
                "Buy %s order with time in force %s for %s is %s by %s."
                " %s amount fulfilled out of %s (%s remaining which is canceled).",
                order_tif,
                order_type,
                pair,
                order_status,
                self.exchange.name,
                order["filled"],
                order["amount"],
                order["remaining"],
            )
            stake_amount = order["cost"]
            amount = order["amount"]
            buy_limit_filled_price = order["price"]
            order_id = None

    # in case of FOK the order may be filled immediately and fully
    elif order_status == "closed":
        stake_amount = order["cost"]
        amount = order["amount"]
        buy_limit_filled_price = order["price"]

    # Fee is applied twice because we make a LIMIT_BUY and LIMIT_SELL
    fee = self.exchange.get_fee(symbol=pair, taker_or_maker="maker")
    trade = Trade(
        pair=pair,
        stake_amount=stake_amount,
        amount=amount,
        fee_open=fee,
        fee_close=fee,
        open_rate=buy_limit_filled_price,
        open_rate_requested=buy_limit_requested,
        open_date=datetime.utcnow(),
        exchange=self.exchange.id,
        open_order_id=order_id,
        strategy=self.strategy.get_strategy_name(),
        ticker_interval=timeframe_to_minutes(self.config["ticker_interval"]),
    )

    # Update fees if order is closed
    if order_status == "closed":
        self.update_trade_state(trade, order)

    Trade.session.add(trade)
    Trade.session.flush()

    # Updating wallets
    self.wallets.update()

    self._notify_buy(trade, order_type)

    return True