diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..2cbbc59cb --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,30 @@ +## Step 1: Have you search for this issue before posting it? + +If you have discovered a bug in the bot, please [search our issue tracker](https://github.com/gcarq/freqtrade/issues?q=is%3Aissue). +If it hasn't been reported, please create a new issue. + +## Step 2: Describe your environment + + * Python Version: _____ (`python -V`) + * Branch: Master | Develop + * Last Commit ID: _____ (`git log --format="%H" -n 1`) + +## Step 3: Describe the problem: +*Explain the problem you have encountered* + +### Steps to reproduce: + + 1. _____ + 2. _____ + 3. _____ + +### Observed Results: + + * What happened? + * What did you expect to happen? + +### Relevant code exceptions or logs: + + ``` + // paste your log here + ``` diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..ae79dd8f0 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,15 @@ +Thank you for sending your pull request. But first, have you included +unit tests, and is your code PEP8 conformant? [More details](https://github.com/gcarq/freqtrade/blob/develop/CONTRIBUTING.md) + +## Summary +Explain in one sentence the goal of this PR + +Solve the issue: #___ + +## Quick changelog + +- +- + +## What's new? +*Explain in details what this PR solve or improve. You can include visuals.* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21dcda44a..967f57b65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,16 +1,21 @@ +# Contribute to freqtrade + Feel like our bot is missing a feature? We welcome your pull requests! Few pointers for contributions: - Create your PR against the `develop` branch, not `master`. -- New features need to contain unit tests and must be PEP8 conformant (max-line-length = 100). +- New features need to contain unit tests and must be PEP8 +conformant (max-line-length = 100). If you are unsure, discuss the feature on our [Slack](https://join.slack.com/t/highfrequencybot/shared_invite/enQtMjQ5NTM0OTYzMzY3LWMxYzE3M2MxNDdjMGM3ZTYwNzFjMGIwZGRjNTc3ZGU3MGE3NzdmZGMwNmU3NDM5ZTNmM2Y3NjRiNzk4NmM4OGE) or in a [issue](https://github.com/gcarq/freqtrade/issues) before a PR. -Before sending the PR: -## Run unit tests +**Before sending the PR:** -All unit tests must pass. If a unit test is broken, change your code to make it pass. It means you have introduced a regression +## 1. Run unit tests + +All unit tests must pass. If a unit test is broken, change your code to +make it pass. It means you have introduced a regression. **Test the whole project** ```bash @@ -26,7 +31,8 @@ pytest freqtrade/tests/test_.py ```bash pytest freqtrade/tests/test_.py::test_ ``` -## Test if your code is PEP8 compliant + +## 2. Test if your code is PEP8 compliant **Install packages** (If not already installed) ```bash pip3.6 install flake8 coveralls diff --git a/README.md b/README.md index 57000301f..7899d24bc 100644 --- a/README.md +++ b/README.md @@ -1,160 +1,137 @@ # freqtrade [![Build Status](https://travis-ci.org/gcarq/freqtrade.svg?branch=develop)](https://travis-ci.org/gcarq/freqtrade) -[![Coverage Status](https://coveralls.io/repos/github/gcarq/freqtrade/badge.svg?branch=develop)](https://coveralls.io/github/gcarq/freqtrade?branch=develop) +[![Coverage Status](https://coveralls.io/repos/github/gcarq/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/gcarq/freqtrade?branch=develop) -Simple High frequency trading bot for crypto currencies. -Currently supports trading on Bittrex exchange. +Simple High frequency trading bot for crypto currencies designed to +support multi exchanges and be controlled via Telegram. -This software is for educational purposes only. -Don't risk money which you are afraid to lose. +![freqtrade](https://raw.githubusercontent.com/gcarq/freqtrade/develop/docs/assets/freqtrade-screenshot.png) -The command interface is accessible via Telegram (not required). -Just register a new bot on https://telegram.me/BotFather -and enter the telegram `token` and your `chat_id` in `config.json` +## Disclaimer +This software is for educational purposes only. Do not risk money which +you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS +AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS. -Persistence is achieved through sqlite. +Always start by running a trading bot in Dry-run and do not engage money +before you understand how it works and what profit/loss you should +expect. -### Telegram RPC commands: -* /start: Starts the trader -* /stop: Stops the trader -* /status [table]: Lists all open trades -* /count: Displays number of open trades -* /profit: Lists cumulative profit from all finished trades -* /forcesell |all: Instantly sells the given trade (Ignoring `minimum_roi`). -* /performance: Show performance of each finished trade grouped by pair -* /balance: Show account balance per currency -* /daily : Shows profit or loss per day, over the last n days -* /help: Show help message -* /version: Show version +We strongly recommend you to have coding and Python knowledge. Do not +hesitate to read the source code and understand the mechanism of this bot. -### Config -`minimal_roi` is a JSON object where the key is a duration -in minutes and the value is the minimum ROI in percent. -See the example below: -``` -"minimal_roi": { - "40": 0.0, # Sell after 40 minutes if the profit is not negative - "30": 0.01, # Sell after 30 minutes if there is at least 1% profit - "20": 0.02, # Sell after 20 minutes if there is at least 2% profit - "0": 0.04 # Sell immediately if there is at least 4% profit -}, -``` +## Table of Contents +- [Features](#features) +- [Quick start](#quick-start) +- [Documentations](https://github.com/gcarq/freqtrade/blob/develop/docs/index.md) + - [Installation](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md) +- [Support](#support) + - [Help](#help--slack) + - [Bugs](#bugs--issues) + - [Feature Requests](#feature-requests) + - [Pull Requests](#pull-requests) +- [Basic Usage](#basic-usage) + - [Bot commands](#bot-commands) + - [Telegram RPC commands](#telegram-rpc-commands) +- [Requirements](#requirements) + - [Min hardware required](#min-hardware-required) + - [Software requirements](#software-requirements) -`stoploss` is loss in percentage that should trigger a sale. -For example value `-0.10` will cause immediate sell if the -profit dips below -10% for a given trade. This parameter is optional. +## Branches +The project is currently setup in two main branches: +- `develop` - This branch has often new features, but might also cause +breaking changes. +- `master` - This branch contains the latest stable release. The bot +'should' be stable on this branch, and is generally well tested. -`initial_state` is an optional field that defines the initial application state. -Possible values are `running` or `stopped`. (default=`running`) -If the value is `stopped` the bot has to be started with `/start` first. +## Features +- [x] **Based on Python 3.6+**: For botting on any operating system - +Windows, macOS and Linux +- [x] **Persistence**: Persistence is achieved through sqlite +- [x] **Dry-run**: Run the bot without playing money. +- [x] **Backtesting**: Run a simulation of your buy/sell strategy. +- [x] **Strategy Optimization**: Optimize your buy/sell strategy +parameters with Hyperopts. +- [x] **Whitelist crypto-currencies**: Select which crypto-currency you +want to trade. +- [x] **Blacklist crypto-currencies**: Select which crypto-currency you +want to avoid. +- [x] **Manageable via Telegram**: Manage the bot with Telegram +- [x] **Display profit/loss in fiat**: Display your profit/loss in +33 fiat. +- [x] **Daily summary of profit/loss**: Provide a daily summary + of your profit/loss. +- [x] **Performance status report**: Provide a performance status of +your current trades. -`ask_last_balance` sets the bidding price. Value `0.0` will use `ask` price, `1.0` will -use the `last` price and values between those interpolate between ask and last -price. Using `ask` price will guarantee quick success in bid, but bot will also -end up paying more then would probably have been necessary. +### Exchange supported +- [x] Bittrex +- [ ] Binance +- [ ] Others -`fiat_display_currency` set the fiat to use for the conversion form coin to -fiat in Telegram. The valid value are: "AUD", "BRL", "CAD", "CHF", -"CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", -"INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", -"RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD". +## Quick start +This quick start section is a very short explanation on how to test the +bot in dry-run. We invite you to read the +[bot documentation](https://github.com/gcarq/freqtrade/blob/develop/docs/index.md) +to ensure you understand how the bot is working. -The other values should be self-explanatory, -if not feel free to raise a github issue. +The following steps are made for Linux/MacOS environment -### Prerequisites -* python3.6 -* sqlite -* [TA-lib](https://github.com/mrjbq7/ta-lib#dependencies) binaries -* Minimal (advised) system requirements: 2GB RAM, 1GB data, 2vCPU - -### Install - -#### Arch Linux - -Use your favorite AUR helper and install `python-freqtrade-git`. - -#### Manually - -`master` branch contains the latest stable release. - -`develop` branch has often new features, but might also cause breaking changes. To use it, you are encouraged to join our [slack channel](https://join.slack.com/t/highfrequencybot/shared_invite/enQtMjQ5NTM0OTYzMzY3LWMxYzE3M2MxNDdjMGM3ZTYwNzFjMGIwZGRjNTc3ZGU3MGE3NzdmZGMwNmU3NDM5ZTNmM2Y3NjRiNzk4NmM4OGE). - -``` -$ cd freqtrade/ -# copy example config. Dont forget to insert your api keys -$ cp config.json.example config.json -$ python -m venv .env -$ source .env/bin/activate -$ pip install -r requirements.txt -$ pip install -e . -$ ./freqtrade/main.py -``` - -There is also an [article](https://www.sales4k.com/blockchain/high-frequency-trading-bot-tutorial/) about how to setup the bot (thanks [@gurghet](https://github.com/gurghet)).* - -\* *Note:* that article was written for an earlier version, so it may be outdated - -#### Docker - -Building the image: - -``` -$ cd freqtrade -$ docker build -t freqtrade . -``` - -For security reasons, your configuration file will not be included in the -image, you will need to bind mount it. It is also advised to bind mount -a SQLite database file (see second example) to keep it between updates. - -You can run a one-off container that is immediately deleted upon exiting with -the following command (config.json must be in the current working directory): - -``` -$ docker run --rm -v `pwd`/config.json:/freqtrade/config.json -it freqtrade -``` - -To run a restartable instance in the background (feel free to place your -configuration and database files wherever it feels comfortable on your -filesystem): - -``` -$ cd ~/.freq -$ touch tradesv3.sqlite -$ docker run -d \ - --name freqtrade \ - -v ~/.freq/config.json:/freqtrade/config.json \ - -v ~/.freq/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \ - freqtrade -``` -If you are using `dry_run=True` it's not necessary to mount `tradesv3.sqlite`. - -You can then use the following commands to monitor and manage your container: - -``` -$ docker logs freqtrade -$ docker logs -f freqtrade -$ docker restart freqtrade -$ docker stop freqtrade -$ docker start freqtrade -``` - -You do not need to rebuild the image for configuration -changes, it will suffice to edit `config.json` and restart the container. - -#### systemd service file -Copy `./freqtrade.service` to your systemd user directory (usually `~/.config/systemd/user`) -and update `WorkingDirectory` and `ExecStart` to match your setup. -After that you can start the daemon with: +**1. Clone the repo** ```bash -$ systemctl --user start freqtrade +git clone git@github.com:gcarq/freqtrade.git +git checkout develop +cd freqtrade +``` +**2. Create the config file** +Switch `"dry_run": true,` +```bash +cp config.json.example config.json +vi config.json +``` +**3. Build your docker image and run it** +```bash +docker build -t freqtrade . +docker run --rm -v `pwd`/config.json:/freqtrade/config.json -it freqtrade ``` -### Usage -``` + +### Help / Slack +For any questions not covered by the documentation or for further +information about the bot, we encourage you to join our slack channel. +- [Click here to join Slack channel](https://join.slack.com/t/highfrequencybot/shared_invite/enQtMjQ5NTM0OTYzMzY3LWMxYzE3M2MxNDdjMGM3ZTYwNzFjMGIwZGRjNTc3ZGU3MGE3NzdmZGMwNmU3NDM5ZTNmM2Y3NjRiNzk4NmM4OGE). + +### [Bugs / Issues](https://github.com/gcarq/freqtrade/issues?q=is%3Aissue) +If you discover a bug in the bot, please +[search our issue tracker](https://github.com/gcarq/freqtrade/issues?q=is%3Aissue) +first. If it hasn't been reported, please +[create a new issue](https://github.com/gcarq/freqtrade/issues/new) and +ensure you follow the template guide so that our team can assist you as +quickly as possible. + +### [Feature Requests](https://github.com/gcarq/freqtrade/labels/enhancement) +Have you a great idea to improve the bot you want to share? Please, +first search if this feature was not [already discussed](https://github.com/gcarq/freqtrade/labels/enhancement). +If it hasn't been requested, please +[create a new request](https://github.com/gcarq/freqtrade/issues/new) +and ensure you follow the template guide so that it does not get lost +in the bug reports. + +### [Pull Requests](https://github.com/gcarq/freqtrade/pulls) +Feel like our bot is missing a feature? We welcome your pull requests! +Please read our +[Contributing document](https://github.com/gcarq/freqtrade/blob/develop/CONTRIBUTING.md) +to understand the requirements before sending your pull-requests. + +**Important:** Always create your PR against the `develop` branch, not +`master`. + +## Basic Usage + +### Bot commands + +```bash usage: main.py [-h] [-c PATH] [-v] [--version] [--dynamic-whitelist [INT]] [--dry-run-db] {backtesting,hyperopt} ... @@ -179,86 +156,39 @@ optional arguments: "tradesv3.dry_run.sqlite" instead of memory DB. Work only if dry_run is enabled. ``` +More details on: +- [How to run the bot](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#bot-commands) +- [How to use Backtesting](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#backtesting-commands) +- [How to use Hyperopt](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#hyperopt-commands) + +### Telegram RPC commands +Telegram is not mandatory. However, this is a great way to control your +bot. More details on our +[documentation](https://github.com/gcarq/freqtrade/blob/develop/docs/index.md) -#### Dynamic whitelist example -Per default `--dynamic-whitelist` will retrieve the 20 currencies based -on BaseVolume. This value can be changed when you run the script. +- `/start`: Starts the trader +- `/stop`: Stops the trader +- `/status [table]`: Lists all open trades +- `/count`: Displays number of open trades +- `/profit`: Lists cumulative profit from all finished trades +- `/forcesell |all`: Instantly sells the given trade +(Ignoring `minimum_roi`). +- `/performance`: Show performance of each finished trade grouped by pair +- `/balance`: Show account balance per currency +- `/daily `: Shows profit or loss per day, over the last n days +- `/help`: Show help message +- `/version`: Show version -**By Default** -Get the 20 currencies based on BaseVolume. -```bash -freqtrade --dynamic-whitelist -``` +## Requirements -**Customize the number of currencies to retrieve** -Get the 30 currencies based on BaseVolume. -```bash -freqtrade --dynamic-whitelist 30 -``` +### Min hardware required +To run this bot we recommend you a cloud instance with a minimum of: +* Minimal (advised) system requirements: 2GB RAM, 1GB disk space, 2vCPU -**Exception** -`--dynamic-whitelist` must be greater than 0. If you enter 0 or a -negative value (e.g -2), `--dynamic-whitelist` will use the default -value (20). - -### Backtesting - -Backtesting also uses the config specified via `-c/--config`. - -``` -usage: freqtrade backtesting [-h] [-l] [-i INT] [--realistic-simulation] - [-r] - -optional arguments: - -h, --help show this help message and exit - -l, --live using live data - -i INT, --ticker-interval INT - specify ticker interval in minutes (default: 5) - --realistic-simulation - uses max_open_trades from config to simulate real - world limitations - -r, --refresh-pairs-cached - refresh the pairs files in tests/testdata with - the latest data from Bittrex. Use it if you want - to run your backtesting with up-to-date data. -``` - -#### How to use --refresh-pairs-cached parameter? -The first time your run Backtesting, it will take the pairs your have -set in your config file and download data from Bittrex. - -If for any reason you want to update your data set, you use -`--refresh-pairs-cached` to force Backtesting to update the data it has. -**Use it only if you want to update your data set. You will not be able -to come back to the previous version.** - -To test your strategy with latest data, we recommend to continue using -the parameter `-l` or `--live`. - - -### Hyperopt - -It is possible to use hyperopt for trading strategy optimization. -Hyperopt uses an internal config named `OPTIMIZE_CONFIG` located in `freqtrade/optimize/hyperopt.py`. - -``` -usage: freqtrade hyperopt [-h] [-e INT] [--use-mongodb] - -optional arguments: - -h, --help show this help message and exit - -e INT, --epochs INT specify number of epochs (default: 100) - --use-mongodb parallelize evaluations with mongodb (requires mongod - in PATH) - -``` - -### Execute tests - -``` -$ pytest freqtrade -``` - -### Contributing - -We welcome contributions. See our [contribution guide](https://github.com/gcarq/freqtrade/blob/develop/README.md) -for more details. \ No newline at end of file +### Software requirements +- [Python 3.6.x](http://docs.python-guide.org/en/latest/starting/installation/) +- [pip](https://pip.pypa.io/en/stable/installing/) +- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +- [TA-Lib](https://mrjbq7.github.io/ta-lib/install.html) +- [virtualenv](https://virtualenv.pypa.io/en/stable/installation/) (Recommended) +- [Docker](https://www.docker.com/products/docker) (Recommended) diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/docs/assets/freqtrade-screenshot.png b/docs/assets/freqtrade-screenshot.png new file mode 100644 index 000000000..4ad681579 Binary files /dev/null and b/docs/assets/freqtrade-screenshot.png differ diff --git a/docs/backtesting.md b/docs/backtesting.md new file mode 100644 index 000000000..d7073365f --- /dev/null +++ b/docs/backtesting.md @@ -0,0 +1,104 @@ +# Backtesting +This page explains how to validate your strategy performance by using +Backtesting. + +## Table of Contents +- [Test your strategy with Backtesting](#test-your-strategy-with-backtesting) +- [Understand the backtesting result](#understand-the-backtesting-result) + +## Test your strategy with Backtesting +Now you have good Buy and Sell strategies, you want to test it against +real data. This is what we call +[backtesting](https://en.wikipedia.org/wiki/Backtesting). + + +Backtesting will use the crypto-currencies (pair) from your config file +and load static tickers located in +[/freqtrade/tests/testdata](https://github.com/gcarq/freqtrade/tree/develop/freqtrade/tests/testdata). +If the 5 min and 1 min ticker for the crypto-currencies to test is not +already in the `testdata` folder, backtesting will download them +automatically. Testdata files will not be updated until you specify it. + +The result of backtesting will confirm you if your bot as more chance to +make a profit than a loss. + + +The backtesting is very easy with freqtrade. + +### Run a backtesting against the currencies listed in your config file +**With 5 min tickers (Per default)** +```bash +python3 ./freqtrade/main.py backtesting --realistic-simulation +``` + +**With 1 min tickers** +```bash +python3 ./freqtrade/main.py backtesting --realistic-simulation --ticker-interval 1 +``` + +**Reload your testdata files** +```bash +python3 ./freqtrade/main.py backtesting --realistic-simulation --refresh-pairs-cached +``` + +**With live data (do not alter your testdata files)** +```bash +python3 ./freqtrade/main.py backtesting --realistic-simulation --live +``` + +For help about backtesting usage, please refer to +[Backtesting commands](#backtesting-commands). + +## Understand the backtesting result +The most important in the backtesting is to understand the result. + +A backtesting result will look like that: +``` +====================== BACKTESTING REPORT ================================ +pair buy count avg profit % total profit BTC avg duration +-------- ----------- -------------- ------------------ -------------- +BTC_ETH 56 -0.67 -0.00075455 62.3 +BTC_LTC 38 -0.48 -0.00036315 57.9 +BTC_ETC 42 -1.15 -0.00096469 67.0 +BTC_DASH 72 -0.62 -0.00089368 39.9 +BTC_ZEC 45 -0.46 -0.00041387 63.2 +BTC_XLM 24 -0.88 -0.00041846 47.7 +BTC_NXT 24 0.68 0.00031833 40.2 +BTC_POWR 35 0.98 0.00064887 45.3 +BTC_ADA 43 -0.39 -0.00032292 55.0 +BTC_XMR 40 -0.40 -0.00032181 47.4 +TOTAL 419 -0.41 -0.00348593 52.9 +``` + +The last line will give you the overall performance of your strategy, +here: +``` +TOTAL 419 -0.41 -0.00348593 52.9 +``` + +We understand the bot has made `419` trades for an average duration of +`52.9` min, with a performance of `-0.41%` (loss), that means it has +lost a total of `-0.00348593 BTC`. + +As you will see your strategy performance will be influenced by your buy +strategy, your sell strategy, and also by the `minimal_roi` and +`stop_loss` you have set. + +As for an example if your minimal_roi is only `"0": 0.01`. You cannot +expect the bot to make more profit than 1% (because it will sell every +time a trade will reach 1%). +```json +"minimal_roi": { + "0": 0.01 +}, +``` + +On the other hand, if you set a too high `minimal_roi` like `"0": 0.55` +(55%), there is a lot of chance that the bot will never reach this +profit. Hence, keep in mind that your performance is a mix of your +strategies, your configuration, and the crypto-currency you have set up. + +## Next step +Great, your strategy is profitable. What if the bot can give your the +optimal parameters to use for your strategy? +Your next step is to learn [how to find optimal parameters with Hyperopt](https://github.com/gcarq/freqtrade/blob/develop/docs/hyperopt.md) \ No newline at end of file diff --git a/docs/bot-optimization.md b/docs/bot-optimization.md new file mode 100644 index 000000000..a49ffdc26 --- /dev/null +++ b/docs/bot-optimization.md @@ -0,0 +1,117 @@ +# Bot Optimization +This page explains where to customize your strategies, and add new +indicators. + +## Table of Contents +- [Change your strategy](#change-your-strategy) +- [Add more Indicator](#add-more-indicator) + +## Change your strategy +The bot is using buy and sell strategies to buy and sell your trades. +Both are customizable. + +### Buy strategy +The default buy strategy is located in the file +[freqtrade/analyze.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/analyze.py#L73-L92). +Edit the function `populate_buy_trend()` to update your buy strategy. + +Sample: +```python +def populate_buy_trend(dataframe: DataFrame) -> DataFrame: + """ + Based on TA indicators, populates the buy signal for the given dataframe + :param dataframe: DataFrame + :return: DataFrame with buy column + """ + dataframe.loc[ + ( + (dataframe['rsi'] < 35) & + (dataframe['fastd'] < 35) & + (dataframe['adx'] > 30) & + (dataframe['plus_di'] > 0.5) + ) | + ( + (dataframe['adx'] > 65) & + (dataframe['plus_di'] > 0.5) + ), + 'buy'] = 1 + + return dataframe +``` + +### Sell strategy +The default buy strategy is located in the file +[freqtrade/analyze.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/analyze.py#L95-L115) +Edit the function `populate_sell_trend()` to update your buy strategy. + +Sample: +```python +def populate_sell_trend(dataframe: DataFrame) -> DataFrame: + """ + Based on TA indicators, populates the sell signal for the given dataframe + :param dataframe: DataFrame + :return: DataFrame with buy column + """ + dataframe.loc[ + ( + ( + (crossed_above(dataframe['rsi'], 70)) | + (crossed_above(dataframe['fastd'], 70)) + ) & + (dataframe['adx'] > 10) & + (dataframe['minus_di'] > 0) + ) | + ( + (dataframe['adx'] > 70) & + (dataframe['minus_di'] > 0.5) + ), + 'sell'] = 1 + return dataframe +``` + +## Add more Indicator +As you have seen, buy and sell strategies need indicators. You can see +the indicators in the file +[freqtrade/analyze.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/analyze.py#L95-L115). +Of course you can add more indicators by extending the list contained in +the function `populate_indicators()`. + +Sample: +```python +def populate_indicators(dataframe: DataFrame) -> DataFrame: + """ + Adds several different TA indicators to the given DataFrame + """ + dataframe['sar'] = ta.SAR(dataframe) + dataframe['adx'] = ta.ADX(dataframe) + stoch = ta.STOCHF(dataframe) + dataframe['fastd'] = stoch['fastd'] + dataframe['fastk'] = stoch['fastk'] + dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband'] + dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) + dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) + dataframe['mfi'] = ta.MFI(dataframe) + dataframe['rsi'] = ta.RSI(dataframe) + dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) + dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) + dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) + dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) + dataframe['ao'] = awesome_oscillator(dataframe) + macd = ta.MACD(dataframe) + dataframe['macd'] = macd['macd'] + dataframe['macdsignal'] = macd['macdsignal'] + dataframe['macdhist'] = macd['macdhist'] + hilbert = ta.HT_SINE(dataframe) + dataframe['htsine'] = hilbert['sine'] + dataframe['htleadsine'] = hilbert['leadsine'] + dataframe['plus_dm'] = ta.PLUS_DM(dataframe) + dataframe['plus_di'] = ta.PLUS_DI(dataframe) + dataframe['minus_dm'] = ta.MINUS_DM(dataframe) + dataframe['minus_di'] = ta.MINUS_DI(dataframe) + return dataframe +``` + + +## Next step +Now you have a perfect strategy you probably want to backtesting it. +Your next step is to learn [How to use ](https://github.com/gcarq/freqtrade/blob/develop/docs/backtesting.md). diff --git a/docs/bot-usage.md b/docs/bot-usage.md new file mode 100644 index 000000000..79044691e --- /dev/null +++ b/docs/bot-usage.md @@ -0,0 +1,136 @@ +# Bot usage +This page explains the difference parameters of the bot and how to run +it. + +## Table of Contents +- [Bot commands](#bot-commands) +- [Backtesting commands](#backtesting-commands) +- [Hyperopt commands](#hyperopt-commands) + +## Bot commands +``` +usage: main.py [-h] [-c PATH] [-v] [--version] [--dynamic-whitelist [INT]] + [--dry-run-db] + {backtesting,hyperopt} ... + +Simple High Frequency Trading Bot for crypto currencies + +positional arguments: + {backtesting,hyperopt} + backtesting backtesting module + hyperopt hyperopt module + +optional arguments: + -h, --help show this help message and exit + -c PATH, --config PATH + specify configuration file (default: config.json) + -v, --verbose be verbose + --version show program's version number and exit + --dynamic-whitelist [INT] + dynamically generate and update whitelist based on 24h + BaseVolume (Default 20 currencies) + --dry-run-db Force dry run to use a local DB + "tradesv3.dry_run.sqlite" instead of memory DB. Work + only if dry_run is enabled. +``` + +### How to use a different config file? +The bot allows you to select which config file you want to use. Per +default, the bot will load the file `./config.json` + +```bash +python3 ./freqtrade/main.py -c path/far/far/away/config.json +``` + +### How to use --dynamic-whitelist? +Per default `--dynamic-whitelist` will retrieve the 20 currencies based +on BaseVolume. This value can be changed when you run the script. + +**By Default** +Get the 20 currencies based on BaseVolume. +```bash +python3 ./freqtrade/main.py --dynamic-whitelist +``` + +**Customize the number of currencies to retrieve** +Get the 30 currencies based on BaseVolume. +```bash +python3 ./freqtrade/main.py --dynamic-whitelist 30 +``` + +**Exception** +`--dynamic-whitelist` must be greater than 0. If you enter 0 or a +negative value (e.g -2), `--dynamic-whitelist` will use the default +value (20). + +### How to use --dry-run-db? +When you run the bot in Dry-run mode, per default no transactions are +stored in a database. If you want to store your bot actions in a DB +using `--dry-run-db`. This command will use a separate database file +`tradesv3.dry_run.sqlite` + +```bash +python3 ./freqtrade/main.py -c config.json --dry-run-db +``` + + +## Backtesting commands + +Backtesting also uses the config specified via `-c/--config`. + +``` +usage: freqtrade backtesting [-h] [-l] [-i INT] [--realistic-simulation] + [-r] + +optional arguments: + -h, --help show this help message and exit + -l, --live using live data + -i INT, --ticker-interval INT + specify ticker interval in minutes (default: 5) + --realistic-simulation + uses max_open_trades from config to simulate real + world limitations + -r, --refresh-pairs-cached + refresh the pairs files in tests/testdata with + the latest data from Bittrex. Use it if you want + to run your backtesting with up-to-date data. +``` + +### How to use --refresh-pairs-cached parameter? +The first time your run Backtesting, it will take the pairs you have +set in your config file and download data from Bittrex. + +If for any reason you want to update your data set, you use +`--refresh-pairs-cached` to force Backtesting to update the data it has. +**Use it only if you want to update your data set. You will not be able +to come back to the previous version.** + +To test your strategy with latest data, we recommend continuing using +the parameter `-l` or `--live`. + + +## Hyperopt commands + +It is possible to use hyperopt for trading strategy optimization. +Hyperopt uses an internal json config return by `hyperopt_optimize_conf()` +located in `freqtrade/optimize/hyperopt_conf.py`. + +``` +usage: freqtrade hyperopt [-h] [-e INT] [--use-mongodb] + +optional arguments: + -h, --help show this help message and exit + -e INT, --epochs INT specify number of epochs (default: 100) + --use-mongodb parallelize evaluations with mongodb (requires mongod + in PATH) + +``` + +## A parameter missing in the configuration? +All parameters for `main.py`, `backtesting`, `hyperopt` are referenced +in [misc.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/misc.py#L84) + +## Next step +The optimal strategy of the bot will change with time depending of the +market trends. The next step is to +[optimize your bot](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-optimization.md). \ No newline at end of file diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 000000000..bfd169aea --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,127 @@ +# Configure the bot +This page explains how to configure your `config.json` file. + +## Table of Contents +- [Bot commands](#bot-commands) +- [Backtesting commands](#backtesting-commands) +- [Hyperopt commands](#hyperopt-commands) + +## Setup config.json +We recommend to copy and use the `config.json.example` as a template +for your bot configuration. + +The table below will list all configuration parameters. + +| Command | Default | Mandatory | Description | +|----------|---------|----------|-------------| +| `max_open_trades` | 3 | Yes | Number of trades open your bot will have. +| `stake_currency` | BTC | Yes | Crypto-currency used for trading. +| `stake_amount` | 0.05 | Yes | Amount of crypto-currency your bot will use for each trade. Per default, the bot will use (0.05 BTC x 3) = 0.15 BTC in total will be always engaged. +| `fiat_display_currency` | USD | Yes | Fiat currency used to show your profits. More information below. +| `dry_run` | true | Yes | Define if the bot must be in Dry-run or production mode. +| `minimal_roi` | See below | Yes | Set the threshold in percent the bot will use to sell a trade. More information below. +| `stoploss` | -0.10 | No | Value of the stoploss in percent used by the bot. More information below. +| `bid_strategy.ask_last_balance` | 0.0 | Yes | Set the bidding price. More information below. +| `exchange.name` | bittrex | Yes | Name of the exchange class to use. +| `exchange.key` | key | No | API key to use for the exchange. Only required when you are in production mode. +| `exchange.secret` | secret | No | API secret to use for the exchange. Only required when you are in production mode. +| `exchange.pair_whitelist` | [] | No | List of currency to use by the bot. Can be overrided with `--dynamic-whitelist` param. +| `exchange.pair_blacklist` | [] | No | List of currency the bot must avoid. Useful when using `--dynamic-whitelist` param. +| `experimental.use_sell_signal` | false | No | Use your sell strategy in addition of the `minimal_roi`. +| `telegram.enabled` | true | Yes | Enable or not the usage of Telegram. +| `telegram.token` | token | No | Your Telegram bot token. Only required is `enable` is `true`. +| `telegram.chat_id` | chat_id | No | Your personal Telegram account id. Only required is `enable` is `true`. +| `initial_state` | running | No | Defines the initial application state. More information below. +| `internals.process_throttle_secs` | 5 | Yes | Set the process throttle. Value in second. + +The definition of each config parameters is in +[misc.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/misc.py#L205). + +### Understand minimal_roi +`minimal_roi` is a JSON object where the key is a duration +in minutes and the value is the minimum ROI in percent. +See the example below: +``` +"minimal_roi": { + "40": 0.0, # Sell after 40 minutes if the profit is not negative + "30": 0.01, # Sell after 30 minutes if there is at least 1% profit + "20": 0.02, # Sell after 20 minutes if there is at least 2% profit + "0": 0.04 # Sell immediately if there is at least 4% profit +}, +``` + +### Understand stoploss +`stoploss` is loss in percentage that should trigger a sale. +For example value `-0.10` will cause immediate sell if the +profit dips below -10% for a given trade. This parameter is optional. + +### Understand initial_state +`initial_state` is an optional field that defines the initial application state. +Possible values are `running` or `stopped`. (default=`running`) +If the value is `stopped` the bot has to be started with `/start` first. + +### Understand ask_last_balance +`ask_last_balance` sets the bidding price. Value `0.0` will use `ask` price, `1.0` will +use the `last` price and values between those interpolate between ask and last +price. Using `ask` price will guarantee quick success in bid, but bot will also +end up paying more then would probably have been necessary. + +### What values for fiat_display_currency? +`fiat_display_currency` set the fiat to use for the conversion form coin to fiat in Telegram. +The valid value are: "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD". + +## Switch to dry-run mode +We recommend starting the bot in dry-run mode to see how your bot will +behave and how is the performance of your strategy. In Dry-run mode the +bot does not engage your money. It only runs a live simulation without +creating trades. + +### To switch your bot in Dry-run mode: +1. Edit your `config.json` file +2. Switch dry-run to true +```json +"dry_run": true, +``` + +3. Remove your Bittrex API key (change them by fake api credentials) +```json +"exchange": { + "name": "bittrex", + "key": "key", + "secret": "secret", + ... +} +``` + +Once you will be happy with your bot performance, you can switch it to +production mode. + +## Switch to production mode +In production mode, the bot will engage your money. Be careful a wrong +strategy can lose all your money. Be aware of what you are doing when +you run it in production mode. + +### To switch your bot in production mode: +1. Edit your `config.json` file + +2. Switch dry-run to false +```json +"dry_run": false, +``` + +3. Insert your Bittrex API key (change them by fake api keys) +```json +"exchange": { + "name": "bittrex", + "key": "af8ddd35195e9dc500b9a6f799f6f5c93d89193b", + "secret": "08a9dc6db3d7b53e1acebd9275677f4b0a04f1a5", + ... +} +``` +If you have not your Bittrex API key yet, +[see our tutorial](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md). + + +## Next step +Now you have configured your config.json, the next step is to +[start your bot](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md). diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 000000000..58929e15c --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,21 @@ +# freqtrade FAQ + +#### I have waited 5 minutes, why hasn't the bot made any trades yet?! + +Depending on the buy strategy, the amount of whitelisted coins, the situation of the market etc, it can take up to hours to find good entry position for a trade. Be patient! + +#### I have made 12 trades already, why is my total profit negative?! + +I understand your disappointment but unfortunately 12 trades is just not enough to say anything. If you run backtesting, you can see that our current algorithm does leave you on the plus side, but that is after thousands of trades and even there, you will be left with losses on specific coins that you have traded tens if not hundreds of times. We of course constantly aim to improve the bot but it will _always_ be a gamble, which should leave you with modest wins on monthly basis but you can't say much from few trades. + +#### I’d like to change the stake amount. Can I just stop the bot with /stop and then change the config.json and run it again? + +Not quite. Trades are persisted to a database but the configuration is currently only read when the bot is killed and restarted. `/stop` more like pauses. You can stop your bot, adjust settings and start it again. + +#### I want to improve the bot with a new strategy + +That's great. We have a nice backtesting and hyperoptimizing setup. See the tutorial [[here|Testing-new-strategies-with-Hyperopt]]. + +#### Is there a setting to only SELL the coins being held and not perform anymore BUYS? + +You can use the `/forcesell all` command from Telegram. \ No newline at end of file diff --git a/docs/hyperopt.md b/docs/hyperopt.md new file mode 100644 index 000000000..212a3f56c --- /dev/null +++ b/docs/hyperopt.md @@ -0,0 +1,269 @@ +# Hyperopt +This page explains how to tune your strategy by finding the optimal +parameters with Hyperopt. + +## Table of Contents +- [Prepare your Hyperopt](#prepare-hyperopt) + - [1. Configure your Guards and Triggers](#1-configure-your-guards-and-triggers) + - [2. Update the hyperopt config file](#2-update-the-hyperopt-config-file) +- [Advanced Hyperopt notions](#advanced-notions) + - [Understand the Guards and Triggers](#understand-the-guards-and-triggers) +- [Execute Hyperopt](#execute-hyperopt) + - [Hyperopt with MongoDB](#hyperopt-with-mongoDB) +- [Understand the hyperopts result](#understand-the-backtesting-result) + +## Prepare Hyperopt +Before we start digging in Hyperopt, we recommend you to take a look at +out Hyperopt file +[freqtrade/optimize/hyperopt.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py) + +### 1. Configure your Guards and Triggers +There are two places you need to change to add a new buy strategy for +testing: +- Inside the [populate_buy_trend()](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py#L167-L207). +- Inside the [SPACE dict](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py#L47-L94). + +There you have two different type of indicators: 1. `guards` and 2. +`triggers`. +1. Guards are conditions like "never buy if ADX < 10", or never buy if +current price is over EMA10. +2. Triggers are ones that actually trigger buy in specific moment, like +"buy when EMA5 crosses over EMA10" or buy when close price touches lower +bollinger band. + +HyperOpt will, for each eval round, pick just ONE trigger, and possibly +multiple guards. So that the constructed strategy will be something like +"*buy exactly when close price touches lower bollinger band, BUT only if +ADX > 10*". + + +If you have updated the buy strategy, means change the content of +`populate_buy_trend()` function you have to update the `guards` and +`triggers` hyperopts must used. + +As for an example if your `populate_buy_trend()` function is: +```python +def populate_buy_trend(dataframe: DataFrame) -> DataFrame: + dataframe.loc[ + (dataframe['rsi'] < 35) & + (dataframe['adx'] > 65), + 'buy'] = 1 + + return dataframe +``` + +Your hyperopt file must contains `guards` to find the right value for +`(dataframe['adx'] > 65)` & and `(dataframe['plus_di'] > 0.5)`. That +means you will need to enable/disable triggers. + +In our case the `SPACE` and `populate_buy_trend` in hyperopt.py file +will be look like: +```python +SPACE = { + 'rsi': hp.choice('rsi', [ + {'enabled': False}, + {'enabled': True, 'value': hp.quniform('rsi-value', 20, 40, 1)} + ]), + 'adx': hp.choice('adx', [ + {'enabled': False}, + {'enabled': True, 'value': hp.quniform('adx-value', 15, 50, 1)} + ]), + 'trigger': hp.choice('trigger', [ + {'type': 'lower_bb'}, + {'type': 'faststoch10'}, + {'type': 'ao_cross_zero'}, + {'type': 'ema5_cross_ema10'}, + {'type': 'macd_cross_signal'}, + {'type': 'sar_reversal'}, + {'type': 'stochf_cross'}, + {'type': 'ht_sine'}, + ]), +} + +... + +def populate_buy_trend(dataframe: DataFrame) -> DataFrame: + conditions = [] + # GUARDS AND TRENDS + if params['adx']['enabled']: + conditions.append(dataframe['adx'] > params['adx']['value']) + if params['rsi']['enabled']: + conditions.append(dataframe['rsi'] < params['rsi']['value']) + + # TRIGGERS + triggers = { + 'lower_bb': dataframe['tema'] <= dataframe['blower'], + 'faststoch10': (crossed_above(dataframe['fastd'], 10.0)), + 'ao_cross_zero': (crossed_above(dataframe['ao'], 0.0)), + 'ema5_cross_ema10': (crossed_above(dataframe['ema5'], dataframe['ema10'])), + 'macd_cross_signal': (crossed_above(dataframe['macd'], dataframe['macdsignal'])), + 'sar_reversal': (crossed_above(dataframe['close'], dataframe['sar'])), + 'stochf_cross': (crossed_above(dataframe['fastk'], dataframe['fastd'])), + 'ht_sine': (crossed_above(dataframe['htleadsine'], dataframe['htsine'])), + } + ... +``` + + +### 2. Update the hyperopt config file +Hyperopt is using a dedicated config file. At this moment hyperopt +cannot use your config file. It is also made on purpose to allow you +testing your strategy with different configurations. + +The Hyperopt configuration is located in +[freqtrade/optimize/hyperopt_conf.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt_conf.py). + + +## Advanced notions +### Understand the Guards and Triggers +When you need to add the new guards and triggers to be hyperopt +parameters, you do this by adding them into the [SPACE dict](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py#L47-L94). + +If it's a trigger, you add one line to the 'trigger' choice group and that's it. + +If it's a guard, you will add a line like this: +``` +'rsi': hp.choice('rsi', [ + {'enabled': False}, + {'enabled': True, 'value': hp.quniform('rsi-value', 20, 40, 1)} +]), +``` +This says, "*one of guards is RSI, it can have two values, enabled or +disabled. If it is enabled, try different values for it between 20 and 40*". + +So, the part of the strategy builder using the above setting looks like +this: +``` +if params['rsi']['enabled']: + conditions.append(dataframe['rsi'] < params['rsi']['value']) +``` +It checks if Hyperopt wants the RSI guard to be enabled for this +round `params['rsi']['enabled']` and if it is, then it will add a +condition that says RSI must be < than the value hyperopt picked +for this evaluation, that is given in the `params['rsi']['value']`. + +That's it. Now you can add new parts of strategies to Hyperopt and it +will try all the combinations with all different values in the search +for best working algo. + + +### Add a new Indicators +If you want to test an indicator that isn't used by the bot currently, +you need to add it to +[freqtrade/analyze.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/analyze.py#L40-L70) +inside the `populate_indicators` function. + +## Execute Hyperopt +Once you have updated your hyperopt configuration you can run it. +Because hyperopt tries a lot of combination to find the best parameters +it will take time you will have the result (more than 30 mins). + +We strongly recommend to use `screen` to prevent any connection loss. +```bash +python3 ./freqtrade/main.py -c config.json hyperopt +``` + +### Hyperopt with MongoDB +Hyperopt with MongoDB, is like Hyperopt under steroids. As you saw by +executing the previous command is the execution takes a long time. +To accelerate it you can use hyperopt with MongoDB. + +To run hyperopt with MongoDb you will need 3 terminals. + +**Terminal 1: Start MongoDB** +```bash +cd +source .env/bin/activate +python3 scripts/start-mongodb.py +``` + +**Terminal 2: Start Hyperopt worker** +```bash +cd +source .env/bin/activate +python3 scripts/start-hyperopt-worker.py +``` + +**Terminal 3: Start Hyperopt with MongoDB** +```bash +cd +source .env/bin/activate +python3 ./freqtrade/main.py -c config.json hyperopt --use-mongodb +``` + +**Re-run an Hyperopt** +To re-run Hyperopt you have to delete the existing MongoDB table. +```bash +cd +rm -rf .hyperopt/mongodb/ +``` + +## Understand the hyperopts result +Once Hyperopt is completed you can use the result to adding new buy +signal. Given following result from hyperopt: +``` +Best parameters: +{ + "adx": 1, + "adx-value": 15.0, + "fastd": 1, + "fastd-value": 40.0, + "green_candle": 1, + "mfi": 0, + "over_sar": 0, + "rsi": 1, + "rsi-value": 37.0, + "trigger": 0, + "uptrend_long_ema": 1, + "uptrend_short_ema": 0, + "uptrend_sma": 0 +} + +Best Result: + 2197 trades. Avg profit 1.84%. Total profit 0.79367541 BTC. Avg duration 241.0 mins. +``` + +You should understand this result like: +- You should **consider** the guard "adx" (`"adx": 1,` = `adx` is true) +and the best value is `15.0` (`"adx-value": 15.0,`) +- You should **consider** the guard "fastd" (`"fastd": 1,` = `fastd` +is true) and the best value is `40.0` (`"fastd-value": 40.0,`) +- You should **consider** to enable the guard "green_candle" +(`"green_candle": 1,` = `candle` is true) but this guards as no +customizable value. +- You should **ignore** the guard "mfi" (`"mfi": 0,` = `mfi` is false) +- and so on... + + +You have to look from +[freqtrade/optimize/hyperopt.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py#L170-L200) +what those values match to. + +So for example you had `adx-value: 15.0` (and `adx: 1` was true) so we +would look at `adx`-block from +[freqtrade/optimize/hyperopt.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/optimize/hyperopt.py#L178-L179). +That translates to the following code block to +[analyze.populate_buy_trend()](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/analyze.py#L73) +``` +(dataframe['adx'] > 15.0) +``` + +So translating your whole hyperopt result to as the new buy-signal +would be the following: +``` +def populate_buy_trend(dataframe: DataFrame) -> DataFrame: + dataframe.loc[ + ( + (dataframe['adx'] > 15.0) & # adx-value + (dataframe['fastd'] < 40.0) & # fastd-value + (dataframe['close'] > dataframe['open']) & # green_candle + (dataframe['rsi'] < 37.0) & # rsi-value + (dataframe['ema50'] > dataframe['ema100']) # uptrend_long_ema + ), + 'buy'] = 1 + return dataframe +``` + +## Next step +Now you have a perfect bot and want to control it from Telegram. Your +next step is to learn the [Telegram usage](https://github.com/gcarq/freqtrade/blob/develop/docs/telegram-usage.md). diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 000000000..ed940d132 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,32 @@ +# freqtrade documentation +Welcome to freqtrade documentation. Please feel free to contribute to +this documentation if you see it became outdated by sending us a +Pull-request. Do not hesitate to reach us on +[Slack](https://join.slack.com/t/highfrequencybot/shared_invite/enQtMjQ5NTM0OTYzMzY3LWMxYzE3M2MxNDdjMGM3ZTYwNzFjMGIwZGRjNTc3ZGU3MGE3NzdmZGMwNmU3NDM5ZTNmM2Y3NjRiNzk4NmM4OGE) + if you do not find the answer to your questions. + +## Table of Contents +- [Pre-requisite](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md) + - [Setup your Bittrex account](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md#setup-your-bittrex-account) + - [Setup your Telegram bot](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md#setup-your-telegram-bot) +- [Bot Installation](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md) + - [Install with Docker (all platforms)](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md#docker) + - [Install on Linux Ubuntu](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md#21-linux---ubuntu-1604) + - [Install on MacOS](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md#23-macos-installation) + - [Install on Windows](https://github.com/gcarq/freqtrade/blob/develop/docs/installation.md#windows) +- [Bot Configuration](https://github.com/gcarq/freqtrade/blob/develop/docs/configuration.md) +- [Bot usage (Start your bot)](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md) + - [Bot commands](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#bot-commands) + - [Backtesting commands](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#backtesting-commands) + - [Hyperopt commands](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-usage.md#hyperopt-commands) +- [Bot Optimization](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-optimization.md) + - [Change your strategy](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-optimization.md#change-your-strategy) + - [Add more Indicator](https://github.com/gcarq/freqtrade/blob/develop/docs/bot-optimization.md#add-more-indicator) + - [Test your strategy with Backtesting](https://github.com/gcarq/freqtrade/blob/develop/docs/backtesting.md) + - [Find optimal parameters with Hyperopt](https://github.com/gcarq/freqtrade/blob/develop/docs/hyperopt.md) +- [Control the bot with telegram](https://github.com/gcarq/freqtrade/blob/develop/docs/telegram-usage.md) +- [Contribute to the project](https://github.com/gcarq/freqtrade/blob/develop/CONTRIBUTING.md) + - [How to contribute](https://github.com/gcarq/freqtrade/blob/develop/CONTRIBUTING.md) + - [Run tests & Check PEP8 compliance](https://github.com/gcarq/freqtrade/blob/develop/CONTRIBUTING.md) +- [FAQ](https://github.com/gcarq/freqtrade/blob/develop/docs/faq.md) + - [SQL cheatsheet](https://github.com/gcarq/freqtrade/blob/develop/docs/sql_cheatsheet.md) \ No newline at end of file diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 000000000..9ea6265ba --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,246 @@ +# Install the bot +This page explains how to prepare your environment for running the bot. +To understand how to set up the bot please read the Bot +[Bot configuration](https://github.com/gcarq/freqtrade/blob/develop/docs/configuration.md) +page. + +## Table of Contents +- [Docker Automatic Installation](#docker) +- [Linux or Mac manual Installation](#linux--mac) + - [Linux - Ubuntu 16.04](#21-linux---ubuntu-1604) + - [Linux - Other distro](#22-linux---other-distro) + - [MacOS installation](#23-macos-installation) + - [Advanced Linux ](#advanced-linux) +- [Windows manual Installation](#windows) + +# Docker + +## Easy installation +Start by downloading Docker for your platform: +- [Mac](https://www.docker.com/products/docker#/mac) +- [Windows](https://www.docker.com/products/docker#/windows) +- [Linux](https://www.docker.com/products/docker#/linux) + +Once you have Docker installed, simply create the config file +(e.g. `config.json`) and then create a Docker image for `freqtrade` +using the Dockerfile in this repo. + +### 1. Prepare the bot +1. Clone the git +```bash +git clone git@github.com:gcarq/freqtrade.git +``` +2. (Optional) Checkout the develop branch +```bash +git checkout develop +``` +3. Go into the new directory +```bash +cd freqtrade +``` +4. Copy `config.sample` to `config.json` +```bash +cp config.json.example config.json +``` +To edit the config please refer to the [Bot Configuration](https://github.com/gcarq/freqtrade/blob/develop/docs/configuration.md) page +5. Create your DB file (Optional, the bot will create it if it is missing) +```bash +# For Production +touch tradesv3.sqlite + +# For Dry-run +touch tradesv3.dryrun.sqlite +``` + +### 2. Build the docker image +```bash +cd freqtrade +docker build -t freqtrade . +``` + +For security reasons, your configuration file will not be included in the +image, you will need to bind mount it. It is also advised to bind mount +a sqlite database file (see the "5. Run a restartable docker image" +section) to keep it between updates. + +### 3. Verify the docker image +After build process you can verify that the image was created with: +``` +docker images +``` + +### 4. Run the docker image +You can run a one-off container that is immediately deleted upon exiting with +the following command (config.json must be in the current working directory): + +``` +docker run --rm -v `pwd`/config.json:/freqtrade/config.json -it freqtrade +``` + +In this example, the database will be created inside the docker instance +and will be lost when you will refresh your image. + +### 5. Run a restartable docker image +To run a restartable instance in the background (feel free to place your +configuration and database files wherever it feels comfortable on your +filesystem). + +**5.1. Move your config file and database** +```bash +mkdir ~/.freqtrade +mv config.json ~/.freqtrade +mv tradesv3.sqlite ~/.freqtrade +``` + +**5.2. Run the docker image** +```bash +docker run -d \ + --name freqtrade \ + -v ~/.freqtrade/config.json:/freqtrade/config.json \ + -v ~/.freqtrade/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \ + freqtrade +``` +If you are using `dry_run=True` it's not necessary to mount +`tradesv3.sqlite`, but you can mount `tradesv3.dryrun.sqlite` if you +plan to use the dry run mode with the param `--dry-run-db`. + + +### 6. Monitor your Docker instance +You can then use the following commands to monitor and manage your container: + +```bash +docker logs freqtrade +docker logs -f freqtrade +docker restart freqtrade +docker stop freqtrade +docker start freqtrade +``` + +You do not need to rebuild the image for configuration changes, it will +suffice to edit `config.json` and restart the container. + + +# Linux / MacOS +## 1. Requirements +Click each one for install guide: +- [Python 3.6.x](http://docs.python-guide.org/en/latest/starting/installation/), +note the bot was not tested on Python >= 3.7.x +- [pip](https://pip.pypa.io/en/stable/installing/) +- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +- [virtualenv](https://virtualenv.pypa.io/en/stable/installation/) (Recommended) +- [TA-Lib](https://mrjbq7.github.io/ta-lib/install.html) + +## 2. First install required packages +This bot require Python 3.6 and TA-LIB + +### 2.1 Linux - Ubuntu 16.04 + +**2.1.1. Install Python 3.6, Git, and wget** +```bash +sudo add-apt-repository ppa:jonathonf/python-3.6 +sudo apt-get update +sudo apt-get install python3.6 python3.6-venv build-essential autoconf libtool pkg-config make wget git +``` + +**2.1.2. Install TA-LIB** +Official webpage: https://mrjbq7.github.io/ta-lib/install.html +``` +wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz +tar xvzf ta-lib-0.4.0-src.tar.gz +cd ta-lib +./configure --prefix=/usr +make +make install +cd .. +rm -rf ./ta-lib* +``` + +**2.1.3. [Optional] Install MongoDB** +Install MongoDB if you plan to optimize your strategy with Hyperopt. + +```bash +sudo apt-get install mongodb-org +``` +Complete tutorial on [Digital Ocean: How to Install MongoDB on Ubuntu 16.04](https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04) + +### 2.2. Linux - Other distro +If you are on a different Linux OS you maybe have to adapt things like: + +- package manager (for example yum instead of apt-get) +- package names + +### 2.3. MacOS installation + +**2.3.1. Install Python 3.6, git and wget** +```bash +brew install python3 git wget +``` + +**2.3.2. [Optional] Install MongoDB** +Install MongoDB if you plan to optimize your strategy with Hyperopt. +```bash +curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.4.10.tgz +tar -zxvf mongodb-osx-ssl-x86_64-3.4.10.tgz +mkdir -p /env/mongodb +cp -R -n mongodb-osx-x86_64-3.4.10/ /env/mongodb +export PATH=/env/mongodb/bin:$PATH +``` + +## 3. Clone the repo +The following steps are made for Linux/mac environment +1. Clone the git `git clone git@github.com:gcarq/freqtrade.git` +2. (Optional) Checkout the develop branch `git checkout develop` + +## 4. Prepare the bot +```bash +cd freqtrade +cp config.json.example config.json +``` +To edit the config please refer to [Bot Configuration](https://github.com/gcarq/freqtrade/blob/develop/docs/configuration.md) + +## 5. Setup your virtual env +```bash +python3.6 -m venv .env +source .env/bin/activate +pip3.6 install -r requirements.txt +pip3.6 install -e . +``` + +## 6. Run the bot +If this is the first time you run the bot, ensure you are running it +in Dry-run `"dry_run": true,` otherwise it will start to buy and sell coins. + +```bash +python3.6 ./freqtrade/main.py -c config.json +``` + +### Advanced Linux +**systemd service file** +Copy `./freqtrade.service` to your systemd user directory (usually `~/.config/systemd/user`) +and update `WorkingDirectory` and `ExecStart` to match your setup. +After that you can start the daemon with: +```bash +systemctl --user start freqtrade +``` + +# Windows +We do recommend Windows users to use [Docker](#docker) this will work +much easier and smoother (also safer). + +```cmd +#copy paste config.json to \path\freqtrade-develop\freqtrade +>cd \path\freqtrade-develop +>python -m venv .env +>cd .env\Scripts +>activate.bat +>cd \path\freqtrade-develop +>pip install -r requirements.txt +>pip install -e . +>cd freqtrade +>python main.py +``` +*Thanks [Owdr](https://github.com/Owdr) for the commands. Source: [Issue #222](https://github.com/gcarq/freqtrade/issues/222)* + +## Next step +Now you have an environment ready, the next step is to +[configure your bot](https://github.com/gcarq/freqtrade/blob/develop/docs/configuration.md). diff --git a/docs/pre-requisite.md b/docs/pre-requisite.md new file mode 100644 index 000000000..1bdad4ece --- /dev/null +++ b/docs/pre-requisite.md @@ -0,0 +1,46 @@ +# Pre-requisite +Before running your bot in production you will need to setup few +external API. In production mode, the bot required valid Bittrex API +credentials and a Telegram bot (optional but recommended). + +## Table of Contents +- [Setup your Bittrex account](#setup-your-bittrex-account) +- [Backtesting commands](#setup-your-telegram-bot) + +## Setup your Bittrex account +*To be completed, please feel free to complete this section.* + +## Setup your Telegram bot +The only things you need is a working Telegram bot and its API token. +Below we explain how to create your Telegram Bot, and how to get your +Telegram user id. + +### 1. Create your instagram bot +**1.1. Start a chat with https://telegram.me/BotFather** +**1.2. Send the message** `/newbot` +*BotFather response:* +``` +Alright, a new bot. How are we going to call it? Please choose a name for your bot. +``` +**1.3. Choose the public name of your bot (e.g "`Freqtrade bot`")** +*BotFather response:* +``` +Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot. +``` +**1.4. Choose the name id of your bot (e.g "`My_own_freqtrade_bot`")** +**1.5. Father bot will return you the token (API key)** +Copy it and keep it you will use it for the config parameter `token`. +*BotFather response:* +``` +Done! Congratulations on your new bot. You will find it at t.me/My_own_freqtrade_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. + +Use this token to access the HTTP API: +521095879:AAEcEZEL7ADJ56FtG_qD0bQJSKETbXCBCi0 + +For a description of the Bot API, see this page: https://core.telegram.org/bots/api +``` + +### 2. Get your user id +**2.1. Talk to https://telegram.me/userinfobot** +**2.2. Get your "Id", you will use it for the config parameter +`chat_id`.** \ No newline at end of file diff --git a/docs/sql_cheatsheet.md b/docs/sql_cheatsheet.md new file mode 100644 index 000000000..1edbcde5b --- /dev/null +++ b/docs/sql_cheatsheet.md @@ -0,0 +1,78 @@ +# SQL Helper +This page constains some help if you want to edit your sqlite db. + +## Install sqlite3 +**Ubuntu/Debian installation** +```bash +sudo apt-get install sqlite3 +``` + +## Open the DB +```bash +sqlite3 +.open +``` + +## Table structure + +### List tables +```bash +.tables +``` + +### Display table structure +```bash +.schema +``` + +### Trade table structure +```sql +CREATE TABLE trades ( + id INTEGER NOT NULL, + exchange VARCHAR NOT NULL, + pair VARCHAR NOT NULL, + is_open BOOLEAN NOT NULL, + fee FLOAT NOT NULL, + open_rate FLOAT, + close_rate FLOAT, + close_profit FLOAT, + stake_amount FLOAT NOT NULL, + amount FLOAT, + open_date DATETIME NOT NULL, + close_date DATETIME, + open_order_id VARCHAR, + PRIMARY KEY (id), + CHECK (is_open IN (0, 1)) +); +``` + +## Get all trades in the table + +```sql +SELECT * FROM trades; +``` + +## Fix trade still open after a /forcesell + +```sql +UPDATE trades +SET is_open=0, close_date=, close_rate=, close_profit=close_rate/open_rate +WHERE id=; +``` + +**Example:** +```sql +UPDATE trades +SET is_open=0, close_date='2017-12-20 03:08:45.103418', close_rate=0.19638016, close_profit=0.0496 +WHERE id=31; +``` + + +## Fix wrong fees in the table +If your DB was created before +[PR#200](https://github.com/gcarq/freqtrade/pull/200) was merged +(before 12/23/17). + +```sql +UPDATE trades SET fee=0.0025 WHERE fee=0.005; +``` \ No newline at end of file diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md new file mode 100644 index 000000000..904723b30 --- /dev/null +++ b/docs/telegram-usage.md @@ -0,0 +1,129 @@ +# Telegram usage + +This page explains how to command your bot with Telegram. + +## Pre-requisite +To control your bot with Telegram, you need first to +[set up a Telegram bot](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md) +and add your Telegram API keys into your config file. + +## Telegram commands +Per default, the Telegram bot shows predefined commands. Some commands +are only available by sending them to the bot. The table below list the +official commands. You can ask at any moment for help with `/help`. + +| Command | Default | Description | +|----------|---------|-------------| +| `/start` | | Starts the trader +| `/stop` | | Starts the trader +| `/status` | | Lists all open trades +| `/status table` | | List all open trades in a table format +| `/count` | | Displays number of trades used and available +| `/profit` | | Display a summary of your profit/loss from close trades and some stats about your performance +| `/forcesell ` | | Instantly sells the given trade (Ignoring `minimum_roi`). +| `/forcesell all` | | Instantly sells all open trades (Ignoring `minimum_roi`). +| `/performance` | | Show performance of each finished trade grouped by pair +| `/balance` | | Show account balance per currency +| `/daily ` | 7 | Shows profit or loss per day, over the last n days +| `/help` | | Show help message +| `/version` | | Show version + +## Telegram commands in action +Below, example of Telegram message you will receive for each command. + +### /start +> **Status:** `running` + +### /stop +> `Stopping trader ...` +> **Status:** `stopped` + +## /status +For each open trade, the bot will send you the following message. + +> **Trade ID:** `123` +> **Current Pair:** BTC_CVC +> **Open Since:** `1 days ago` +> **Amount:** `26.64180098` +> **Open Rate:** `0.00007489` +> **Close Rate:** `None` +> **Current Rate:** `0.00007489` +> **Close Profit:** `None` +> **Current Profit:** `12.95%` +> **Open Order:** `None` + +## /status table +Return the status of all open trades in a table format. +``` + ID Pair Since Profit +---- -------- ------- -------- + 67 BTC_SC 1 d 13.33% + 123 BTC_CVC 1 h 12.95% +``` + +## /count +Return the number of trades used and available. +``` +current max +--------- ----- + 2 10 +``` + +## /profit +Return a summary of your profit/loss and performance. + +> **ROI:** Close trades +> ∙ `0.00485701 BTC (258.45%)` +> ∙ `62.968 USD` +> **ROI:** All trades +> ∙ `0.00255280 BTC (143.43%)` +> ∙ `33.095 EUR` +> +> **Total Trade Count:** `138` +> **First Trade opened:** `3 days ago` +> **Latest Trade opened:** `2 minutes ago` +> **Avg. Duration:** `2:33:45` +> **Best Performing:** `BTC_PAY: 50.23%` + +## /forcesell + +> **BITTREX:** Selling BTC/LTC with limit `0.01650000 (profit: ~-4.07%, -0.00008168)` + +## /performance +Return the performance of each crypto-currency the bot has sold. +> Performance: +> 1. `BTC_RCN 57.77%` +> 2. `BTC_PAY 56.91%` +> 3. `BTC_VIB 47.07%` +> 4. `BTC_SALT 30.24%` +> 5. `BTC_STORJ 27.24%` +> ... + +## /balance +Return the balance of all crypto-currency your have on the exchange. + +> **Currency:** BTC +> **Available:** 3.05890234 +> **Balance:** 3.05890234 +> **Pending:** 0.0 + +> **Currency:** CVC +> **Available:** 86.64180098 +> **Balance:** 86.64180098 +> **Pending:** 0.0 + +## /daily +Per default `/daily` will return the 7 last days. +The example below if for `/daily 3`: + +> **Daily Profit over the last 3 days:** +``` +Day Profit BTC Profit USD +---------- -------------- ------------ +2018-01-03 0.00224175 BTC 29,142 USD +2018-01-02 0.00033131 BTC 4,307 USD +2018-01-01 0.00269130 BTC 34.986 USD +``` + +## /version +> **Version:** `0.14.3` \ No newline at end of file