internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: freqtrade/freqtrade

Issue:
Add commands helper in the bot
_Okay it's not an issue, but I don't know how to make a pull request and link my changes, and I don't want to push badly, even in develop branch._

Just wanted to add the bot's commands... In a /help command !
Maybe useful for other people.

Hopefully, changes are very simple.

Add line 49 of telegram.py:

`CommandHandler('help', _help),`

Then, add after performance definition command (for example):

> @authorized_only
def _help(bot: Bot, update: Update) -> None:
    """
    Handler for /help.
    Show commands of the bot
    :param bot: telegram bot
    :param update: message update
    :return: None
    """
    message = """
*/start:* `Starts the trader`
*/stop:* `Stops the trader`
*/status:* `Lists all open trades`
*/profit:* `Lists cumulative profit from all finished trades`
*/forcesell <trade_id>:* `Instantly sells the given trade (Ignoring minimum_roi).`
*/performance:* `Show performance of each finished trade grouped by pair`
    """
    send_msg(message, bot=bot)

When you send `/help` in your Telegram bot, you receive all available commands.

And because I suck with markdown formatting, I add the modified telegram.py (renamed with .txt extension).

[telegram.txt](https://github.com/gcarq/freqtrade/files/1346420/telegram.txt)







Discussion:

Resolving patch:
diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py
--- a/freqtrade/rpc/telegram.py
+++ b/freqtrade/rpc/telegram.py
@@ -45,6 +45,7 @@ def init(config: dict) -> None:
         CommandHandler('stop', _stop),
         CommandHandler('forcesell', _forcesell),
         CommandHandler('performance', _performance),
+        CommandHandler('help', _help),
     ]
     for handle in handles:
         _updater.dispatcher.add_handler(handle)
@@ -301,6 +302,27 @@ def _performance(bot: Bot, update: Update) -> None:
     send_msg(message, parse_mode=ParseMode.HTML)
 
 
+@authorized_only
+def _help(bot: Bot, update: Update) -> None:
+    """
+    Handler for /help.
+    Show commands of the bot
+    :param bot: telegram bot
+    :param update: message update
+    :return: None
+    """
+    message = """
+*/start:* `Starts the trader`
+*/stop:* `Stops the trader`
+*/status:* `Lists all open trades`
+*/profit:* `Lists cumulative profit from all finished trades`
+*/forcesell <trade_id>:* `Instantly sells the given trade, regardless of profit`
+*/performance:* `Show performance of each finished trade grouped by pair`
+*/help:* `This help message`
+    """
+    send_msg(message, bot=bot)
+
+
 def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
     """
     Send given markdown message
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@
       install_requires=[
           'python-bittrex==0.1.3',
           'SQLAlchemy==1.1.13',
-          'python-telegram-bot==8.0',
+          'python-telegram-bot==8.1.1',
           'arrow==0.10.0',
           'requests==2.18.4',
           'urllib3==1.22',


Test patch:
Repository: freqtrade/freqtrade

Issue:
DB Migration failing 
##  Describe your environment

  * Python Version: 3.7.0
  * Branch:  Develop
  * Last Commit ID: _____ (`git log --format="%H" -n 1`)
  
## Step 3: Describe the problem:
Running the bot with an old database (causing a migration) has the migration fail with an index exception.

```
018-12-08 20:10:11,026 - freqtrade.wallets - INFO - Wallets synced ...                                                  
2018-12-08 20:10:11,711 - freqtrade.persistence - INFO - Running database migration - backup available as trades_bak0                  2018-12-08 20:10:12,096 - freqtrade - ERROR - Fatal exception!                                                           
Traceback (most recent call last):                                                                                       
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context                              
    context)                                                                                                                           
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute                                 
    cursor.execute(statement, parameters)
sqlite3.OperationalError: index ix_trades_pair already exists


```


Discussion:

Resolving patch:
diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py
--- a/freqtrade/persistence.py
+++ b/freqtrade/persistence.py
@@ -100,6 +100,9 @@ def check_migrate(engine) -> None:
 
         # Schema migration necessary
         engine.execute(f"alter table trades rename to {table_back_name}")
+        # drop indexes on backup table
+        for index in inspector.get_indexes(table_back_name):
+            engine.execute(f"drop index {index['name']}")
         # let SQLAlchemy create the schema as required
         _DECL_BASE.metadata.create_all(engine)
 


Test patch:
diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py
--- a/freqtrade/tests/test_persistence.py
+++ b/freqtrade/tests/test_persistence.py
@@ -446,6 +446,8 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
 
     # Create table using the old format
     engine.execute(create_table_old)
+    engine.execute("create index ix_trades_is_open on trades(is_open)")
+    engine.execute("create index ix_trades_pair on trades(pair)")
     engine.execute(insert_table_old)
 
     # fake previous backup
Repository: freqtrade/freqtrade

Issue:
Hyperopt Resamples
   Python Version: 3.6.7
    CCXT version: 1.18.507
    Branch: Develop
    Last Commit ID: 4ae743e

  
## Step 3: Describe the problem:

self.ticker_interval is not implemented in the hyperopt interface, so you cannot resample data to higher timeframes.




Discussion:
why can't you resample data if you _know_ that, for example, your timeframe set in the config is 5 min and you need data for the 1h timeframe? Just resample from 5 min to 1 h in your strategy, using hardcoded 5 min and 1 h there...


@MichealReed, I implemeting the solution for it (almost done), see the reference to the Pull Request above.

The timeframe used by the bot will be available as `metadata['timeframe']` in the populate_*() methods in both strategies and hyperopts.



Resolving patch:
diff --git a/freqtrade/optimize/hyperopt_interface.py b/freqtrade/optimize/hyperopt_interface.py
--- a/freqtrade/optimize/hyperopt_interface.py
+++ b/freqtrade/optimize/hyperopt_interface.py
@@ -20,6 +20,7 @@ class IHyperOpt(ABC):
         stoploss -> float: optimal stoploss designed for the strategy
         ticker_interval -> int: value of the ticker interval to use for the strategy
     """
+    ticker_interval: str
 
     @staticmethod
     @abstractmethod
diff --git a/freqtrade/resolvers/hyperopt_resolver.py b/freqtrade/resolvers/hyperopt_resolver.py
--- a/freqtrade/resolvers/hyperopt_resolver.py
+++ b/freqtrade/resolvers/hyperopt_resolver.py
@@ -32,6 +32,9 @@ def __init__(self, config: Optional[Dict] = None) -> None:
         hyperopt_name = config.get('hyperopt') or DEFAULT_HYPEROPT
         self.hyperopt = self._load_hyperopt(hyperopt_name, extra_dir=config.get('hyperopt_path'))
 
+        # Assign ticker_interval to be used in hyperopt
+        self.hyperopt.__class__.ticker_interval = str(config['ticker_interval'])
+
         if not hasattr(self.hyperopt, 'populate_buy_trend'):
             logger.warning("Custom Hyperopt does not provide populate_buy_trend. "
                            "Using populate_buy_trend from DefaultStrategy.")


Test patch:
diff --git a/freqtrade/tests/optimize/test_hyperopt.py b/freqtrade/tests/optimize/test_hyperopt.py
--- a/freqtrade/tests/optimize/test_hyperopt.py
+++ b/freqtrade/tests/optimize/test_hyperopt.py
@@ -167,6 +167,7 @@ def test_hyperoptresolver(mocker, default_conf, caplog) -> None:
                    "Using populate_sell_trend from DefaultStrategy.", caplog.record_tuples)
     assert log_has("Custom Hyperopt does not provide populate_buy_trend. "
                    "Using populate_buy_trend from DefaultStrategy.", caplog.record_tuples)
+    assert hasattr(x, "ticker_interval")
 
 
 def test_start(mocker, default_conf, caplog) -> None:
Repository: freqtrade/freqtrade

Issue:
hyperopt don't use the dataframe indicators of populate_indicators (of curent file) when optimize only roi stoploss
## Step 3: Describe the problem:

when running hyperopt with --spaces roi stoploss the populate_buy_trend use the indicators of i think default_strategy instead of use the indicators of the populate_indicators of the current file.

It raise an keyerror exception because he don't find the indicator.

### Steps to reproduce:

  1. Create a custom indicator in hyperopt populate_indicators 
  2. run hyperopt with --spaces roi stoploss
  3. freqtrade raise a key error because he don't find the indicator in the dataframe.

Have a nice day
  

hyperopt don't use the dataframe indicators of populate_indicators (of curent file) when optimize only roi stoploss
## Step 3: Describe the problem:

when running hyperopt with --spaces roi stoploss the populate_buy_trend use the indicators of i think default_strategy instead of use the indicators of the populate_indicators of the current file.

It raise an keyerror exception because he don't find the indicator.

### Steps to reproduce:

  1. Create a custom indicator in hyperopt populate_indicators 
  2. run hyperopt with --spaces roi stoploss
  3. freqtrade raise a key error because he don't find the indicator in the dataframe.

Have a nice day
  



Discussion:

Resolving patch:
diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py
--- a/freqtrade/optimize/hyperopt.py
+++ b/freqtrade/optimize/hyperopt.py
@@ -288,9 +288,8 @@ def start(self) -> None:
             (max_date - min_date).days
         )
 
-        if self.has_space('buy') or self.has_space('sell'):
-            self.strategy.advise_indicators = \
-                self.custom_hyperopt.populate_indicators  # type: ignore
+        self.strategy.advise_indicators = \
+            self.custom_hyperopt.populate_indicators  # type: ignore
 
         preprocessed = self.strategy.tickerdata_to_dataframe(data)
 


Test patch:
Repository: freqtrade/freqtrade

Issue:
plot_dataframe.py
## Step 1: Have you search for this issue before posting it?

Couldn't find similar issue, so starting a new issue.

## Step 2: Describe your environment

  * Python Version: Python 3.6.8
  * CCXT version: ccxt==1.18.992
  * Branch: Master 
  * Last Commit ID: b8713a515e960f1ffadcf1c7ee62c4bee80b506c
  
## Step 3: Describe the problem:
Unable to plot my backtest results.

*Explain the problem you have encountered*
Executing the following command results in error.
Error
### Steps to reproduce:

`
        Command: python3 scripts/plot_dataframe.py -s EMACrossHTF1h --export 
        EMACrossHTF1h_results.json -p BTC/USDT --datadir user_data/data/binance/
`
  
### Observed Results:

Error is thrown. 

### Relevant code exceptions or logs:
`
          File "scripts/plot_dataframe.py", line 113, in <module>
            main(sys.argv[1:])
          File "scripts/plot_dataframe.py", line 107, in main
            plot_parse_args(sysargv)
          File "scripts/plot_dataframe.py", line 58, in analyse_and_plot_pairs
            plot_elements = init_plotscript(config)
          File "/home/ubuntu/freqtrade/freqtrade/plot/plotting.py", line 57, in init_plotscript
            trades = load_trades(config)
          File "/home/ubuntu/freqtrade/freqtrade/data/btanalysis.py", line 113, in load_trades
            return load_backtest_data(Path(config["exportfilename"]))
          File "/home/ubuntu/freqtrade/freqtrade/data/btanalysis.py", line 33, in load_backtest_data
            raise ValueError("File {filename} does not exist.")
        ValueError: File {filename} does not exist.
`



Discussion:
it's a syntax error i think ...

you'll need `python3 scripts/plot_dataframe.py -s EMACrossHTF1h --export trades --export-filename EMACrossHTF1h_results.json -p BTC/USDT --datadir user_data/data/binance/`

--export does not take a filename - hence the filename uses the default, which you did apparently not use

Resolving patch:
diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py
--- a/freqtrade/data/btanalysis.py
+++ b/freqtrade/data/btanalysis.py
@@ -30,7 +30,7 @@ def load_backtest_data(filename) -> pd.DataFrame:
         filename = Path(filename)
 
     if not filename.is_file():
-        raise ValueError("File {filename} does not exist.")
+        raise ValueError(f"File {filename} does not exist.")
 
     with filename.open() as file:
         data = json_load(file)


Test patch:
Repository: freqtrade/freqtrade

Issue:
Strategy list is space separated
`--strategy-list Strat1,Strat2` produces an error while `--strategy-list Strat1 Strat2` works

It became a space separated list somehow while its description states it's a comma-separated list:
```
  --strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
                        Provide **a comma-separated list** of strategies to
                        backtest. Please note that ticker-interval needs to be
                        set either in config or via command line. When using
                        this together with `--export trades`, the strategy-
                        name is injected into the filename (so `backtest-
                        data.json` becomes `backtest-data-
                        DefaultStrategy.json`
```

Which direction this should be fixed to?



Discussion:

Resolving patch:
diff --git a/freqtrade/configuration/cli_options.py b/freqtrade/configuration/cli_options.py
--- a/freqtrade/configuration/cli_options.py
+++ b/freqtrade/configuration/cli_options.py
@@ -130,7 +130,7 @@ def __init__(self, *args, **kwargs):
     ),
     "strategy_list": Arg(
         '--strategy-list',
-        help='Provide a comma-separated list of strategies to backtest. '
+        help='Provide a space-separated list of strategies to backtest. '
         'Please note that ticker-interval needs to be set either in config '
         'or via command line. When using this together with `--export trades`, '
         'the strategy-name is injected into the filename '


Test patch:
Repository: freqtrade/freqtrade

Issue:
Freqtrade create 2 buys with same pair...
i noticed that the bot takes two buys with same pair 
![image](https://user-images.githubusercontent.com/39638559/68229578-ce9e5a00-fff7-11e9-9cd8-97181a00c6dc.png)

if i activate  this...
![image](https://user-images.githubusercontent.com/39638559/68229485-a7e02380-fff7-11e9-9a02-13e635eee6a7.png)

... is this a feature or a bug ? :-)


Discussion:
definitely not a feature ...
i don't think it's to do with the buy-strategy though...

Are you able to access the database (via sqlbrowser or sqlite3 ) and run the following command and show us the output?
(first line is for sqlite3
```
.headers on 
select * from trades where id in (32, 33, 36, 37, 38, 39, 40, 31);
```

Also, still got the logs of the buys for these trades? that'll help us identify the problem.

uff so iam able to access the database via a sqlbrowser but where should i run this command? 
then run `select * from trades where id in (32, 33, 36, 37, 38, 39, 40, 31);` only ...

sqlitebrowser has a "Execute SQL" tab ... insert this command and it should show you 8 rows ... 
![image](https://user-images.githubusercontent.com/39638559/68239127-bd127d80-000a-11ea-860b-4433afb06338.png)
 like this?
Yes
That's very odd, never seen something like this before...

Have you got the logs from when these buys happen ...? 

Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -319,8 +319,7 @@ def create_trades(self) -> bool:
                         (bidstrat_check_depth_of_market.get('bids_to_ask_delta', 0) > 0):
                     if self._check_depth_of_market_buy(_pair, bidstrat_check_depth_of_market):
                         buycount += self.execute_buy(_pair, stake_amount)
-                    else:
-                        continue
+                    continue
 
                 buycount += self.execute_buy(_pair, stake_amount)
 


Test patch:
diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py
--- a/tests/test_freqtradebot.py
+++ b/tests/test_freqtradebot.py
@@ -3213,6 +3213,8 @@ def test_order_book_depth_of_market(default_conf, ticker, limit_buy_order, fee,
     assert trade.open_date is not None
     assert trade.exchange == 'bittrex'
 
+    assert len(Trade.query.all()) == 1
+
     # Simulate fulfilled LIMIT_BUY order for trade
     trade.update(limit_buy_order)
Repository: freqtrade/freqtrade

Issue:
db-url defaults during dryrun
In the [docker doc](https://www.freqtrade.io/en/latest/docker/#create-your-database-file) the doc recommend to create the database in live with  ` touch tradesv3.sqlite`, and in dryrun with`touch tradesv3.dryrun.sqlite`.

But then in the note below it says :

> db-url defaults to sqlite:///tradesv3.sqlite but it defaults to sqlite:// if dry_run=True is being used. To override this behaviour use a custom db-url value: i.e.: --db-url sqlite:///tradesv3.dryrun.sqlite

1/ not sure end user know what _sqlite://_ means : create in memory or create a default file, but we don't know his name ?
2/ When we say the end-user to create the files `touch tradesv3.dryrun.sqlite` for dry-run then the default should be _sqlite:///tradesv3.dryrun.sqlite_ and not _sqlite://_ .If we give recommandations for naming the databases in the doc, then we should take this in account for default. And It can be seen like a convention over configuration approach.

Have a nice day.



Discussion:
There is nothing to discuss 😄 , this badly covered in the docs, should be improved...
Agreed, i also don't like the approach to use in-memory as default for dry-run - I expect users to want to analyze the results after a dry-run - so without a database we remove this possibility - which can be a pain if you get started.

So i personally would change this to default to a "persisted" database - not just limit us to aligning the docs related to this.


Resolving patch:
diff --git a/freqtrade/constants.py b/freqtrade/constants.py
--- a/freqtrade/constants.py
+++ b/freqtrade/constants.py
@@ -10,7 +10,7 @@
 RETRY_TIMEOUT = 30  # sec
 DEFAULT_HYPEROPT_LOSS = 'DefaultHyperOptLoss'
 DEFAULT_DB_PROD_URL = 'sqlite:///tradesv3.sqlite'
-DEFAULT_DB_DRYRUN_URL = 'sqlite://'
+DEFAULT_DB_DRYRUN_URL = 'sqlite:///tradesv3.dryrun.sqlite'
 UNLIMITED_STAKE_AMOUNT = 'unlimited'
 DEFAULT_AMOUNT_RESERVE_PERCENT = 0.05
 REQUIRED_ORDERTIF = ['buy', 'sell']


Test patch:
diff --git a/tests/test_persistence.py b/tests/test_persistence.py
--- a/tests/test_persistence.py
+++ b/tests/test_persistence.py
@@ -100,7 +100,7 @@ def test_init_dryrun_db(default_conf, mocker):
 
     init(default_conf['db_url'], default_conf['dry_run'])
     assert create_engine_mock.call_count == 1
-    assert create_engine_mock.mock_calls[0][1][0] == 'sqlite://'
+    assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.dryrun.sqlite'
 
 
 @pytest.mark.usefixtures("init_persistence")
Repository: freqtrade/freqtrade

Issue:
UserWarning: Boolean Series key will be reindexed to match DataFrame index.
## Step 1: Have you search for this issue before posting it?

Yes

## Step 2: Describe your environment

  * Operating system: MacOS
  * Python Version: Python 3.7.5 (`python -V`)
  * CCXT version: 1.21.76 (`pip freeze | grep ccxt`)
  * Branch: Develop
  * Last Commit ID: 66415d48d4d9d42aaeec6beb1b8fc58dd58cf022 (`git log --format="%H" -n 1`)
  
## Step 3: Describe the problem:

When running the code:

`freqtrade backtesting --strategy Low_BB -i 1h`

It prints out the report just fine except there's an error interrupting these lines:

`
========================================================= SELL REASON STATS =========================================================
/Users/yazeed/Sites/freqtrade/freqtrade/optimize/optimize_reports.py:73: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  loss = len(result[results['profit_abs'] < 0])
| Sell Reason        |   Count |   Profit |   Loss |   Profit % |
|:-------------------|--------:|---------:|-------:|-----------:|
| trailing_stop_loss |     580 |      350 |    230 |       1.22 |
| stop_loss          |     151 |        0 |    151 |      -1.7  |
`

The error:

`/Users/yazeed/Sites/freqtrade/freqtrade/optimize/optimize_reports.py:73: UserWarning: Boolean Series key will be reindexed to match DataFrame index.`


Discussion:

Resolving patch:
diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py
--- a/freqtrade/optimize/optimize_reports.py
+++ b/freqtrade/optimize/optimize_reports.py
@@ -70,7 +70,7 @@ def generate_text_table_sell_reason(data: Dict[str, Dict], results: DataFrame) -
     for reason, count in results['sell_reason'].value_counts().iteritems():
         result = results.loc[results['sell_reason'] == reason]
         profit = len(result[result['profit_abs'] >= 0])
-        loss = len(result[results['profit_abs'] < 0])
+        loss = len(result[result['profit_abs'] < 0])
         profit_mean = round(result['profit_percent'].mean() * 100.0, 2)
         tabular_data.append([reason.value, count, profit, loss, profit_mean])
     return tabulate(tabular_data, headers=headers, tablefmt="pipe")


Test patch:
Repository: freqtrade/freqtrade

Issue:
bug in qtpylib max<->min
a very simple bug.. the functions rolling_min/rolling_max are copies..

```
diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py
index b3b2ac53..bef14039 100644
--- a/freqtrade/vendor/qtpylib/indicators.py
+++ b/freqtrade/vendor/qtpylib/indicators.py
@@ -288,9 +288,9 @@ def rolling_min(series, window=14, min_periods=None):
 def rolling_max(series, window=14, min_periods=None):
     min_periods = window if min_periods is None else min_periods
     try:
-        return series.rolling(window=window, min_periods=min_periods).min()
+        return series.rolling(window=window, min_periods=min_periods).max()
     except Exception as e:  # noqa: F841
-        return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
+        return pd.Series(series).rolling(window=window, min_periods=min_periods).max()
```




Discussion:
(fixed formatting)


Resolving patch:
diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py
--- a/freqtrade/vendor/qtpylib/indicators.py
+++ b/freqtrade/vendor/qtpylib/indicators.py
@@ -288,9 +288,9 @@ def rolling_min(series, window=14, min_periods=None):
 def rolling_max(series, window=14, min_periods=None):
     min_periods = window if min_periods is None else min_periods
     try:
-        return series.rolling(window=window, min_periods=min_periods).min()
+        return series.rolling(window=window, min_periods=min_periods).max()
     except Exception as e:  # noqa: F841
-        return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
+        return pd.Series(series).rolling(window=window, min_periods=min_periods).max()
 
 
 # ---------------------------------------------


Test patch: