Compare commits
No commits in common. "develop" and "2021.6" have entirely different histories.
@ -1,24 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "freqtrade Develop",
|
"name": "freqtrade Develop",
|
||||||
"build": {
|
|
||||||
"dockerfile": "Dockerfile",
|
|
||||||
"context": ".."
|
|
||||||
},
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
||||||
"forwardPorts": [
|
|
||||||
8080
|
|
||||||
],
|
|
||||||
"mounts": [
|
|
||||||
"source=freqtrade-bashhistory,target=/home/ftuser/commandhistory,type=volume"
|
|
||||||
],
|
|
||||||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/freqtrade,type=bind,consistency=cached",
|
|
||||||
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
|
|
||||||
"remoteUser": "ftuser",
|
|
||||||
|
|
||||||
"onCreateCommand": "pip install --user -e .",
|
"dockerComposeFile": [
|
||||||
"postCreateCommand": "freqtrade create-userdir --userdir user_data/",
|
"docker-compose.yml"
|
||||||
|
],
|
||||||
|
|
||||||
"workspaceFolder": "/workspaces/freqtrade",
|
"service": "ft_vscode",
|
||||||
|
|
||||||
|
"workspaceFolder": "/freqtrade/",
|
||||||
|
|
||||||
"settings": {
|
"settings": {
|
||||||
"terminal.integrated.shell.linux": "/bin/bash",
|
"terminal.integrated.shell.linux": "/bin/bash",
|
||||||
@ -36,6 +25,20 @@
|
|||||||
"ms-python.vscode-pylance",
|
"ms-python.vscode-pylance",
|
||||||
"davidanson.vscode-markdownlint",
|
"davidanson.vscode-markdownlint",
|
||||||
"ms-azuretools.vscode-docker",
|
"ms-azuretools.vscode-docker",
|
||||||
"vscode-icons-team.vscode-icons",
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [],
|
||||||
|
|
||||||
|
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
||||||
|
// "runServices": [],
|
||||||
|
|
||||||
|
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
|
||||||
|
// "shutdownAction": "none",
|
||||||
|
|
||||||
|
// Uncomment the next line to run commands after the container is created - for example installing curl.
|
||||||
|
// "postCreateCommand": "sudo apt-get update && apt-get install -y git",
|
||||||
|
|
||||||
|
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
|
||||||
|
"remoteUser": "ftuser"
|
||||||
}
|
}
|
||||||
|
24
.devcontainer/docker-compose.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
ft_vscode:
|
||||||
|
build:
|
||||||
|
context: ..
|
||||||
|
dockerfile: ".devcontainer/Dockerfile"
|
||||||
|
volumes:
|
||||||
|
# Allow git usage within container
|
||||||
|
- "${HOME}/.ssh:/home/ftuser/.ssh:ro"
|
||||||
|
- "${HOME}/.gitconfig:/home/ftuser/.gitconfig:ro"
|
||||||
|
- ..:/freqtrade:cached
|
||||||
|
# Persist bash-history
|
||||||
|
- freqtrade-vscode-server:/home/ftuser/.vscode-server
|
||||||
|
- freqtrade-bashhistory:/home/ftuser/commandhistory
|
||||||
|
# Expose API port
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
command: /bin/sh -c "while sleep 1000; do :; done"
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
freqtrade-vscode-server:
|
||||||
|
freqtrade-bashhistory:
|
3
.github/FUNDING.yml
vendored
@ -1,3 +0,0 @@
|
|||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: [xmatthias]
|
|
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -9,7 +9,7 @@ assignees: ''
|
|||||||
<!--
|
<!--
|
||||||
Have you searched for similar issues before posting it?
|
Have you searched for similar issues before posting it?
|
||||||
|
|
||||||
If you have discovered a bug in the bot, please [search the issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue).
|
If you have discovered a bug in the bot, please [search our issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue).
|
||||||
If it hasn't been reported, please create a new issue.
|
If it hasn't been reported, please create a new issue.
|
||||||
|
|
||||||
Please do not use bug reports to request new features.
|
Please do not use bug reports to request new features.
|
||||||
@ -20,7 +20,7 @@ Please do not use bug reports to request new features.
|
|||||||
* Operating system: ____
|
* Operating system: ____
|
||||||
* Python Version: _____ (`python -V`)
|
* Python Version: _____ (`python -V`)
|
||||||
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
||||||
* Freqtrade Version: ____ (`freqtrade -V` or `docker compose run --rm freqtrade -V` for Freqtrade running in docker)
|
* Freqtrade Version: ____ (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)
|
||||||
|
|
||||||
Note: All issues other than enhancement requests will be closed without further comment if the above template is deleted or not filled out.
|
Note: All issues other than enhancement requests will be closed without further comment if the above template is deleted or not filled out.
|
||||||
|
|
||||||
|
3
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -18,9 +18,10 @@ Have you search for this feature before requesting it? It's highly likely that a
|
|||||||
* Operating system: ____
|
* Operating system: ____
|
||||||
* Python Version: _____ (`python -V`)
|
* Python Version: _____ (`python -V`)
|
||||||
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
||||||
* Freqtrade Version: ____ (`freqtrade -V` or `docker compose run --rm freqtrade -V` for Freqtrade running in docker)
|
* Freqtrade Version: ____ (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)
|
||||||
|
|
||||||
|
|
||||||
## Describe the enhancement
|
## Describe the enhancement
|
||||||
|
|
||||||
*Explain the enhancement you would like*
|
*Explain the enhancement you would like*
|
||||||
|
|
||||||
|
4
.github/ISSUE_TEMPLATE/question.md
vendored
@ -18,8 +18,8 @@ Please do not use the question template to report bugs or to request new feature
|
|||||||
* Operating system: ____
|
* Operating system: ____
|
||||||
* Python Version: _____ (`python -V`)
|
* Python Version: _____ (`python -V`)
|
||||||
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
* CCXT version: _____ (`pip freeze | grep ccxt`)
|
||||||
* Freqtrade Version: ____ (`freqtrade -V` or `docker compose run --rm freqtrade -V` for Freqtrade running in docker)
|
* Freqtrade Version: ____ (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)
|
||||||
|
|
||||||
## Your question
|
## Your question
|
||||||
|
|
||||||
*Ask the question you have not been able to find an answer in the [Documentation](https://www.freqtrade.io/en/latest/)*
|
*Ask the question you have not been able to find an answer in our [Documentation](https://www.freqtrade.io/en/latest/)*
|
||||||
|
14
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,17 +1,15 @@
|
|||||||
<!-- Thank you for sending your pull request. But first, have you included
|
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/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md)
|
unit tests, and is your code PEP8 conformant? [More details](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md)
|
||||||
-->
|
|
||||||
## Summary
|
|
||||||
|
|
||||||
<!-- Explain in one sentence the goal of this PR -->
|
## Summary
|
||||||
|
Explain in one sentence the goal of this PR
|
||||||
|
|
||||||
Solve the issue: #___
|
Solve the issue: #___
|
||||||
|
|
||||||
## Quick changelog
|
## Quick changelog
|
||||||
|
|
||||||
- <change log 1>
|
- <change log #1>
|
||||||
- <change log 1>
|
- <change log #2>
|
||||||
|
|
||||||
## What's new?
|
## What's new?
|
||||||
|
*Explain in details what this PR solve or improve. You can include visuals.*
|
||||||
<!-- Explain in details what this PR solve or improve. You can include visuals. -->
|
|
||||||
|
8
.github/dependabot.yml
vendored
@ -5,17 +5,9 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: weekly
|
interval: weekly
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
target-branch: develop
|
target-branch: develop
|
||||||
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
target-branch: develop
|
|
||||||
|
479
.github/workflows/ci.yml
vendored
@ -3,9 +3,9 @@ name: Freqtrade CI
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
- master
|
||||||
- stable
|
- stable
|
||||||
- develop
|
- develop
|
||||||
- ci/*
|
|
||||||
tags:
|
tags:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
@ -13,38 +13,33 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 5 * * 4'
|
- cron: '0 5 * * 4'
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
permissions:
|
|
||||||
repository-projects: read
|
|
||||||
jobs:
|
jobs:
|
||||||
build_linux:
|
build_linux:
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-20.04, ubuntu-22.04 ]
|
os: [ ubuntu-18.04, ubuntu-20.04 ]
|
||||||
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
python-version: [3.7, 3.8, 3.9]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Cache_dependencies
|
- name: Cache_dependencies
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: ~/dependencies/
|
path: ~/dependencies/
|
||||||
key: ${{ runner.os }}-dependencies
|
key: ${{ runner.os }}-dependencies
|
||||||
|
|
||||||
- name: pip cache (linux)
|
- name: pip cache (linux)
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
if: runner.os == 'Linux'
|
if: startsWith(matrix.os, 'ubuntu')
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
|
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
|
||||||
@ -55,9 +50,107 @@ jobs:
|
|||||||
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
|
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
|
||||||
|
|
||||||
- name: Installation - *nix
|
- name: Installation - *nix
|
||||||
if: runner.os == 'Linux'
|
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip wheel
|
python -m pip install --upgrade pip
|
||||||
|
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
||||||
|
export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
||||||
|
export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
||||||
|
pip install -r requirements-dev.txt
|
||||||
|
pip install -e .
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: |
|
||||||
|
pytest --random-order --cov=freqtrade --cov-config=.coveragerc
|
||||||
|
if: matrix.python-version != '3.9'
|
||||||
|
|
||||||
|
- name: Tests incl. ccxt compatibility tests
|
||||||
|
run: |
|
||||||
|
pytest --random-order --cov=freqtrade --cov-config=.coveragerc --longrun
|
||||||
|
if: matrix.python-version == '3.9'
|
||||||
|
|
||||||
|
- name: Coveralls
|
||||||
|
if: (startsWith(matrix.os, 'ubuntu-20') && matrix.python-version == '3.8')
|
||||||
|
env:
|
||||||
|
# Coveralls token. Not used as secret due to github not providing secrets to forked repositories
|
||||||
|
COVERALLS_REPO_TOKEN: 6D1m0xupS3FgutfuGao8keFf9Hc0FpIXu
|
||||||
|
run: |
|
||||||
|
# Allow failure for coveralls
|
||||||
|
coveralls || true
|
||||||
|
|
||||||
|
- name: Backtesting
|
||||||
|
run: |
|
||||||
|
cp config_bittrex.json.example config.json
|
||||||
|
freqtrade create-userdir --userdir user_data
|
||||||
|
freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy
|
||||||
|
|
||||||
|
- name: Hyperopt
|
||||||
|
run: |
|
||||||
|
cp config_bittrex.json.example config.json
|
||||||
|
freqtrade create-userdir --userdir user_data
|
||||||
|
freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
||||||
|
|
||||||
|
- name: Flake8
|
||||||
|
run: |
|
||||||
|
flake8
|
||||||
|
|
||||||
|
- name: Sort imports (isort)
|
||||||
|
run: |
|
||||||
|
isort --check .
|
||||||
|
|
||||||
|
- name: Mypy
|
||||||
|
run: |
|
||||||
|
mypy freqtrade scripts
|
||||||
|
|
||||||
|
- name: Slack Notification
|
||||||
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
|
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
|
with:
|
||||||
|
type: ${{ job.status }}
|
||||||
|
job_name: '*Freqtrade CI ${{ matrix.os }}*'
|
||||||
|
mention: 'here'
|
||||||
|
mention_if: 'failure'
|
||||||
|
channel: '#notifications'
|
||||||
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
||||||
|
build_macos:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ macos-latest ]
|
||||||
|
python-version: [3.7, 3.8, 3.9]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Cache_dependencies
|
||||||
|
uses: actions/cache@v2
|
||||||
|
id: cache
|
||||||
|
with:
|
||||||
|
path: ~/dependencies/
|
||||||
|
key: ${{ runner.os }}-dependencies
|
||||||
|
|
||||||
|
- name: pip cache (macOS)
|
||||||
|
uses: actions/cache@v2
|
||||||
|
if: startsWith(matrix.os, 'macOS')
|
||||||
|
with:
|
||||||
|
path: ~/Library/Caches/pip
|
||||||
|
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
|
||||||
|
|
||||||
|
- name: TA binary *nix
|
||||||
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
|
||||||
|
|
||||||
|
- name: Installation - macOS
|
||||||
|
run: |
|
||||||
|
brew update
|
||||||
|
brew install hdf5 c-blosc
|
||||||
|
python -m pip install --upgrade pip
|
||||||
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
||||||
export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
||||||
export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
||||||
@ -69,143 +162,49 @@ jobs:
|
|||||||
pytest --random-order --cov=freqtrade --cov-config=.coveragerc
|
pytest --random-order --cov=freqtrade --cov-config=.coveragerc
|
||||||
|
|
||||||
- name: Coveralls
|
- name: Coveralls
|
||||||
if: (runner.os == 'Linux' && matrix.python-version == '3.10' && matrix.os == 'ubuntu-22.04')
|
if: (startsWith(matrix.os, 'ubuntu-20') && matrix.python-version == '3.8')
|
||||||
env:
|
env:
|
||||||
# Coveralls token. Not used as secret due to github not providing secrets to forked repositories
|
# Coveralls token. Not used as secret due to github not providing secrets to forked repositories
|
||||||
COVERALLS_REPO_TOKEN: 6D1m0xupS3FgutfuGao8keFf9Hc0FpIXu
|
COVERALLS_REPO_TOKEN: 6D1m0xupS3FgutfuGao8keFf9Hc0FpIXu
|
||||||
run: |
|
run: |
|
||||||
# Allow failure for coveralls
|
# Allow failure for coveralls
|
||||||
coveralls || true
|
coveralls -v || true
|
||||||
|
|
||||||
- name: Backtesting (multi)
|
|
||||||
run: |
|
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
|
||||||
freqtrade create-userdir --userdir user_data
|
|
||||||
freqtrade new-strategy -s AwesomeStrategy
|
|
||||||
freqtrade new-strategy -s AwesomeStrategyMin --template minimal
|
|
||||||
freqtrade backtesting --datadir tests/testdata --strategy-list AwesomeStrategy AwesomeStrategyMin -i 5m
|
|
||||||
|
|
||||||
- name: Hyperopt
|
|
||||||
run: |
|
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
|
||||||
freqtrade create-userdir --userdir user_data
|
|
||||||
freqtrade hyperopt --datadir tests/testdata -e 6 --strategy SampleStrategy --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
|
||||||
|
|
||||||
- name: Sort imports (isort)
|
|
||||||
run: |
|
|
||||||
isort --check .
|
|
||||||
|
|
||||||
- name: Run Ruff
|
|
||||||
run: |
|
|
||||||
ruff check --format=github .
|
|
||||||
|
|
||||||
- name: Mypy
|
|
||||||
run: |
|
|
||||||
mypy freqtrade scripts tests
|
|
||||||
|
|
||||||
- name: Discord notification
|
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
|
||||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
|
||||||
with:
|
|
||||||
severity: error
|
|
||||||
details: Freqtrade CI failed on ${{ matrix.os }}
|
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
|
||||||
|
|
||||||
build_macos:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os: [ macos-latest ]
|
|
||||||
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: ${{ matrix.python-version }}
|
|
||||||
|
|
||||||
- name: Cache_dependencies
|
|
||||||
uses: actions/cache@v3
|
|
||||||
id: cache
|
|
||||||
with:
|
|
||||||
path: ~/dependencies/
|
|
||||||
key: ${{ runner.os }}-dependencies
|
|
||||||
|
|
||||||
- name: pip cache (macOS)
|
|
||||||
uses: actions/cache@v3
|
|
||||||
if: runner.os == 'macOS'
|
|
||||||
with:
|
|
||||||
path: ~/Library/Caches/pip
|
|
||||||
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
|
|
||||||
|
|
||||||
- name: TA binary *nix
|
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
|
||||||
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
|
|
||||||
|
|
||||||
- name: Installation - macOS
|
|
||||||
if: runner.os == 'macOS'
|
|
||||||
run: |
|
|
||||||
brew update
|
|
||||||
# homebrew fails to update python due to unlinking failures
|
|
||||||
# https://github.com/actions/runner-images/issues/6817
|
|
||||||
rm /usr/local/bin/2to3 || true
|
|
||||||
rm /usr/local/bin/2to3-3.11 || true
|
|
||||||
rm /usr/local/bin/idle3 || true
|
|
||||||
rm /usr/local/bin/idle3.11 || true
|
|
||||||
rm /usr/local/bin/pydoc3 || true
|
|
||||||
rm /usr/local/bin/pydoc3.11 || true
|
|
||||||
rm /usr/local/bin/python3 || true
|
|
||||||
rm /usr/local/bin/python3.11 || true
|
|
||||||
rm /usr/local/bin/python3-config || true
|
|
||||||
rm /usr/local/bin/python3.11-config || true
|
|
||||||
|
|
||||||
brew install hdf5 c-blosc
|
|
||||||
python -m pip install --upgrade pip wheel
|
|
||||||
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
|
||||||
export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
|
||||||
export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
|
||||||
pip install -r requirements-dev.txt
|
|
||||||
pip install -e .
|
|
||||||
|
|
||||||
- name: Tests
|
|
||||||
run: |
|
|
||||||
pytest --random-order
|
|
||||||
|
|
||||||
- name: Backtesting
|
- name: Backtesting
|
||||||
run: |
|
run: |
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
cp config_bittrex.json.example config.json
|
||||||
freqtrade create-userdir --userdir user_data
|
freqtrade create-userdir --userdir user_data
|
||||||
freqtrade new-strategy -s AwesomeStrategyAdv --template advanced
|
freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy
|
||||||
freqtrade backtesting --datadir tests/testdata --strategy AwesomeStrategyAdv
|
|
||||||
|
|
||||||
- name: Hyperopt
|
- name: Hyperopt
|
||||||
run: |
|
run: |
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
cp config_bittrex.json.example config.json
|
||||||
freqtrade create-userdir --userdir user_data
|
freqtrade create-userdir --userdir user_data
|
||||||
freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
||||||
|
|
||||||
|
- name: Flake8
|
||||||
|
run: |
|
||||||
|
flake8
|
||||||
|
|
||||||
- name: Sort imports (isort)
|
- name: Sort imports (isort)
|
||||||
run: |
|
run: |
|
||||||
isort --check .
|
isort --check .
|
||||||
|
|
||||||
- name: Run Ruff
|
|
||||||
run: |
|
|
||||||
ruff check --format=github .
|
|
||||||
|
|
||||||
- name: Mypy
|
- name: Mypy
|
||||||
run: |
|
run: |
|
||||||
mypy freqtrade scripts
|
mypy freqtrade scripts
|
||||||
|
|
||||||
- name: Discord notification
|
- name: Slack Notification
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
with:
|
with:
|
||||||
severity: info
|
type: ${{ job.status }}
|
||||||
details: Test Succeeded!
|
job_name: '*Freqtrade CI ${{ matrix.os }}*'
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
mention: 'here'
|
||||||
|
mention_if: 'failure'
|
||||||
|
channel: '#notifications'
|
||||||
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
||||||
|
|
||||||
build_windows:
|
build_windows:
|
||||||
|
|
||||||
@ -213,18 +212,19 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ windows-latest ]
|
os: [ windows-latest ]
|
||||||
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
python-version: [3.7, 3.8]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Pip cache (Windows)
|
- name: Pip cache (Windows)
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@preview
|
||||||
|
if: startsWith(runner.os, 'Windows')
|
||||||
with:
|
with:
|
||||||
path: ~\AppData\Local\pip\Cache
|
path: ~\AppData\Local\pip\Cache
|
||||||
key: ${{ matrix.os }}-${{ matrix.python-version }}-pip
|
key: ${{ matrix.os }}-${{ matrix.python-version }}-pip
|
||||||
@ -235,74 +235,52 @@ jobs:
|
|||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: |
|
run: |
|
||||||
pytest --random-order
|
pytest --random-order --cov=freqtrade --cov-config=.coveragerc
|
||||||
|
|
||||||
- name: Backtesting
|
- name: Backtesting
|
||||||
run: |
|
run: |
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
cp config_bittrex.json.example config.json
|
||||||
freqtrade create-userdir --userdir user_data
|
freqtrade create-userdir --userdir user_data
|
||||||
freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy
|
freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy
|
||||||
|
|
||||||
- name: Hyperopt
|
- name: Hyperopt
|
||||||
run: |
|
run: |
|
||||||
cp config_examples/config_bittrex.example.json config.json
|
cp config_bittrex.json.example config.json
|
||||||
freqtrade create-userdir --userdir user_data
|
freqtrade create-userdir --userdir user_data
|
||||||
freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all
|
||||||
|
|
||||||
- name: Run Ruff
|
- name: Flake8
|
||||||
run: |
|
run: |
|
||||||
ruff check --format=github .
|
flake8
|
||||||
|
|
||||||
- name: Mypy
|
- name: Mypy
|
||||||
run: |
|
run: |
|
||||||
mypy freqtrade scripts tests
|
mypy freqtrade scripts
|
||||||
|
|
||||||
- name: Discord notification
|
- name: Slack Notification
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
with:
|
with:
|
||||||
severity: error
|
type: ${{ job.status }}
|
||||||
details: Test Failed
|
job_name: '*Freqtrade CI windows*'
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
mention: 'here'
|
||||||
|
mention_if: 'failure'
|
||||||
mypy_version_check:
|
channel: '#notifications'
|
||||||
runs-on: ubuntu-22.04
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
|
|
||||||
- name: pre-commit dependencies
|
|
||||||
run: |
|
|
||||||
pip install pyaml
|
|
||||||
python build_helpers/pre_commit_update.py
|
|
||||||
|
|
||||||
pre-commit:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
- uses: pre-commit/action@v3.0.0
|
|
||||||
|
|
||||||
docs_check:
|
docs_check:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Documentation syntax
|
- name: Documentation syntax
|
||||||
run: |
|
run: |
|
||||||
./tests/test_docs.sh
|
./tests/test_docs.sh
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: 3.8
|
||||||
|
|
||||||
- name: Documentation build
|
- name: Documentation build
|
||||||
run: |
|
run: |
|
||||||
@ -310,78 +288,28 @@ jobs:
|
|||||||
pip install mkdocs
|
pip install mkdocs
|
||||||
mkdocs build
|
mkdocs build
|
||||||
|
|
||||||
- name: Discord notification
|
- name: Slack Notification
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
with:
|
with:
|
||||||
severity: error
|
type: ${{ job.status }}
|
||||||
details: Freqtrade doc test failed!
|
job_name: '*Freqtrade Docs*'
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
channel: '#notifications'
|
||||||
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
||||||
|
cleanup-prior-runs:
|
||||||
build_linux_online:
|
runs-on: ubuntu-20.04
|
||||||
# Run pytest with "live" checks
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Cleanup previous runs on this branch
|
||||||
|
uses: rokroskar/workflow-run-cleanup-action@v0.3.3
|
||||||
- name: Set up Python
|
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/stable' && github.repository == 'freqtrade/freqtrade'"
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.9"
|
|
||||||
|
|
||||||
- name: Cache_dependencies
|
|
||||||
uses: actions/cache@v3
|
|
||||||
id: cache
|
|
||||||
with:
|
|
||||||
path: ~/dependencies/
|
|
||||||
key: ${{ runner.os }}-dependencies
|
|
||||||
|
|
||||||
- name: pip cache (linux)
|
|
||||||
uses: actions/cache@v3
|
|
||||||
if: runner.os == 'Linux'
|
|
||||||
with:
|
|
||||||
path: ~/.cache/pip
|
|
||||||
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
|
|
||||||
|
|
||||||
- name: TA binary *nix
|
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
|
||||||
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
|
|
||||||
|
|
||||||
- name: Installation - *nix
|
|
||||||
if: runner.os == 'Linux'
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip wheel
|
|
||||||
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
|
||||||
export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
|
||||||
export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
|
||||||
pip install -r requirements-dev.txt
|
|
||||||
pip install -e .
|
|
||||||
|
|
||||||
- name: Tests incl. ccxt compatibility tests
|
|
||||||
env:
|
env:
|
||||||
CI_WEB_PROXY: http://152.67.78.211:13128
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
run: |
|
|
||||||
pytest --random-order --cov=freqtrade --cov-config=.coveragerc --longrun
|
|
||||||
|
|
||||||
|
# Notify on slack only once - when CI completes (and after deploy) in case it's successfull
|
||||||
# Notify only once - when CI completes (and after deploy) in case it's successfull
|
|
||||||
notify-complete:
|
notify-complete:
|
||||||
needs: [
|
needs: [ build_linux, build_macos, build_windows, docs_check ]
|
||||||
build_linux,
|
runs-on: ubuntu-20.04
|
||||||
build_macos,
|
|
||||||
build_windows,
|
|
||||||
docs_check,
|
|
||||||
mypy_version_check,
|
|
||||||
pre-commit,
|
|
||||||
build_linux_online
|
|
||||||
]
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
# Discord notification can't handle schedule events
|
|
||||||
if: (github.event_name != 'schedule')
|
|
||||||
permissions:
|
|
||||||
repository-projects: read
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Check user permission
|
- name: Check user permission
|
||||||
@ -392,27 +320,27 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Discord notification
|
- name: Slack Notification
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
if: always() && steps.check.outputs.has-permission && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
if: always() && steps.check.outputs.has-permission && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
with:
|
with:
|
||||||
severity: info
|
type: ${{ job.status }}
|
||||||
details: Test Completed!
|
job_name: '*Freqtrade CI*'
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
channel: '#notifications'
|
||||||
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: [ build_linux, build_macos, build_windows, docs_check, mypy_version_check, pre-commit ]
|
needs: [ build_linux, build_macos, build_windows, docs_check ]
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release') && github.repository == 'freqtrade/freqtrade'
|
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release') && github.repository == 'freqtrade/freqtrade'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: "3.9"
|
python-version: 3.8
|
||||||
|
|
||||||
- name: Extract branch name
|
- name: Extract branch name
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -425,7 +353,7 @@ jobs:
|
|||||||
python setup.py sdist bdist_wheel
|
python setup.py sdist bdist_wheel
|
||||||
|
|
||||||
- name: Publish to PyPI (Test)
|
- name: Publish to PyPI (Test)
|
||||||
uses: pypa/gh-action-pypi-publish@v1.8.5
|
uses: pypa/gh-action-pypi-publish@master
|
||||||
if: (github.event_name == 'release')
|
if: (github.event_name == 'release')
|
||||||
with:
|
with:
|
||||||
user: __token__
|
user: __token__
|
||||||
@ -433,7 +361,7 @@ jobs:
|
|||||||
repository_url: https://test.pypi.org/legacy/
|
repository_url: https://test.pypi.org/legacy/
|
||||||
|
|
||||||
- name: Publish to PyPI
|
- name: Publish to PyPI
|
||||||
uses: pypa/gh-action-pypi-publish@v1.8.5
|
uses: pypa/gh-action-pypi-publish@master
|
||||||
if: (github.event_name == 'release')
|
if: (github.event_name == 'release')
|
||||||
with:
|
with:
|
||||||
user: __token__
|
user: __token__
|
||||||
@ -456,7 +384,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: crazy-max/ghaction-docker-buildx@v3.3.1
|
uses: crazy-max/ghaction-docker-buildx@v1
|
||||||
with:
|
with:
|
||||||
buildx-version: latest
|
buildx-version: latest
|
||||||
qemu-version: latest
|
qemu-version: latest
|
||||||
@ -466,45 +394,20 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and test and push docker images
|
- name: Build and test and push docker images
|
||||||
env:
|
env:
|
||||||
|
IMAGE_NAME: freqtradeorg/freqtrade
|
||||||
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
|
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
|
||||||
run: |
|
run: |
|
||||||
build_helpers/publish_docker_multi.sh
|
build_helpers/publish_docker_multi.sh
|
||||||
|
|
||||||
deploy_arm:
|
|
||||||
permissions:
|
|
||||||
packages: write
|
|
||||||
needs: [ deploy ]
|
|
||||||
# Only run on 64bit machines
|
|
||||||
runs-on: [self-hosted, linux, ARM64]
|
|
||||||
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release') && github.repository == 'freqtrade/freqtrade'
|
|
||||||
|
|
||||||
steps:
|
- name: Slack Notification
|
||||||
- uses: actions/checkout@v3
|
uses: lazy-actions/slatify@v3.0.0
|
||||||
|
if: always() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||||
- name: Extract branch name
|
|
||||||
shell: bash
|
|
||||||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
|
|
||||||
id: extract_branch
|
|
||||||
|
|
||||||
- name: Dockerhub login
|
|
||||||
env:
|
|
||||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
run: |
|
|
||||||
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
|
|
||||||
|
|
||||||
- name: Build and test and push docker images
|
|
||||||
env:
|
|
||||||
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
|
|
||||||
GHCR_USERNAME: ${{ github.actor }}
|
|
||||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
build_helpers/publish_docker_arm64.sh
|
|
||||||
|
|
||||||
- name: Discord notification
|
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
|
||||||
if: always() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) && (github.event_name != 'schedule')
|
|
||||||
with:
|
with:
|
||||||
severity: info
|
type: ${{ job.status }}
|
||||||
details: Deploy Succeeded!
|
job_name: '*Freqtrade CI Deploy*'
|
||||||
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
mention: 'here'
|
||||||
|
mention_if: 'failure'
|
||||||
|
channel: '#notifications'
|
||||||
|
url: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
||||||
|
5
.github/workflows/docker_update_readme.yml
vendored
@ -8,10 +8,11 @@ jobs:
|
|||||||
dockerHubDescription:
|
dockerHubDescription:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v1
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v2.1.0
|
||||||
env:
|
env:
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
DOCKERHUB_REPOSITORY: freqtradeorg/freqtrade
|
DOCKERHUB_REPOSITORY: freqtradeorg/freqtrade
|
||||||
|
|
||||||
|
17
.gitignore
vendored
@ -1,24 +1,14 @@
|
|||||||
# Freqtrade rules
|
# Freqtrade rules
|
||||||
config*.json
|
config*.json
|
||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-shm
|
|
||||||
*.sqlite-wal
|
|
||||||
logfile.txt
|
logfile.txt
|
||||||
user_data/*
|
user_data/*
|
||||||
!user_data/strategy/sample_strategy.py
|
!user_data/strategy/sample_strategy.py
|
||||||
!user_data/notebooks
|
!user_data/notebooks
|
||||||
!user_data/models
|
|
||||||
!user_data/freqaimodels
|
|
||||||
user_data/freqaimodels/*
|
|
||||||
user_data/models/*
|
|
||||||
user_data/notebooks/*
|
user_data/notebooks/*
|
||||||
freqtrade-plot.html
|
freqtrade-plot.html
|
||||||
freqtrade-profit-plot.html
|
freqtrade-profit-plot.html
|
||||||
freqtrade/rpc/api_server/ui/*
|
freqtrade/rpc/api_server/ui/*
|
||||||
build_helpers/ta-lib/*
|
|
||||||
|
|
||||||
# Macos related
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
@ -85,8 +75,6 @@ instance/
|
|||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
# Mkdocs documentation
|
|
||||||
site/
|
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
@ -107,8 +95,3 @@ target/
|
|||||||
|
|
||||||
#exceptions
|
#exceptions
|
||||||
!*.gitkeep
|
!*.gitkeep
|
||||||
!config_examples/config_binance.example.json
|
|
||||||
!config_examples/config_bittrex.example.json
|
|
||||||
!config_examples/config_full.example.json
|
|
||||||
!config_examples/config_kraken.example.json
|
|
||||||
!config_examples/config_freqai.example.json
|
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
# See https://pre-commit.com for more information
|
|
||||||
# See https://pre-commit.com/hooks.html for more hooks
|
|
||||||
repos:
|
|
||||||
- repo: https://github.com/pycqa/flake8
|
|
||||||
rev: "6.0.0"
|
|
||||||
hooks:
|
|
||||||
- id: flake8
|
|
||||||
# stages: [push]
|
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
||||||
rev: "v1.0.1"
|
|
||||||
hooks:
|
|
||||||
- id: mypy
|
|
||||||
exclude: build_helpers
|
|
||||||
additional_dependencies:
|
|
||||||
- types-cachetools==5.3.0.5
|
|
||||||
- types-filelock==3.2.7
|
|
||||||
- types-requests==2.28.11.17
|
|
||||||
- types-tabulate==0.9.0.2
|
|
||||||
- types-python-dateutil==2.8.19.12
|
|
||||||
- SQLAlchemy==2.0.9
|
|
||||||
# stages: [push]
|
|
||||||
|
|
||||||
- repo: https://github.com/pycqa/isort
|
|
||||||
rev: "5.12.0"
|
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
name: isort (python)
|
|
||||||
# stages: [push]
|
|
||||||
|
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
||||||
# Ruff version.
|
|
||||||
rev: 'v0.0.255'
|
|
||||||
hooks:
|
|
||||||
- id: ruff
|
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v4.4.0
|
|
||||||
hooks:
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
exclude: |
|
|
||||||
(?x)^(
|
|
||||||
tests/.*|
|
|
||||||
.*\.svg|
|
|
||||||
.*\.yml|
|
|
||||||
.*\.json
|
|
||||||
)$
|
|
||||||
- id: mixed-line-ending
|
|
||||||
- id: debug-statements
|
|
||||||
- id: check-ast
|
|
||||||
- id: trailing-whitespace
|
|
||||||
exclude: |
|
|
||||||
(?x)^(
|
|
||||||
.*\.md
|
|
||||||
)$
|
|
@ -7,3 +7,4 @@ ignore=vendor
|
|||||||
|
|
||||||
[TYPECHECK]
|
[TYPECHECK]
|
||||||
ignored-modules=numpy,talib,talib.abstract
|
ignored-modules=numpy,talib,talib.abstract
|
||||||
|
|
||||||
|
55
.travis.yml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
os:
|
||||||
|
- linux
|
||||||
|
dist: bionic
|
||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- 3.8
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- IMAGE_NAME=freqtradeorg/freqtrade
|
||||||
|
install:
|
||||||
|
- cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies; cd ..
|
||||||
|
- export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
|
||||||
|
- export TA_LIBRARY_PATH=${HOME}/dependencies/lib
|
||||||
|
- export TA_INCLUDE_PATH=${HOME}/dependencies/include
|
||||||
|
- pip install -r requirements-dev.txt
|
||||||
|
- pip install -e .
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
include:
|
||||||
|
- stage: tests
|
||||||
|
script:
|
||||||
|
- pytest --random-order --cov=freqtrade --cov-config=.coveragerc
|
||||||
|
# Allow failure for coveralls
|
||||||
|
# - coveralls || true
|
||||||
|
name: pytest
|
||||||
|
- script:
|
||||||
|
- cp config_bittrex.json.example config.json
|
||||||
|
- freqtrade create-userdir --userdir user_data
|
||||||
|
- freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy
|
||||||
|
name: backtest
|
||||||
|
- script:
|
||||||
|
- cp config_bittrex.json.example config.json
|
||||||
|
- freqtrade create-userdir --userdir user_data
|
||||||
|
- freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily
|
||||||
|
name: hyperopt
|
||||||
|
- script: flake8
|
||||||
|
name: flake8
|
||||||
|
- script:
|
||||||
|
# Test Documentation boxes -
|
||||||
|
# !!! <TYPE>: is not allowed!
|
||||||
|
# !!! <TYPE> "title" - Title needs to be quoted!
|
||||||
|
- grep -Er '^!{3}\s\S+:|^!{3}\s\S+\s[^"]' docs/*; test $? -ne 0
|
||||||
|
name: doc syntax
|
||||||
|
- script: mypy freqtrade scripts
|
||||||
|
name: mypy
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
slack:
|
||||||
|
secure: bKLXmOrx8e2aPZl7W8DA5BdPAXWGpI5UzST33oc1G/thegXcDVmHBTJrBs4sZak6bgAclQQrdZIsRd2eFYzHLalJEaw6pk7hoAw8SvLnZO0ZurWboz7qg2+aZZXfK4eKl/VUe4sM9M4e/qxjkK+yWG7Marg69c4v1ypF7ezUi1fPYILYw8u0paaiX0N5UX8XNlXy+PBlga2MxDjUY70MuajSZhPsY2pDUvYnMY1D/7XN3cFW0g+3O8zXjF0IF4q1Z/1ASQe+eYjKwPQacE+O8KDD+ZJYoTOFBAPllrtpO1jnOPFjNGf3JIbVMZw4bFjIL0mSQaiSUaUErbU3sFZ5Or79rF93XZ81V7uEZ55vD8KMfR2CB1cQJcZcj0v50BxLo0InkFqa0Y8Nra3sbpV4fV5Oe8pDmomPJrNFJnX6ULQhQ1gTCe0M5beKgVms5SITEpt4/Y0CmLUr6iHDT0CUiyMIRWAXdIgbGh1jfaWOMksybeRevlgDsIsNBjXmYI1Sw2ZZR2Eo2u4R6zyfyjOMLwYJ3vgq9IrACv2w5nmf0+oguMWHf6iWi2hiOqhlAN1W74+3HsYQcqnuM3LGOmuCnPprV1oGBqkPXjIFGpy21gNx4vHfO1noLUyJnMnlu2L7SSuN1CdLsnjJ1hVjpJjPfqB4nn8g12x87TqM1bOm+3Q=
|
||||||
|
cache:
|
||||||
|
pip: True
|
||||||
|
directories:
|
||||||
|
- $HOME/dependencies
|
@ -12,7 +12,7 @@ Few pointers for contributions:
|
|||||||
- New features need to contain unit tests, must conform to PEP8 (max-line-length = 100) and should be documented with the introduction PR.
|
- New features need to contain unit tests, must conform to PEP8 (max-line-length = 100) and should be documented with the introduction PR.
|
||||||
- PR's can be declared as `[WIP]` - which signify Work in Progress Pull Requests (which are not finished).
|
- PR's can be declared as `[WIP]` - which signify Work in Progress Pull Requests (which are not finished).
|
||||||
|
|
||||||
If you are unsure, discuss the feature on our [discord server](https://discord.gg/p7nuUNVfP7) or in a [issue](https://github.com/freqtrade/freqtrade/issues) before a Pull Request.
|
If you are unsure, discuss the feature on our [discord server](https://discord.gg/p7nuUNVfP7), on [Slack](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw) or in a [issue](https://github.com/freqtrade/freqtrade/issues) before a PR.
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
@ -45,24 +45,16 @@ pytest tests/test_<file_name>.py::test_<method_name>
|
|||||||
|
|
||||||
### 2. Test if your code is PEP8 compliant
|
### 2. Test if your code is PEP8 compliant
|
||||||
|
|
||||||
#### Run Ruff
|
#### Run Flake8
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ruff .
|
flake8 freqtrade tests scripts
|
||||||
```
|
```
|
||||||
|
|
||||||
We receive a lot of code that fails the `ruff` checks.
|
We receive a lot of code that fails the `flake8` checks.
|
||||||
To help with that, we encourage you to install the git pre-commit
|
To help with that, we encourage you to install the git pre-commit
|
||||||
hook that will warn you when you try to commit code that fails these checks.
|
hook that will warn you when you try to commit code that fails these checks.
|
||||||
|
Guide for installing them is [here](http://flake8.pycqa.org/en/latest/user/using-hooks.html).
|
||||||
you can manually run pre-commit with `pre-commit run -a`.
|
|
||||||
|
|
||||||
##### Additional styles applied
|
|
||||||
|
|
||||||
* Have docstrings on all public methods
|
|
||||||
* Use double-quotes for docstrings
|
|
||||||
* Multiline docstrings should be indented to the level of the first quote
|
|
||||||
* Doc-strings should follow the reST format (`:param xxx: ...`, `:return: ...`, `:raises KeyError: ... `)
|
|
||||||
|
|
||||||
### 3. Test if all type-hints are correct
|
### 3. Test if all type-hints are correct
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.10.11-slim-bullseye as base
|
FROM python:3.9.5-slim-buster as base
|
||||||
|
|
||||||
# Setup env
|
# Setup env
|
||||||
ENV LANG C.UTF-8
|
ENV LANG C.UTF-8
|
||||||
@ -11,9 +11,9 @@ ENV FT_APP_ENV="docker"
|
|||||||
# Prepare environment
|
# Prepare environment
|
||||||
RUN mkdir /freqtrade \
|
RUN mkdir /freqtrade \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get -y install sudo libatlas3-base curl sqlite3 libhdf5-serial-dev libgomp1 \
|
&& apt-get -y install sudo libatlas3-base curl sqlite3 libhdf5-serial-dev \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& useradd -u 1000 -G sudo -U -m -s /bin/bash ftuser \
|
&& useradd -u 1000 -G sudo -U -m ftuser \
|
||||||
&& chown ftuser:ftuser /freqtrade \
|
&& chown ftuser:ftuser /freqtrade \
|
||||||
# Allow sudoers
|
# Allow sudoers
|
||||||
&& echo "ftuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers
|
&& echo "ftuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers
|
||||||
|
@ -2,6 +2,5 @@ include LICENSE
|
|||||||
include README.md
|
include README.md
|
||||||
recursive-include freqtrade *.py
|
recursive-include freqtrade *.py
|
||||||
recursive-include freqtrade/templates/ *.j2 *.ipynb
|
recursive-include freqtrade/templates/ *.j2 *.ipynb
|
||||||
include freqtrade/exchange/binance_leverage_tiers.json
|
|
||||||
include freqtrade/rpc/api_server/ui/fallback_file.html
|
include freqtrade/rpc/api_server/ui/fallback_file.html
|
||||||
include freqtrade/rpc/api_server/ui/favicon.ico
|
include freqtrade/rpc/api_server/ui/favicon.ico
|
||||||
|
83
README.md
@ -1,12 +1,11 @@
|
|||||||
# ![freqtrade](https://raw.githubusercontent.com/freqtrade/freqtrade/develop/docs/assets/freqtrade_poweredby.svg)
|
# ![freqtrade](https://raw.githubusercontent.com/freqtrade/freqtrade/develop/docs/assets/freqtrade_poweredby.svg)
|
||||||
|
|
||||||
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/workflows/Freqtrade%20CI/badge.svg)](https://github.com/freqtrade/freqtrade/actions/)
|
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/workflows/Freqtrade%20CI/badge.svg)](https://github.com/freqtrade/freqtrade/actions/)
|
||||||
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04864/status.svg)](https://doi.org/10.21105/joss.04864)
|
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/freqtrade/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
[![Coverage Status](https://coveralls.io/repos/github/freqtrade/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
||||||
[![Documentation](https://readthedocs.org/projects/freqtrade/badge/)](https://www.freqtrade.io)
|
[![Documentation](https://readthedocs.org/projects/freqtrade/badge/)](https://www.freqtrade.io)
|
||||||
[![Maintainability](https://api.codeclimate.com/v1/badges/5737e6d668200b7518ff/maintainability)](https://codeclimate.com/github/freqtrade/freqtrade/maintainability)
|
[![Maintainability](https://api.codeclimate.com/v1/badges/5737e6d668200b7518ff/maintainability)](https://codeclimate.com/github/freqtrade/freqtrade/maintainability)
|
||||||
|
|
||||||
Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram or webUI. It contains backtesting, plotting and money management tools as well as strategy optimization by machine learning.
|
Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram. It contains backtesting, plotting and money management tools as well as strategy optimization by machine learning.
|
||||||
|
|
||||||
![freqtrade](https://raw.githubusercontent.com/freqtrade/freqtrade/develop/docs/assets/freqtrade-screenshot.png)
|
![freqtrade](https://raw.githubusercontent.com/freqtrade/freqtrade/develop/docs/assets/freqtrade-screenshot.png)
|
||||||
|
|
||||||
@ -27,57 +26,50 @@ hesitate to read the source code and understand the mechanism of this bot.
|
|||||||
|
|
||||||
Please read the [exchange specific notes](docs/exchanges.md) to learn about eventual, special configurations needed for each exchange.
|
Please read the [exchange specific notes](docs/exchanges.md) to learn about eventual, special configurations needed for each exchange.
|
||||||
|
|
||||||
- [X] [Binance](https://www.binance.com/)
|
|
||||||
- [X] [Bittrex](https://bittrex.com/)
|
- [X] [Bittrex](https://bittrex.com/)
|
||||||
- [X] [Gate.io](https://www.gate.io/ref/6266643)
|
- [X] [Binance](https://www.binance.com/) ([*Note for binance users](docs/exchanges.md#blacklists))
|
||||||
- [X] [Huobi](http://huobi.com/)
|
|
||||||
- [X] [Kraken](https://kraken.com/)
|
- [X] [Kraken](https://kraken.com/)
|
||||||
- [X] [OKX](https://okx.com/) (Former OKEX)
|
- [X] [FTX](https://ftx.com)
|
||||||
- [ ] [potentially many others](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_
|
- [ ] [potentially many others](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_
|
||||||
|
|
||||||
### Supported Futures Exchanges (experimental)
|
|
||||||
|
|
||||||
- [X] [Binance](https://www.binance.com/)
|
|
||||||
- [X] [Gate.io](https://www.gate.io/ref/6266643)
|
|
||||||
- [X] [OKX](https://okx.com/)
|
|
||||||
- [X] [Bybit](https://bybit.com/)
|
|
||||||
|
|
||||||
Please make sure to read the [exchange specific notes](docs/exchanges.md), as well as the [trading with leverage](docs/leverage.md) documentation before diving in.
|
|
||||||
|
|
||||||
### Community tested
|
### Community tested
|
||||||
|
|
||||||
Exchanges confirmed working by the community:
|
Exchanges confirmed working by the community:
|
||||||
|
|
||||||
- [X] [Bitvavo](https://bitvavo.com/)
|
- [X] [Bitvavo](https://bitvavo.com/)
|
||||||
- [X] [Kucoin](https://www.kucoin.com/)
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
We invite you to read the bot documentation to ensure you understand how the bot is working.
|
We invite you to read the bot documentation to ensure you understand how the bot is working.
|
||||||
|
|
||||||
Please find the complete documentation on the [freqtrade website](https://www.freqtrade.io).
|
Please find the complete documentation on our [website](https://www.freqtrade.io).
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] **Based on Python 3.8+**: For botting on any operating system - Windows, macOS and Linux.
|
- [x] **Based on Python 3.7+**: For botting on any operating system - Windows, macOS and Linux.
|
||||||
- [x] **Persistence**: Persistence is achieved through sqlite.
|
- [x] **Persistence**: Persistence is achieved through sqlite.
|
||||||
- [x] **Dry-run**: Run the bot without paying money.
|
- [x] **Dry-run**: Run the bot without paying money.
|
||||||
- [x] **Backtesting**: Run a simulation of your buy/sell strategy.
|
- [x] **Backtesting**: Run a simulation of your buy/sell strategy.
|
||||||
- [x] **Strategy Optimization by machine learning**: Use machine learning to optimize your buy/sell strategy parameters with real exchange data.
|
- [x] **Strategy Optimization by machine learning**: Use machine learning to optimize your buy/sell strategy parameters with real exchange data.
|
||||||
- [X] **Adaptive prediction modeling**: Build a smart strategy with FreqAI that self-trains to the market via adaptive machine learning methods. [Learn more](https://www.freqtrade.io/en/stable/freqai/)
|
- [x] **Edge position sizing** Calculate your win rate, risk reward ratio, the best stoploss and adjust your position size before taking a position for each specific market. [Learn more](https://www.freqtrade.io/en/latest/edge/).
|
||||||
- [x] **Edge position sizing** Calculate your win rate, risk reward ratio, the best stoploss and adjust your position size before taking a position for each specific market. [Learn more](https://www.freqtrade.io/en/stable/edge/).
|
|
||||||
- [x] **Whitelist crypto-currencies**: Select which crypto-currency you want to trade or use dynamic whitelists.
|
- [x] **Whitelist crypto-currencies**: Select which crypto-currency you want to trade or use dynamic whitelists.
|
||||||
- [x] **Blacklist crypto-currencies**: Select which crypto-currency you want to avoid.
|
- [x] **Blacklist crypto-currencies**: Select which crypto-currency you want to avoid.
|
||||||
- [x] **Builtin WebUI**: Builtin web UI to manage your bot.
|
|
||||||
- [x] **Manageable via Telegram**: Manage the bot with Telegram.
|
- [x] **Manageable via Telegram**: Manage the bot with Telegram.
|
||||||
- [x] **Display profit/loss in fiat**: Display your profit/loss in fiat currency.
|
- [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.
|
- [x] **Performance status report**: Provide a performance status of your current trades.
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
Please refer to the [Docker Quickstart documentation](https://www.freqtrade.io/en/stable/docker_quickstart/) on how to get started quickly.
|
Freqtrade provides a Linux/macOS script to install all dependencies and help you to configure the bot.
|
||||||
|
|
||||||
For further (native) installation methods, please refer to the [Installation documentation page](https://www.freqtrade.io/en/stable/installation/).
|
```bash
|
||||||
|
git clone -b develop https://github.com/freqtrade/freqtrade.git
|
||||||
|
cd freqtrade
|
||||||
|
./setup.sh --install
|
||||||
|
```
|
||||||
|
|
||||||
|
For any other type of installation please refer to [Installation doc](https://www.freqtrade.io/en/latest/installation/).
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
@ -85,22 +77,22 @@ For further (native) installation methods, please refer to the [Installation doc
|
|||||||
|
|
||||||
```
|
```
|
||||||
usage: freqtrade [-h] [-V]
|
usage: freqtrade [-h] [-V]
|
||||||
{trade,create-userdir,new-config,new-strategy,download-data,convert-data,convert-trade-data,list-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,install-ui,plot-dataframe,plot-profit,webserver}
|
{trade,create-userdir,new-config,new-hyperopt,new-strategy,download-data,convert-data,convert-trade-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,plot-dataframe,plot-profit}
|
||||||
...
|
...
|
||||||
|
|
||||||
Free, open source crypto trading bot
|
Free, open source crypto trading bot
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{trade,create-userdir,new-config,new-strategy,download-data,convert-data,convert-trade-data,list-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,install-ui,plot-dataframe,plot-profit,webserver}
|
{trade,create-userdir,new-config,new-hyperopt,new-strategy,download-data,convert-data,convert-trade-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,plot-dataframe,plot-profit}
|
||||||
trade Trade module.
|
trade Trade module.
|
||||||
create-userdir Create user-data directory.
|
create-userdir Create user-data directory.
|
||||||
new-config Create new config
|
new-config Create new config
|
||||||
|
new-hyperopt Create new hyperopt
|
||||||
new-strategy Create new strategy
|
new-strategy Create new strategy
|
||||||
download-data Download backtesting data.
|
download-data Download backtesting data.
|
||||||
convert-data Convert candle (OHLCV) data from one format to
|
convert-data Convert candle (OHLCV) data from one format to
|
||||||
another.
|
another.
|
||||||
convert-trade-data Convert trade data from one format to another.
|
convert-trade-data Convert trade data from one format to another.
|
||||||
list-data List downloaded data.
|
|
||||||
backtesting Backtesting module.
|
backtesting Backtesting module.
|
||||||
edge Edge module.
|
edge Edge module.
|
||||||
hyperopt Hyperopt module.
|
hyperopt Hyperopt module.
|
||||||
@ -114,10 +106,8 @@ positional arguments:
|
|||||||
list-timeframes Print available timeframes for the exchange.
|
list-timeframes Print available timeframes for the exchange.
|
||||||
show-trades Show trades.
|
show-trades Show trades.
|
||||||
test-pairlist Test your pairlist configuration.
|
test-pairlist Test your pairlist configuration.
|
||||||
install-ui Install FreqUI
|
|
||||||
plot-dataframe Plot candles with indicators.
|
plot-dataframe Plot candles with indicators.
|
||||||
plot-profit Generate plot showing profits.
|
plot-profit Generate plot showing profits.
|
||||||
webserver Webserver module.
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
@ -127,15 +117,14 @@ optional arguments:
|
|||||||
|
|
||||||
### Telegram RPC commands
|
### Telegram RPC commands
|
||||||
|
|
||||||
Telegram is not mandatory. However, this is a great way to control your bot. More details and the full command list on the [documentation](https://www.freqtrade.io/en/latest/telegram-usage/)
|
Telegram is not mandatory. However, this is a great way to control your bot. More details and the full command list on our [documentation](https://www.freqtrade.io/en/latest/telegram-usage/)
|
||||||
|
|
||||||
- `/start`: Starts the trader.
|
- `/start`: Starts the trader.
|
||||||
- `/stop`: Stops the trader.
|
- `/stop`: Stops the trader.
|
||||||
- `/stopentry`: Stop entering new trades.
|
- `/stopbuy`: Stop entering new trades.
|
||||||
- `/status <trade_id>|[table]`: Lists all or specific open trades.
|
- `/status <trade_id>|[table]`: Lists all or specific open trades.
|
||||||
- `/profit [<n>]`: Lists cumulative profit from all finished trades, over the last n days.
|
- `/profit [<n>]`: Lists cumulative profit from all finished trades, over the last n days.
|
||||||
- `/forceexit <trade_id>|all`: Instantly exits the given trade (Ignoring `minimum_roi`).
|
- `/forcesell <trade_id>|all`: Instantly sells the given trade (Ignoring `minimum_roi`).
|
||||||
- `/fx <trade_id>|all`: Alias to `/forceexit`
|
|
||||||
- `/performance`: Show performance of each finished trade grouped by pair
|
- `/performance`: Show performance of each finished trade grouped by pair
|
||||||
- `/balance`: Show account balance per currency.
|
- `/balance`: Show account balance per currency.
|
||||||
- `/daily <n>`: Shows profit or loss per day, over the last n days.
|
- `/daily <n>`: Shows profit or loss per day, over the last n days.
|
||||||
@ -152,23 +141,23 @@ The project is currently setup in two main branches:
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
### Help / Discord
|
### Help / Discord / Slack
|
||||||
|
|
||||||
For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join the Freqtrade [discord server](https://discord.gg/p7nuUNVfP7).
|
For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join our slack channel.
|
||||||
|
|
||||||
|
Please check out our [discord server](https://discord.gg/p7nuUNVfP7).
|
||||||
|
|
||||||
|
You can also join our [Slack channel](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw).
|
||||||
|
|
||||||
### [Bugs / Issues](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue)
|
### [Bugs / Issues](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue)
|
||||||
|
|
||||||
If you discover a bug in the bot, please
|
If you discover a bug in the bot, please
|
||||||
[search the issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue)
|
[search our issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue)
|
||||||
first. If it hasn't been reported, please
|
first. If it hasn't been reported, please
|
||||||
[create a new issue](https://github.com/freqtrade/freqtrade/issues/new/choose) and
|
[create a new issue](https://github.com/freqtrade/freqtrade/issues/new/choose) and
|
||||||
ensure you follow the template guide so that the team can assist you as
|
ensure you follow the template guide so that our team can assist you as
|
||||||
quickly as possible.
|
quickly as possible.
|
||||||
|
|
||||||
For every [issue](https://github.com/freqtrade/freqtrade/issues/new/choose) created, kindly follow up and mark satisfaction or reminder to close issue when equilibrium ground is reached.
|
|
||||||
|
|
||||||
--Maintain github's [community policy](https://docs.github.com/en/site-policy/github-terms/github-community-code-of-conduct)--
|
|
||||||
|
|
||||||
### [Feature Requests](https://github.com/freqtrade/freqtrade/labels/enhancement)
|
### [Feature Requests](https://github.com/freqtrade/freqtrade/labels/enhancement)
|
||||||
|
|
||||||
Have you a great idea to improve the bot you want to share? Please,
|
Have you a great idea to improve the bot you want to share? Please,
|
||||||
@ -180,16 +169,16 @@ in the bug reports.
|
|||||||
|
|
||||||
### [Pull Requests](https://github.com/freqtrade/freqtrade/pulls)
|
### [Pull Requests](https://github.com/freqtrade/freqtrade/pulls)
|
||||||
|
|
||||||
Feel like the bot is missing a feature? We welcome your pull requests!
|
Feel like our bot is missing a feature? We welcome your pull requests!
|
||||||
|
|
||||||
Please read the
|
Please read our
|
||||||
[Contributing document](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md)
|
[Contributing document](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md)
|
||||||
to understand the requirements before sending your pull-requests.
|
to understand the requirements before sending your pull-requests.
|
||||||
|
|
||||||
Coding is not a necessity to contribute - maybe start with improving the documentation?
|
Coding is not a necessity to contribute - maybe start with improving our documentation?
|
||||||
Issues labeled [good first issue](https://github.com/freqtrade/freqtrade/labels/good%20first%20issue) can be good first contributions, and will help get you familiar with the codebase.
|
Issues labeled [good first issue](https://github.com/freqtrade/freqtrade/labels/good%20first%20issue) can be good first contributions, and will help get you familiar with the codebase.
|
||||||
|
|
||||||
**Note** before starting any major new feature work, *please open an issue describing what you are planning to do* or talk to us on [discord](https://discord.gg/p7nuUNVfP7) (please use the #dev channel for this). This will ensure that interested parties can give valuable feedback on the feature, and let others know that you are working on it.
|
**Note** before starting any major new feature work, *please open an issue describing what you are planning to do* or talk to us on [discord](https://discord.gg/p7nuUNVfP7) or [Slack](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw). This will ensure that interested parties can give valuable feedback on the feature, and let others know that you are working on it.
|
||||||
|
|
||||||
**Important:** Always create your PR against the `develop` branch, not `stable`.
|
**Important:** Always create your PR against the `develop` branch, not `stable`.
|
||||||
|
|
||||||
@ -199,7 +188,7 @@ Issues labeled [good first issue](https://github.com/freqtrade/freqtrade/labels/
|
|||||||
|
|
||||||
The clock must be accurate, synchronized to a NTP server very frequently to avoid problems with communication to the exchanges.
|
The clock must be accurate, synchronized to a NTP server very frequently to avoid problems with communication to the exchanges.
|
||||||
|
|
||||||
### Minimum hardware required
|
### Min hardware required
|
||||||
|
|
||||||
To run this bot we recommend you a cloud instance with a minimum of:
|
To run this bot we recommend you a cloud instance with a minimum of:
|
||||||
|
|
||||||
@ -207,7 +196,7 @@ To run this bot we recommend you a cloud instance with a minimum of:
|
|||||||
|
|
||||||
### Software requirements
|
### Software requirements
|
||||||
|
|
||||||
- [Python >= 3.8](http://docs.python-guide.org/en/latest/starting/installation/)
|
- [Python 3.7.x](http://docs.python-guide.org/en/latest/starting/installation/)
|
||||||
- [pip](https://pip.pypa.io/en/stable/installing/)
|
- [pip](https://pip.pypa.io/en/stable/installing/)
|
||||||
- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
||||||
- [TA-Lib](https://mrjbq7.github.io/ta-lib/install.html)
|
- [TA-Lib](https://mrjbq7.github.io/ta-lib/install.html)
|
||||||
|
BIN
build_helpers/TA_Lib-0.4.20-cp37-cp37m-win_amd64.whl
Normal file
BIN
build_helpers/TA_Lib-0.4.20-cp38-cp38-win_amd64.whl
Normal file
@ -4,31 +4,17 @@ else
|
|||||||
INSTALL_LOC=${1}
|
INSTALL_LOC=${1}
|
||||||
fi
|
fi
|
||||||
echo "Installing to ${INSTALL_LOC}"
|
echo "Installing to ${INSTALL_LOC}"
|
||||||
if [ -n "$2" ] || [ ! -f "${INSTALL_LOC}/lib/libta_lib.a" ]; then
|
if [ ! -f "${INSTALL_LOC}/lib/libta_lib.a" ]; then
|
||||||
tar zxvf ta-lib-0.4.0-src.tar.gz
|
tar zxvf ta-lib-0.4.0-src.tar.gz
|
||||||
cd ta-lib \
|
cd ta-lib \
|
||||||
&& sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h \
|
&& sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h \
|
||||||
&& curl 'https://raw.githubusercontent.com/gcc-mirror/gcc/master/config.guess' -o config.guess \
|
&& curl 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' -o config.guess \
|
||||||
&& curl 'https://raw.githubusercontent.com/gcc-mirror/gcc/master/config.sub' -o config.sub \
|
&& curl 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' -o config.sub \
|
||||||
&& ./configure --prefix=${INSTALL_LOC}/ \
|
&& ./configure --prefix=${INSTALL_LOC}/ \
|
||||||
&& make
|
&& make -j$(nproc) \
|
||||||
if [ $? -ne 0 ]; then
|
&& which sudo && sudo make install || make install \
|
||||||
echo "Failed building ta-lib."
|
&& cd ..
|
||||||
cd .. && rm -rf ./ta-lib/
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
which sudo && sudo make install || make install
|
|
||||||
if [ -x "$(command -v apt-get)" ]; then
|
|
||||||
echo "Updating library path using ldconfig"
|
|
||||||
sudo ldconfig
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Don't install with sudo
|
|
||||||
make install
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd .. && rm -rf ./ta-lib/
|
|
||||||
else
|
else
|
||||||
echo "TA-lib already installed, skipping installation"
|
echo "TA-lib already installed, skipping installation"
|
||||||
fi
|
fi
|
||||||
|
# && sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h \
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
# Downloads don't work automatically, since the URL is regenerated via javascript.
|
# Downloads don't work automatically, since the URL is regenerated via javascript.
|
||||||
# Downloaded from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
|
# Downloaded from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
|
||||||
|
|
||||||
python -m pip install --upgrade pip wheel
|
python -m pip install --upgrade pip
|
||||||
|
|
||||||
$pyv = python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"
|
$pyv = python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"
|
||||||
|
|
||||||
|
if ($pyv -eq '3.7') {
|
||||||
|
pip install build_helpers\TA_Lib-0.4.20-cp37-cp37m-win_amd64.whl
|
||||||
|
}
|
||||||
if ($pyv -eq '3.8') {
|
if ($pyv -eq '3.8') {
|
||||||
pip install build_helpers\TA_Lib-0.4.25-cp38-cp38-win_amd64.whl
|
pip install build_helpers\TA_Lib-0.4.20-cp38-cp38-win_amd64.whl
|
||||||
}
|
|
||||||
if ($pyv -eq '3.9') {
|
|
||||||
pip install build_helpers\TA_Lib-0.4.25-cp39-cp39-win_amd64.whl
|
|
||||||
}
|
|
||||||
if ($pyv -eq '3.10') {
|
|
||||||
pip install build_helpers\TA_Lib-0.4.25-cp310-cp310-win_amd64.whl
|
|
||||||
}
|
|
||||||
if ($pyv -eq '3.11') {
|
|
||||||
pip install build_helpers\TA_Lib-0.4.25-cp311-cp311-win_amd64.whl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pip install -r requirements-dev.txt
|
pip install -r requirements-dev.txt
|
||||||
pip install -e .
|
pip install -e .
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
# File used in CI to ensure pre-commit dependencies are kept uptodate.
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
|
||||||
pre_commit_file = Path('.pre-commit-config.yaml')
|
|
||||||
require_dev = Path('requirements-dev.txt')
|
|
||||||
require = Path('requirements.txt')
|
|
||||||
|
|
||||||
with require_dev.open('r') as rfile:
|
|
||||||
requirements = rfile.readlines()
|
|
||||||
|
|
||||||
with require.open('r') as rfile:
|
|
||||||
requirements.extend(rfile.readlines())
|
|
||||||
|
|
||||||
# Extract types only
|
|
||||||
type_reqs = [r.strip('\n') for r in requirements if r.startswith(
|
|
||||||
'types-') or r.startswith('SQLAlchemy')]
|
|
||||||
|
|
||||||
with pre_commit_file.open('r') as file:
|
|
||||||
f = yaml.load(file, Loader=yaml.FullLoader)
|
|
||||||
|
|
||||||
|
|
||||||
mypy_repo = [repo for repo in f['repos'] if repo['repo']
|
|
||||||
== 'https://github.com/pre-commit/mirrors-mypy']
|
|
||||||
|
|
||||||
hooks = mypy_repo[0]['hooks'][0]['additional_dependencies']
|
|
||||||
|
|
||||||
errors = []
|
|
||||||
for hook in hooks:
|
|
||||||
if hook not in type_reqs:
|
|
||||||
errors.append(f"{hook} is missing in requirements-dev.txt.")
|
|
||||||
|
|
||||||
for req in type_reqs:
|
|
||||||
if req not in hooks:
|
|
||||||
errors.append(f"{req} is missing in pre-config file.")
|
|
||||||
|
|
||||||
|
|
||||||
if errors:
|
|
||||||
for e in errors:
|
|
||||||
print(e)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
sys.exit(0)
|
|
@ -1,119 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Use BuildKit, otherwise building on ARM fails
|
|
||||||
export DOCKER_BUILDKIT=1
|
|
||||||
|
|
||||||
IMAGE_NAME=freqtradeorg/freqtrade
|
|
||||||
CACHE_IMAGE=freqtradeorg/freqtrade_cache
|
|
||||||
GHCR_IMAGE_NAME=ghcr.io/freqtrade/freqtrade
|
|
||||||
|
|
||||||
# Replace / with _ to create a valid tag
|
|
||||||
TAG=$(echo "${BRANCH_NAME}" | sed -e "s/\//_/g")
|
|
||||||
TAG_PLOT=${TAG}_plot
|
|
||||||
TAG_FREQAI=${TAG}_freqai
|
|
||||||
TAG_FREQAI_RL=${TAG_FREQAI}rl
|
|
||||||
TAG_FREQAI_TORCH=${TAG_FREQAI}torch
|
|
||||||
TAG_PI="${TAG}_pi"
|
|
||||||
|
|
||||||
TAG_ARM=${TAG}_arm
|
|
||||||
TAG_PLOT_ARM=${TAG_PLOT}_arm
|
|
||||||
TAG_FREQAI_ARM=${TAG_FREQAI}_arm
|
|
||||||
TAG_FREQAI_RL_ARM=${TAG_FREQAI_RL}_arm
|
|
||||||
|
|
||||||
echo "Running for ${TAG}"
|
|
||||||
|
|
||||||
# Add commit and commit_message to docker container
|
|
||||||
echo "${GITHUB_SHA}" > freqtrade_commit
|
|
||||||
|
|
||||||
if [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then
|
|
||||||
echo "event ${GITHUB_EVENT_NAME}: full rebuild - skipping cache"
|
|
||||||
# Build regular image
|
|
||||||
docker build -t freqtrade:${TAG_ARM} .
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "event ${GITHUB_EVENT_NAME}: building with cache"
|
|
||||||
# Build regular image
|
|
||||||
docker pull ${IMAGE_NAME}:${TAG_ARM}
|
|
||||||
docker build --cache-from ${IMAGE_NAME}:${TAG_ARM} -t freqtrade:${TAG_ARM} .
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "failed building multiarch images"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG_ARM} -t freqtrade:${TAG_PLOT_ARM} -f docker/Dockerfile.plot .
|
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG_ARM} -t freqtrade:${TAG_FREQAI_ARM} -f docker/Dockerfile.freqai .
|
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG_FREQAI_ARM} -t freqtrade:${TAG_FREQAI_RL_ARM} -f docker/Dockerfile.freqai_rl .
|
|
||||||
|
|
||||||
# Tag image for upload and next build step
|
|
||||||
docker tag freqtrade:$TAG_ARM ${CACHE_IMAGE}:$TAG_ARM
|
|
||||||
docker tag freqtrade:$TAG_PLOT_ARM ${CACHE_IMAGE}:$TAG_PLOT_ARM
|
|
||||||
docker tag freqtrade:$TAG_FREQAI_ARM ${CACHE_IMAGE}:$TAG_FREQAI_ARM
|
|
||||||
docker tag freqtrade:$TAG_FREQAI_RL_ARM ${CACHE_IMAGE}:$TAG_FREQAI_RL_ARM
|
|
||||||
|
|
||||||
# Run backtest
|
|
||||||
docker run --rm -v $(pwd)/config_examples/config_bittrex.example.json:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG_ARM} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy StrategyTestV3
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "failed running backtest"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker images
|
|
||||||
|
|
||||||
docker push ${CACHE_IMAGE}:$TAG_PLOT_ARM
|
|
||||||
docker push ${CACHE_IMAGE}:$TAG_FREQAI_ARM
|
|
||||||
docker push ${CACHE_IMAGE}:$TAG_FREQAI_RL_ARM
|
|
||||||
docker push ${CACHE_IMAGE}:$TAG_ARM
|
|
||||||
|
|
||||||
# Create multi-arch image
|
|
||||||
# Make sure that all images contained here are pushed to github first.
|
|
||||||
# Otherwise installation might fail.
|
|
||||||
echo "create manifests"
|
|
||||||
|
|
||||||
docker manifest create ${IMAGE_NAME}:${TAG} ${CACHE_IMAGE}:${TAG} ${CACHE_IMAGE}:${TAG_ARM} ${IMAGE_NAME}:${TAG_PI}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:${TAG}
|
|
||||||
|
|
||||||
docker manifest create ${IMAGE_NAME}:${TAG_PLOT} ${CACHE_IMAGE}:${TAG_PLOT} ${CACHE_IMAGE}:${TAG_PLOT_ARM}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:${TAG_PLOT}
|
|
||||||
|
|
||||||
docker manifest create ${IMAGE_NAME}:${TAG_FREQAI} ${CACHE_IMAGE}:${TAG_FREQAI} ${CACHE_IMAGE}:${TAG_FREQAI_ARM}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:${TAG_FREQAI}
|
|
||||||
|
|
||||||
docker manifest create ${IMAGE_NAME}:${TAG_FREQAI_RL} ${CACHE_IMAGE}:${TAG_FREQAI_RL} ${CACHE_IMAGE}:${TAG_FREQAI_RL_ARM}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:${TAG_FREQAI_RL}
|
|
||||||
|
|
||||||
# Create special Torch tag - which is identical to the RL tag.
|
|
||||||
docker manifest create ${IMAGE_NAME}:${TAG_FREQAI_TORCH} ${CACHE_IMAGE}:${TAG_FREQAI_RL} ${CACHE_IMAGE}:${TAG_FREQAI_RL_ARM}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:${TAG_FREQAI_TORCH}
|
|
||||||
|
|
||||||
# copy images to ghcr.io
|
|
||||||
|
|
||||||
alias crane="docker run --rm -i -v $(pwd)/.crane:/home/nonroot/.docker/ gcr.io/go-containerregistry/crane"
|
|
||||||
mkdir .crane
|
|
||||||
chmod a+rwx .crane
|
|
||||||
|
|
||||||
echo "${GHCR_TOKEN}" | crane auth login ghcr.io -u "${GHCR_USERNAME}" --password-stdin
|
|
||||||
|
|
||||||
crane copy ${IMAGE_NAME}:${TAG_FREQAI_RL} ${GHCR_IMAGE_NAME}:${TAG_FREQAI_RL}
|
|
||||||
crane copy ${IMAGE_NAME}:${TAG_FREQAI_RL} ${GHCR_IMAGE_NAME}:${TAG_FREQAI_TORCH}
|
|
||||||
crane copy ${IMAGE_NAME}:${TAG_FREQAI} ${GHCR_IMAGE_NAME}:${TAG_FREQAI}
|
|
||||||
crane copy ${IMAGE_NAME}:${TAG_PLOT} ${GHCR_IMAGE_NAME}:${TAG_PLOT}
|
|
||||||
crane copy ${IMAGE_NAME}:${TAG} ${GHCR_IMAGE_NAME}:${TAG}
|
|
||||||
|
|
||||||
# Tag as latest for develop builds
|
|
||||||
if [ "${TAG}" = "develop" ]; then
|
|
||||||
echo 'Tagging image as latest'
|
|
||||||
docker manifest create ${IMAGE_NAME}:latest ${CACHE_IMAGE}:${TAG_ARM} ${IMAGE_NAME}:${TAG_PI} ${CACHE_IMAGE}:${TAG}
|
|
||||||
docker manifest push -p ${IMAGE_NAME}:latest
|
|
||||||
|
|
||||||
crane copy ${IMAGE_NAME}:latest ${GHCR_IMAGE_NAME}:latest
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker images
|
|
||||||
rm -rf .crane
|
|
||||||
|
|
||||||
# Cleanup old images from arm64 node.
|
|
||||||
docker image prune -a --force --filter "until=24h"
|
|
@ -2,18 +2,14 @@
|
|||||||
|
|
||||||
# The below assumes a correctly setup docker buildx environment
|
# The below assumes a correctly setup docker buildx environment
|
||||||
|
|
||||||
IMAGE_NAME=freqtradeorg/freqtrade
|
|
||||||
CACHE_IMAGE=freqtradeorg/freqtrade_cache
|
|
||||||
# Replace / with _ to create a valid tag
|
# Replace / with _ to create a valid tag
|
||||||
TAG=$(echo "${BRANCH_NAME}" | sed -e "s/\//_/g")
|
TAG=$(echo "${BRANCH_NAME}" | sed -e "s/\//_/g")
|
||||||
TAG_PLOT=${TAG}_plot
|
TAG_PLOT=${TAG}_plot
|
||||||
TAG_FREQAI=${TAG}_freqai
|
|
||||||
TAG_FREQAI_RL=${TAG_FREQAI}rl
|
|
||||||
TAG_PI="${TAG}_pi"
|
TAG_PI="${TAG}_pi"
|
||||||
|
|
||||||
PI_PLATFORM="linux/arm/v7"
|
PI_PLATFORM="linux/arm/v7"
|
||||||
echo "Running for ${TAG}"
|
echo "Running for ${TAG}"
|
||||||
CACHE_TAG=${CACHE_IMAGE}:${TAG_PI}_cache
|
CACHE_TAG=freqtradeorg/freqtrade_cache:${TAG}_cache
|
||||||
|
|
||||||
# Add commit and commit_message to docker container
|
# Add commit and commit_message to docker container
|
||||||
echo "${GITHUB_SHA}" > freqtrade_commit
|
echo "${GITHUB_SHA}" > freqtrade_commit
|
||||||
@ -27,10 +23,7 @@ if [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then
|
|||||||
--cache-to=type=registry,ref=${CACHE_TAG} \
|
--cache-to=type=registry,ref=${CACHE_TAG} \
|
||||||
-f docker/Dockerfile.armhf \
|
-f docker/Dockerfile.armhf \
|
||||||
--platform ${PI_PLATFORM} \
|
--platform ${PI_PLATFORM} \
|
||||||
-t ${IMAGE_NAME}:${TAG_PI} \
|
-t ${IMAGE_NAME}:${TAG_PI} --push .
|
||||||
--push \
|
|
||||||
--provenance=false \
|
|
||||||
.
|
|
||||||
else
|
else
|
||||||
echo "event ${GITHUB_EVENT_NAME}: building with cache"
|
echo "event ${GITHUB_EVENT_NAME}: building with cache"
|
||||||
# Build regular image
|
# Build regular image
|
||||||
@ -39,16 +32,12 @@ else
|
|||||||
|
|
||||||
# Pull last build to avoid rebuilding the whole image
|
# Pull last build to avoid rebuilding the whole image
|
||||||
# docker pull --platform ${PI_PLATFORM} ${IMAGE_NAME}:${TAG}
|
# docker pull --platform ${PI_PLATFORM} ${IMAGE_NAME}:${TAG}
|
||||||
# disable provenance due to https://github.com/docker/buildx/issues/1509
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--cache-from=type=registry,ref=${CACHE_TAG} \
|
--cache-from=type=registry,ref=${CACHE_TAG} \
|
||||||
--cache-to=type=registry,ref=${CACHE_TAG} \
|
--cache-to=type=registry,ref=${CACHE_TAG} \
|
||||||
-f docker/Dockerfile.armhf \
|
-f docker/Dockerfile.armhf \
|
||||||
--platform ${PI_PLATFORM} \
|
--platform ${PI_PLATFORM} \
|
||||||
-t ${IMAGE_NAME}:${TAG_PI} \
|
-t ${IMAGE_NAME}:${TAG_PI} --push .
|
||||||
--push \
|
|
||||||
--provenance=false \
|
|
||||||
.
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -56,18 +45,14 @@ if [ $? -ne 0 ]; then
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Tag image for upload and next build step
|
# Tag image for upload and next build step
|
||||||
docker tag freqtrade:$TAG ${CACHE_IMAGE}:$TAG
|
docker tag freqtrade:$TAG ${IMAGE_NAME}:$TAG
|
||||||
|
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG} -t freqtrade:${TAG_PLOT} -f docker/Dockerfile.plot .
|
docker build --cache-from freqtrade:${TAG} --build-arg sourceimage=${TAG} -t freqtrade:${TAG_PLOT} -f docker/Dockerfile.plot .
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG} -t freqtrade:${TAG_FREQAI} -f docker/Dockerfile.freqai .
|
|
||||||
docker build --build-arg sourceimage=freqtrade --build-arg sourcetag=${TAG_FREQAI} -t freqtrade:${TAG_FREQAI_RL} -f docker/Dockerfile.freqai_rl .
|
|
||||||
|
|
||||||
docker tag freqtrade:$TAG_PLOT ${CACHE_IMAGE}:$TAG_PLOT
|
docker tag freqtrade:$TAG_PLOT ${IMAGE_NAME}:$TAG_PLOT
|
||||||
docker tag freqtrade:$TAG_FREQAI ${CACHE_IMAGE}:$TAG_FREQAI
|
|
||||||
docker tag freqtrade:$TAG_FREQAI_RL ${CACHE_IMAGE}:$TAG_FREQAI_RL
|
|
||||||
|
|
||||||
# Run backtest
|
# Run backtest
|
||||||
docker run --rm -v $(pwd)/config_examples/config_bittrex.example.json:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy StrategyTestV3
|
docker run --rm -v $(pwd)/config_bittrex.json.example:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy DefaultStrategy
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "failed running backtest"
|
echo "failed running backtest"
|
||||||
@ -76,10 +61,23 @@ fi
|
|||||||
|
|
||||||
docker images
|
docker images
|
||||||
|
|
||||||
docker push ${CACHE_IMAGE}:$TAG
|
docker push ${IMAGE_NAME}
|
||||||
docker push ${CACHE_IMAGE}:$TAG_PLOT
|
docker push ${IMAGE_NAME}:$TAG_PLOT
|
||||||
docker push ${CACHE_IMAGE}:$TAG_FREQAI
|
docker push ${IMAGE_NAME}:$TAG
|
||||||
docker push ${CACHE_IMAGE}:$TAG_FREQAI_RL
|
|
||||||
|
# Create multiarch image
|
||||||
|
# Make sure that all images contained here are pushed to github first.
|
||||||
|
# Otherwise installation might fail.
|
||||||
|
|
||||||
|
docker manifest create freqtradeorg/freqtrade:${TAG} ${IMAGE_NAME}:${TAG} ${IMAGE_NAME}:${TAG_PI}
|
||||||
|
docker manifest push freqtradeorg/freqtrade:${TAG}
|
||||||
|
|
||||||
|
# Tag as latest for develop builds
|
||||||
|
if [ "${TAG}" = "develop" ]; then
|
||||||
|
docker manifest create freqtradeorg/freqtrade:latest ${IMAGE_NAME}:${TAG} ${IMAGE_NAME}:${TAG_PI}
|
||||||
|
docker manifest push freqtradeorg/freqtrade:latest
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
docker images
|
docker images
|
||||||
|
|
||||||
|
@ -8,32 +8,34 @@
|
|||||||
"dry_run": true,
|
"dry_run": true,
|
||||||
"cancel_open_orders_on_exit": false,
|
"cancel_open_orders_on_exit": false,
|
||||||
"unfilledtimeout": {
|
"unfilledtimeout": {
|
||||||
"entry": 10,
|
"buy": 10,
|
||||||
"exit": 10,
|
"sell": 30
|
||||||
"exit_timeout_count": 0,
|
|
||||||
"unit": "minutes"
|
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "same",
|
"ask_last_balance": 0.0,
|
||||||
"use_order_book": true,
|
"use_order_book": false,
|
||||||
"order_book_top": 1,
|
"order_book_top": 1,
|
||||||
"price_last_balance": 0.0,
|
|
||||||
"check_depth_of_market": {
|
"check_depth_of_market": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"bids_to_ask_delta": 1
|
"bids_to_ask_delta": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exit_pricing": {
|
"ask_strategy": {
|
||||||
"price_side": "same",
|
"use_order_book": false,
|
||||||
"use_order_book": true,
|
"order_book_min": 1,
|
||||||
"order_book_top": 1
|
"order_book_max": 1,
|
||||||
|
"use_sell_signal": true,
|
||||||
|
"sell_profit_only": false,
|
||||||
|
"ignore_roi_if_buy_signal": false
|
||||||
},
|
},
|
||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "binance",
|
"name": "binance",
|
||||||
"key": "your_exchange_key",
|
"key": "your_exchange_key",
|
||||||
"secret": "your_exchange_secret",
|
"secret": "your_exchange_secret",
|
||||||
"ccxt_config": {},
|
"ccxt_config": {"enableRateLimit": true},
|
||||||
"ccxt_async_config": {
|
"ccxt_async_config": {
|
||||||
|
"enableRateLimit": true,
|
||||||
|
"rateLimit": 200
|
||||||
},
|
},
|
||||||
"pair_whitelist": [
|
"pair_whitelist": [
|
||||||
"ALGO/BTC",
|
"ALGO/BTC",
|
||||||
@ -53,12 +55,26 @@
|
|||||||
"XTZ/BTC"
|
"XTZ/BTC"
|
||||||
],
|
],
|
||||||
"pair_blacklist": [
|
"pair_blacklist": [
|
||||||
"BNB/.*"
|
"BNB/BTC"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"pairlists": [
|
"pairlists": [
|
||||||
{"method": "StaticPairList"}
|
{"method": "StaticPairList"}
|
||||||
],
|
],
|
||||||
|
"edge": {
|
||||||
|
"enabled": false,
|
||||||
|
"process_throttle_secs": 3600,
|
||||||
|
"calculate_since_number_of_days": 7,
|
||||||
|
"allowed_risk": 0.01,
|
||||||
|
"stoploss_range_min": -0.01,
|
||||||
|
"stoploss_range_max": -0.1,
|
||||||
|
"stoploss_range_step": -0.01,
|
||||||
|
"minimum_winrate": 0.60,
|
||||||
|
"minimum_expectancy": 0.20,
|
||||||
|
"min_trade_number": 10,
|
||||||
|
"max_trade_duration_minute": 1440,
|
||||||
|
"remove_pumps": false
|
||||||
|
},
|
||||||
"telegram": {
|
"telegram": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"token": "your_telegram_token",
|
"token": "your_telegram_token",
|
||||||
@ -76,7 +92,7 @@
|
|||||||
},
|
},
|
||||||
"bot_name": "freqtrade",
|
"bot_name": "freqtrade",
|
||||||
"initial_state": "running",
|
"initial_state": "running",
|
||||||
"force_entry_enable": false,
|
"forcebuy_enable": false,
|
||||||
"internals": {
|
"internals": {
|
||||||
"process_throttle_secs": 5
|
"process_throttle_secs": 5
|
||||||
}
|
}
|
@ -8,25 +8,25 @@
|
|||||||
"dry_run": true,
|
"dry_run": true,
|
||||||
"cancel_open_orders_on_exit": false,
|
"cancel_open_orders_on_exit": false,
|
||||||
"unfilledtimeout": {
|
"unfilledtimeout": {
|
||||||
"entry": 10,
|
"buy": 10,
|
||||||
"exit": 10,
|
"sell": 30
|
||||||
"exit_timeout_count": 0,
|
|
||||||
"unit": "minutes"
|
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "same",
|
"use_order_book": false,
|
||||||
"use_order_book": true,
|
"ask_last_balance": 0.0,
|
||||||
"order_book_top": 1,
|
"order_book_top": 1,
|
||||||
"price_last_balance": 0.0,
|
|
||||||
"check_depth_of_market": {
|
"check_depth_of_market": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"bids_to_ask_delta": 1
|
"bids_to_ask_delta": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exit_pricing":{
|
"ask_strategy":{
|
||||||
"price_side": "same",
|
"use_order_book": false,
|
||||||
"use_order_book": true,
|
"order_book_min": 1,
|
||||||
"order_book_top": 1
|
"order_book_max": 1,
|
||||||
|
"use_sell_signal": true,
|
||||||
|
"sell_profit_only": false,
|
||||||
|
"ignore_roi_if_buy_signal": false
|
||||||
},
|
},
|
||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "bittrex",
|
"name": "bittrex",
|
||||||
@ -56,6 +56,20 @@
|
|||||||
"pairlists": [
|
"pairlists": [
|
||||||
{"method": "StaticPairList"}
|
{"method": "StaticPairList"}
|
||||||
],
|
],
|
||||||
|
"edge": {
|
||||||
|
"enabled": false,
|
||||||
|
"process_throttle_secs": 3600,
|
||||||
|
"calculate_since_number_of_days": 7,
|
||||||
|
"allowed_risk": 0.01,
|
||||||
|
"stoploss_range_min": -0.01,
|
||||||
|
"stoploss_range_max": -0.1,
|
||||||
|
"stoploss_range_step": -0.01,
|
||||||
|
"minimum_winrate": 0.60,
|
||||||
|
"minimum_expectancy": 0.20,
|
||||||
|
"min_trade_number": 10,
|
||||||
|
"max_trade_duration_minute": 1440,
|
||||||
|
"remove_pumps": false
|
||||||
|
},
|
||||||
"telegram": {
|
"telegram": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"token": "your_telegram_token",
|
"token": "your_telegram_token",
|
||||||
@ -73,7 +87,7 @@
|
|||||||
},
|
},
|
||||||
"bot_name": "freqtrade",
|
"bot_name": "freqtrade",
|
||||||
"initial_state": "running",
|
"initial_state": "running",
|
||||||
"force_entry_enable": false,
|
"forcebuy_enable": false,
|
||||||
"internals": {
|
"internals": {
|
||||||
"process_throttle_secs": 5
|
"process_throttle_secs": 5
|
||||||
}
|
}
|
@ -1,90 +0,0 @@
|
|||||||
{
|
|
||||||
"trading_mode": "futures",
|
|
||||||
"margin_mode": "isolated",
|
|
||||||
"max_open_trades": 5,
|
|
||||||
"stake_currency": "USDT",
|
|
||||||
"stake_amount": 200,
|
|
||||||
"tradable_balance_ratio": 1,
|
|
||||||
"fiat_display_currency": "USD",
|
|
||||||
"dry_run": true,
|
|
||||||
"timeframe": "3m",
|
|
||||||
"dry_run_wallet": 1000,
|
|
||||||
"cancel_open_orders_on_exit": true,
|
|
||||||
"unfilledtimeout": {
|
|
||||||
"entry": 10,
|
|
||||||
"exit": 30
|
|
||||||
},
|
|
||||||
"exchange": {
|
|
||||||
"name": "binance",
|
|
||||||
"key": "",
|
|
||||||
"secret": "",
|
|
||||||
"ccxt_config": {},
|
|
||||||
"ccxt_async_config": {},
|
|
||||||
"pair_whitelist": [
|
|
||||||
"1INCH/USDT:USDT",
|
|
||||||
"ALGO/USDT:USDT"
|
|
||||||
],
|
|
||||||
"pair_blacklist": []
|
|
||||||
},
|
|
||||||
"entry_pricing": {
|
|
||||||
"price_side": "same",
|
|
||||||
"use_order_book": true,
|
|
||||||
"order_book_top": 1,
|
|
||||||
"price_last_balance": 0.0,
|
|
||||||
"check_depth_of_market": {
|
|
||||||
"enabled": false,
|
|
||||||
"bids_to_ask_delta": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exit_pricing": {
|
|
||||||
"price_side": "other",
|
|
||||||
"use_order_book": true,
|
|
||||||
"order_book_top": 1
|
|
||||||
},
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "StaticPairList"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"freqai": {
|
|
||||||
"enabled": true,
|
|
||||||
"purge_old_models": 2,
|
|
||||||
"train_period_days": 15,
|
|
||||||
"backtest_period_days": 7,
|
|
||||||
"live_retrain_hours": 0,
|
|
||||||
"identifier": "uniqe-id",
|
|
||||||
"feature_parameters": {
|
|
||||||
"include_timeframes": [
|
|
||||||
"3m",
|
|
||||||
"15m",
|
|
||||||
"1h"
|
|
||||||
],
|
|
||||||
"include_corr_pairlist": [
|
|
||||||
"BTC/USDT:USDT",
|
|
||||||
"ETH/USDT:USDT"
|
|
||||||
],
|
|
||||||
"label_period_candles": 20,
|
|
||||||
"include_shifted_candles": 2,
|
|
||||||
"DI_threshold": 0.9,
|
|
||||||
"weight_factor": 0.9,
|
|
||||||
"principal_component_analysis": false,
|
|
||||||
"use_SVM_to_remove_outliers": true,
|
|
||||||
"indicator_periods_candles": [
|
|
||||||
10,
|
|
||||||
20
|
|
||||||
],
|
|
||||||
"plot_feature_importances": 0
|
|
||||||
},
|
|
||||||
"data_split_parameters": {
|
|
||||||
"test_size": 0.33,
|
|
||||||
"random_state": 1
|
|
||||||
},
|
|
||||||
"model_training_parameters": {}
|
|
||||||
},
|
|
||||||
"bot_name": "",
|
|
||||||
"force_entry_enable": true,
|
|
||||||
"initial_state": "running",
|
|
||||||
"internals": {
|
|
||||||
"process_throttle_secs": 5
|
|
||||||
}
|
|
||||||
}
|
|
99
config_ftx.json.example
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
{
|
||||||
|
"max_open_trades": 3,
|
||||||
|
"stake_currency": "USD",
|
||||||
|
"stake_amount": 50,
|
||||||
|
"tradable_balance_ratio": 0.99,
|
||||||
|
"fiat_display_currency": "USD",
|
||||||
|
"timeframe": "5m",
|
||||||
|
"dry_run": true,
|
||||||
|
"cancel_open_orders_on_exit": false,
|
||||||
|
"unfilledtimeout": {
|
||||||
|
"buy": 10,
|
||||||
|
"sell": 30
|
||||||
|
},
|
||||||
|
"bid_strategy": {
|
||||||
|
"ask_last_balance": 0.0,
|
||||||
|
"use_order_book": false,
|
||||||
|
"order_book_top": 1,
|
||||||
|
"check_depth_of_market": {
|
||||||
|
"enabled": false,
|
||||||
|
"bids_to_ask_delta": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ask_strategy": {
|
||||||
|
"use_order_book": false,
|
||||||
|
"order_book_min": 1,
|
||||||
|
"order_book_max": 1,
|
||||||
|
"use_sell_signal": true,
|
||||||
|
"sell_profit_only": false,
|
||||||
|
"ignore_roi_if_buy_signal": false
|
||||||
|
},
|
||||||
|
"exchange": {
|
||||||
|
"name": "ftx",
|
||||||
|
"key": "your_exchange_key",
|
||||||
|
"secret": "your_exchange_secret",
|
||||||
|
"ccxt_config": {"enableRateLimit": true},
|
||||||
|
"ccxt_async_config": {
|
||||||
|
"enableRateLimit": true,
|
||||||
|
"rateLimit": 50
|
||||||
|
},
|
||||||
|
"pair_whitelist": [
|
||||||
|
"BTC/USD",
|
||||||
|
"ETH/USD",
|
||||||
|
"BNB/USD",
|
||||||
|
"USDT/USD",
|
||||||
|
"LTC/USD",
|
||||||
|
"SRM/USD",
|
||||||
|
"SXP/USD",
|
||||||
|
"XRP/USD",
|
||||||
|
"DOGE/USD",
|
||||||
|
"1INCH/USD",
|
||||||
|
"CHZ/USD",
|
||||||
|
"MATIC/USD",
|
||||||
|
"LINK/USD",
|
||||||
|
"OXY/USD",
|
||||||
|
"SUSHI/USD"
|
||||||
|
],
|
||||||
|
"pair_blacklist": [
|
||||||
|
"FTT/USD"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pairlists": [
|
||||||
|
{"method": "StaticPairList"}
|
||||||
|
],
|
||||||
|
"edge": {
|
||||||
|
"enabled": false,
|
||||||
|
"process_throttle_secs": 3600,
|
||||||
|
"calculate_since_number_of_days": 7,
|
||||||
|
"allowed_risk": 0.01,
|
||||||
|
"stoploss_range_min": -0.01,
|
||||||
|
"stoploss_range_max": -0.1,
|
||||||
|
"stoploss_range_step": -0.01,
|
||||||
|
"minimum_winrate": 0.60,
|
||||||
|
"minimum_expectancy": 0.20,
|
||||||
|
"min_trade_number": 10,
|
||||||
|
"max_trade_duration_minute": 1440,
|
||||||
|
"remove_pumps": false
|
||||||
|
},
|
||||||
|
"telegram": {
|
||||||
|
"enabled": false,
|
||||||
|
"token": "your_telegram_token",
|
||||||
|
"chat_id": "your_telegram_chat_id"
|
||||||
|
},
|
||||||
|
"api_server": {
|
||||||
|
"enabled": false,
|
||||||
|
"listen_ip_address": "127.0.0.1",
|
||||||
|
"listen_port": 8080,
|
||||||
|
"verbosity": "error",
|
||||||
|
"jwt_secret_key": "somethingrandom",
|
||||||
|
"CORS_origins": [],
|
||||||
|
"username": "freqtrader",
|
||||||
|
"password": "SuperSecurePassword"
|
||||||
|
},
|
||||||
|
"bot_name": "freqtrade",
|
||||||
|
"initial_state": "running",
|
||||||
|
"forcebuy_enable": false,
|
||||||
|
"internals": {
|
||||||
|
"process_throttle_secs": 5
|
||||||
|
}
|
||||||
|
}
|
@ -5,24 +5,15 @@
|
|||||||
"tradable_balance_ratio": 0.99,
|
"tradable_balance_ratio": 0.99,
|
||||||
"fiat_display_currency": "USD",
|
"fiat_display_currency": "USD",
|
||||||
"amount_reserve_percent": 0.05,
|
"amount_reserve_percent": 0.05,
|
||||||
"available_capital": 1000,
|
|
||||||
"amend_last_stake_amount": false,
|
"amend_last_stake_amount": false,
|
||||||
"last_stake_amount_min_ratio": 0.5,
|
"last_stake_amount_min_ratio": 0.5,
|
||||||
"dry_run": true,
|
"dry_run": true,
|
||||||
"dry_run_wallet": 1000,
|
|
||||||
"cancel_open_orders_on_exit": false,
|
"cancel_open_orders_on_exit": false,
|
||||||
"timeframe": "5m",
|
"timeframe": "5m",
|
||||||
"trailing_stop": false,
|
"trailing_stop": false,
|
||||||
"trailing_stop_positive": 0.005,
|
"trailing_stop_positive": 0.005,
|
||||||
"trailing_stop_positive_offset": 0.0051,
|
"trailing_stop_positive_offset": 0.0051,
|
||||||
"trailing_only_offset_is_reached": false,
|
"trailing_only_offset_is_reached": false,
|
||||||
"use_exit_signal": true,
|
|
||||||
"exit_profit_only": false,
|
|
||||||
"exit_profit_offset": 0.0,
|
|
||||||
"ignore_roi_if_entry_signal": false,
|
|
||||||
"ignore_buying_expired_candle_after": 300,
|
|
||||||
"trading_mode": "spot",
|
|
||||||
"margin_mode": "",
|
|
||||||
"minimal_roi": {
|
"minimal_roi": {
|
||||||
"40": 0.0,
|
"40": 0.0,
|
||||||
"30": 0.01,
|
"30": 0.01,
|
||||||
@ -31,42 +22,43 @@
|
|||||||
},
|
},
|
||||||
"stoploss": -0.10,
|
"stoploss": -0.10,
|
||||||
"unfilledtimeout": {
|
"unfilledtimeout": {
|
||||||
"entry": 10,
|
"buy": 10,
|
||||||
"exit": 10,
|
"sell": 30,
|
||||||
"exit_timeout_count": 0,
|
|
||||||
"unit": "minutes"
|
"unit": "minutes"
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "same",
|
"price_side": "bid",
|
||||||
"use_order_book": true,
|
"use_order_book": false,
|
||||||
|
"ask_last_balance": 0.0,
|
||||||
"order_book_top": 1,
|
"order_book_top": 1,
|
||||||
"price_last_balance": 0.0,
|
|
||||||
"check_depth_of_market": {
|
"check_depth_of_market": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"bids_to_ask_delta": 1
|
"bids_to_ask_delta": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exit_pricing":{
|
"ask_strategy":{
|
||||||
"price_side": "same",
|
"price_side": "ask",
|
||||||
"use_order_book": true,
|
"use_order_book": false,
|
||||||
"order_book_top": 1,
|
"order_book_min": 1,
|
||||||
"price_last_balance": 0.0
|
"order_book_max": 1,
|
||||||
|
"use_sell_signal": true,
|
||||||
|
"sell_profit_only": false,
|
||||||
|
"sell_profit_offset": 0.0,
|
||||||
|
"ignore_roi_if_buy_signal": false
|
||||||
},
|
},
|
||||||
"order_types": {
|
"order_types": {
|
||||||
"entry": "limit",
|
"buy": "limit",
|
||||||
"exit": "limit",
|
"sell": "limit",
|
||||||
"emergency_exit": "market",
|
"emergencysell": "market",
|
||||||
"force_exit": "market",
|
"forcesell": "market",
|
||||||
"force_entry": "market",
|
"forcebuy": "market",
|
||||||
"stoploss": "market",
|
"stoploss": "market",
|
||||||
"stoploss_on_exchange": false,
|
"stoploss_on_exchange": false,
|
||||||
"stoploss_price_type": "last",
|
"stoploss_on_exchange_interval": 60
|
||||||
"stoploss_on_exchange_interval": 60,
|
|
||||||
"stoploss_on_exchange_limit_ratio": 0.99
|
|
||||||
},
|
},
|
||||||
"order_time_in_force": {
|
"order_time_in_force": {
|
||||||
"entry": "GTC",
|
"buy": "gtc",
|
||||||
"exit": "GTC"
|
"sell": "gtc"
|
||||||
},
|
},
|
||||||
"pairlists": [
|
"pairlists": [
|
||||||
{"method": "StaticPairList"},
|
{"method": "StaticPairList"},
|
||||||
@ -87,16 +79,45 @@
|
|||||||
"refresh_period": 1440
|
"refresh_period": 1440
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"protections": [
|
||||||
|
{
|
||||||
|
"method": "StoplossGuard",
|
||||||
|
"lookback_period_candles": 60,
|
||||||
|
"trade_limit": 4,
|
||||||
|
"stop_duration_candles": 60,
|
||||||
|
"only_per_pair": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "CooldownPeriod",
|
||||||
|
"stop_duration_candles": 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "MaxDrawdown",
|
||||||
|
"lookback_period_candles": 200,
|
||||||
|
"trade_limit": 20,
|
||||||
|
"stop_duration_candles": 10,
|
||||||
|
"max_allowed_drawdown": 0.2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "LowProfitPairs",
|
||||||
|
"lookback_period_candles": 360,
|
||||||
|
"trade_limit": 1,
|
||||||
|
"stop_duration_candles": 2,
|
||||||
|
"required_profit": 0.02
|
||||||
|
}
|
||||||
|
],
|
||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "binance",
|
"name": "binance",
|
||||||
"sandbox": false,
|
"sandbox": false,
|
||||||
"key": "your_exchange_key",
|
"key": "your_exchange_key",
|
||||||
"secret": "your_exchange_secret",
|
"secret": "your_exchange_secret",
|
||||||
"password": "",
|
"password": "",
|
||||||
"log_responses": false,
|
"ccxt_config": {"enableRateLimit": true},
|
||||||
// "unknown_fee_rate": 1,
|
"ccxt_async_config": {
|
||||||
"ccxt_config": {},
|
"enableRateLimit": true,
|
||||||
"ccxt_async_config": {},
|
"rateLimit": 500,
|
||||||
|
"aiohttp_trust_env": false
|
||||||
|
},
|
||||||
"pair_whitelist": [
|
"pair_whitelist": [
|
||||||
"ALGO/BTC",
|
"ALGO/BTC",
|
||||||
"ATOM/BTC",
|
"ATOM/BTC",
|
||||||
@ -142,24 +163,21 @@
|
|||||||
"status": "on",
|
"status": "on",
|
||||||
"warning": "on",
|
"warning": "on",
|
||||||
"startup": "on",
|
"startup": "on",
|
||||||
"entry": "on",
|
"buy": "on",
|
||||||
"entry_fill": "on",
|
"buy_fill": "on",
|
||||||
"exit": {
|
"sell": {
|
||||||
"roi": "off",
|
"roi": "off",
|
||||||
"emergency_exit": "off",
|
"emergency_sell": "off",
|
||||||
"force_exit": "off",
|
"force_sell": "off",
|
||||||
"exit_signal": "off",
|
"sell_signal": "off",
|
||||||
"trailing_stop_loss": "off",
|
"trailing_stop_loss": "off",
|
||||||
"stop_loss": "off",
|
"stop_loss": "off",
|
||||||
"stoploss_on_exchange": "off",
|
"stoploss_on_exchange": "off",
|
||||||
"custom_exit": "off"
|
"custom_sell": "off"
|
||||||
},
|
},
|
||||||
"exit_fill": "on",
|
"sell_fill": "on",
|
||||||
"entry_cancel": "on",
|
"buy_cancel": "on",
|
||||||
"exit_cancel": "on",
|
"sell_cancel": "on"
|
||||||
"protection_trigger": "off",
|
|
||||||
"protection_trigger_global": "on",
|
|
||||||
"show_candle": "off"
|
|
||||||
},
|
},
|
||||||
"reload": true,
|
"reload": true,
|
||||||
"balance_dust_level": 0.01
|
"balance_dust_level": 0.01
|
||||||
@ -173,39 +191,19 @@
|
|||||||
"jwt_secret_key": "somethingrandom",
|
"jwt_secret_key": "somethingrandom",
|
||||||
"CORS_origins": [],
|
"CORS_origins": [],
|
||||||
"username": "freqtrader",
|
"username": "freqtrader",
|
||||||
"password": "SuperSecurePassword",
|
"password": "SuperSecurePassword"
|
||||||
"ws_token": "secret_ws_t0ken."
|
|
||||||
},
|
|
||||||
"external_message_consumer": {
|
|
||||||
"enabled": false,
|
|
||||||
"producers": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"host": "127.0.0.2",
|
|
||||||
"port": 8080,
|
|
||||||
"ws_token": "secret_ws_t0ken."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"wait_timeout": 300,
|
|
||||||
"ping_timeout": 10,
|
|
||||||
"sleep_time": 10,
|
|
||||||
"remove_entry_exit_signals": false,
|
|
||||||
"message_size_limit": 8
|
|
||||||
},
|
},
|
||||||
"bot_name": "freqtrade",
|
"bot_name": "freqtrade",
|
||||||
"db_url": "sqlite:///tradesv3.sqlite",
|
"db_url": "sqlite:///tradesv3.sqlite",
|
||||||
"initial_state": "running",
|
"initial_state": "running",
|
||||||
"force_entry_enable": false,
|
"forcebuy_enable": false,
|
||||||
"internals": {
|
"internals": {
|
||||||
"process_throttle_secs": 5,
|
"process_throttle_secs": 5,
|
||||||
"heartbeat_interval": 60
|
"heartbeat_interval": 60
|
||||||
},
|
},
|
||||||
"disable_dataframe_checks": false,
|
"disable_dataframe_checks": false,
|
||||||
"strategy": "SampleStrategy",
|
"strategy": "DefaultStrategy",
|
||||||
"strategy_path": "user_data/strategies/",
|
"strategy_path": "user_data/strategies/",
|
||||||
"recursive_strategy_search": false,
|
|
||||||
"add_config_files": [],
|
|
||||||
"reduce_df_footprint": false,
|
|
||||||
"dataformat_ohlcv": "json",
|
"dataformat_ohlcv": "json",
|
||||||
"dataformat_trades": "jsongz"
|
"dataformat_trades": "jsongz"
|
||||||
}
|
}
|
@ -8,32 +8,34 @@
|
|||||||
"dry_run": true,
|
"dry_run": true,
|
||||||
"cancel_open_orders_on_exit": false,
|
"cancel_open_orders_on_exit": false,
|
||||||
"unfilledtimeout": {
|
"unfilledtimeout": {
|
||||||
"entry": 10,
|
"buy": 10,
|
||||||
"exit": 10,
|
"sell": 30
|
||||||
"exit_timeout_count": 0,
|
|
||||||
"unit": "minutes"
|
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "same",
|
"use_order_book": false,
|
||||||
"use_order_book": true,
|
"ask_last_balance": 0.0,
|
||||||
"order_book_top": 1,
|
"order_book_top": 1,
|
||||||
"price_last_balance": 0.0,
|
|
||||||
"check_depth_of_market": {
|
"check_depth_of_market": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"bids_to_ask_delta": 1
|
"bids_to_ask_delta": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exit_pricing":{
|
"ask_strategy":{
|
||||||
"price_side": "same",
|
"use_order_book": false,
|
||||||
"use_order_book": true,
|
"order_book_min": 1,
|
||||||
"order_book_top": 1
|
"order_book_max": 1,
|
||||||
|
"use_sell_signal": true,
|
||||||
|
"sell_profit_only": false,
|
||||||
|
"ignore_roi_if_buy_signal": false
|
||||||
},
|
},
|
||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "kraken",
|
"name": "kraken",
|
||||||
"key": "your_exchange_key",
|
"key": "your_exchange_key",
|
||||||
"secret": "your_exchange_key",
|
"secret": "your_exchange_key",
|
||||||
"ccxt_config": {},
|
"ccxt_config": {"enableRateLimit": true},
|
||||||
"ccxt_async_config": {
|
"ccxt_async_config": {
|
||||||
|
"enableRateLimit": true,
|
||||||
|
"rateLimit": 1000
|
||||||
},
|
},
|
||||||
"pair_whitelist": [
|
"pair_whitelist": [
|
||||||
"ADA/EUR",
|
"ADA/EUR",
|
||||||
@ -64,6 +66,20 @@
|
|||||||
"pairlists": [
|
"pairlists": [
|
||||||
{"method": "StaticPairList"}
|
{"method": "StaticPairList"}
|
||||||
],
|
],
|
||||||
|
"edge": {
|
||||||
|
"enabled": false,
|
||||||
|
"process_throttle_secs": 3600,
|
||||||
|
"calculate_since_number_of_days": 7,
|
||||||
|
"allowed_risk": 0.01,
|
||||||
|
"stoploss_range_min": -0.01,
|
||||||
|
"stoploss_range_max": -0.1,
|
||||||
|
"stoploss_range_step": -0.01,
|
||||||
|
"minimum_winrate": 0.60,
|
||||||
|
"minimum_expectancy": 0.20,
|
||||||
|
"min_trade_number": 10,
|
||||||
|
"max_trade_duration_minute": 1440,
|
||||||
|
"remove_pumps": false
|
||||||
|
},
|
||||||
"telegram": {
|
"telegram": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"token": "your_telegram_token",
|
"token": "your_telegram_token",
|
||||||
@ -81,7 +97,7 @@
|
|||||||
},
|
},
|
||||||
"bot_name": "freqtrade",
|
"bot_name": "freqtrade",
|
||||||
"initial_state": "running",
|
"initial_state": "running",
|
||||||
"force_entry_enable": false,
|
"forcebuy_enable": false,
|
||||||
"internals": {
|
"internals": {
|
||||||
"process_throttle_secs": 5
|
"process_throttle_secs": 5
|
||||||
},
|
},
|
@ -15,10 +15,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- "./user_data:/freqtrade/user_data"
|
- "./user_data:/freqtrade/user_data"
|
||||||
# Expose api on port 8080 (localhost only)
|
# Expose api on port 8080 (localhost only)
|
||||||
# Please read the https://www.freqtrade.io/en/stable/rest-api/ documentation
|
# Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation
|
||||||
# before enabling this.
|
# before enabling this.
|
||||||
ports:
|
# ports:
|
||||||
- "127.0.0.1:8080:8080"
|
# - "127.0.0.1:8080:8080"
|
||||||
# Default command used when running `docker compose up`
|
# Default command used when running `docker compose up`
|
||||||
command: >
|
command: >
|
||||||
trade
|
trade
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.9.16-slim-bullseye as base
|
FROM python:3.7.10-slim-buster as base
|
||||||
|
|
||||||
# Setup env
|
# Setup env
|
||||||
ENV LANG C.UTF-8
|
ENV LANG C.UTF-8
|
||||||
@ -11,7 +11,7 @@ ENV FT_APP_ENV="docker"
|
|||||||
# Prepare environment
|
# Prepare environment
|
||||||
RUN mkdir /freqtrade \
|
RUN mkdir /freqtrade \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get -y install sudo libatlas3-base curl sqlite3 libhdf5-dev libutf8proc-dev libsnappy-dev \
|
&& apt-get -y install sudo libatlas3-base curl sqlite3 libhdf5-dev \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& useradd -u 1000 -G sudo -U -m ftuser \
|
&& useradd -u 1000 -G sudo -U -m ftuser \
|
||||||
&& chown ftuser:ftuser /freqtrade \
|
&& chown ftuser:ftuser /freqtrade \
|
||||||
@ -37,7 +37,6 @@ ENV LD_LIBRARY_PATH /usr/local/lib
|
|||||||
COPY --chown=ftuser:ftuser requirements.txt /freqtrade/
|
COPY --chown=ftuser:ftuser requirements.txt /freqtrade/
|
||||||
USER ftuser
|
USER ftuser
|
||||||
RUN pip install --user --no-cache-dir numpy \
|
RUN pip install --user --no-cache-dir numpy \
|
||||||
&& pip install --user /tmp/pyarrow-*.whl \
|
|
||||||
&& pip install --user --no-cache-dir -r requirements.txt
|
&& pip install --user --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy dependencies to runtime-image
|
# Copy dependencies to runtime-image
|
||||||
|
@ -7,5 +7,4 @@ FROM freqtradeorg/freqtrade:develop
|
|||||||
# The below dependency - pyti - serves as an example. Please use whatever you need!
|
# The below dependency - pyti - serves as an example. Please use whatever you need!
|
||||||
RUN pip install --user pyti
|
RUN pip install --user pyti
|
||||||
|
|
||||||
# Switch back to user (only if you required root above)
|
|
||||||
# USER ftuser
|
# USER ftuser
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
ARG sourceimage=freqtradeorg/freqtrade
|
|
||||||
ARG sourcetag=develop
|
|
||||||
FROM ${sourceimage}:${sourcetag}
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
COPY requirements-freqai.txt /freqtrade/
|
|
||||||
|
|
||||||
RUN pip install -r requirements-freqai.txt --user --no-cache-dir
|
|
@ -1,8 +0,0 @@
|
|||||||
ARG sourceimage=freqtradeorg/freqtrade
|
|
||||||
ARG sourcetag=develop_freqai
|
|
||||||
FROM ${sourceimage}:${sourcetag}
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
COPY requirements-freqai.txt requirements-freqai-rl.txt /freqtrade/
|
|
||||||
|
|
||||||
RUN pip install -r requirements-freqai-rl.txt --user --no-cache-dir
|
|
@ -1,8 +1,7 @@
|
|||||||
FROM freqtradeorg/freqtrade:develop_plot
|
FROM freqtradeorg/freqtrade:develop_plot
|
||||||
|
|
||||||
|
|
||||||
# Pin jupyter-client to avoid tornado version conflict
|
RUN pip install jupyterlab --user --no-cache-dir
|
||||||
RUN pip install jupyterlab jupyter-client==7.3.4 --user --no-cache-dir
|
|
||||||
|
|
||||||
# Empty the ENTRYPOINT to allow all commands
|
# Empty the ENTRYPOINT to allow all commands
|
||||||
ENTRYPOINT []
|
ENTRYPOINT []
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
ARG sourceimage=freqtradeorg/freqtrade
|
ARG sourceimage=develop
|
||||||
ARG sourcetag=develop
|
FROM freqtradeorg/freqtrade:${sourceimage}
|
||||||
FROM ${sourceimage}:${sourcetag}
|
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
COPY requirements-plot.txt /freqtrade/
|
COPY requirements-plot.txt /freqtrade/
|
||||||
|
@ -10,7 +10,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8888:8888"
|
- "127.0.0.1:8888:8888"
|
||||||
volumes:
|
volumes:
|
||||||
- "../user_data:/freqtrade/user_data"
|
- "./user_data:/freqtrade/user_data"
|
||||||
# Default command used when running `docker compose up`
|
# Default command used when running `docker compose up`
|
||||||
command: >
|
command: >
|
||||||
jupyter lab --port=8888 --ip 0.0.0.0 --allow-root
|
jupyter lab --port=8888 --ip 0.0.0.0 --allow-root
|
||||||
|
@ -1,117 +0,0 @@
|
|||||||
# Advanced Backtesting Analysis
|
|
||||||
|
|
||||||
## Analyze the buy/entry and sell/exit tags
|
|
||||||
|
|
||||||
It can be helpful to understand how a strategy behaves according to the buy/entry tags used to
|
|
||||||
mark up different buy conditions. You might want to see more complex statistics about each buy and
|
|
||||||
sell condition above those provided by the default backtesting output. You may also want to
|
|
||||||
determine indicator values on the signal candle that resulted in a trade opening.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
The following buy reason analysis is only available for backtesting, *not hyperopt*.
|
|
||||||
|
|
||||||
We need to run backtesting with the `--export` option set to `signals` to enable the exporting of
|
|
||||||
signals **and** trades:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals
|
|
||||||
```
|
|
||||||
|
|
||||||
This will tell freqtrade to output a pickled dictionary of strategy, pairs and corresponding
|
|
||||||
DataFrame of the candles that resulted in buy signals. Depending on how many buys your strategy
|
|
||||||
makes, this file may get quite large, so periodically check your `user_data/backtest_results`
|
|
||||||
folder to delete old exports.
|
|
||||||
|
|
||||||
Before running your next backtest, make sure you either delete your old backtest results or run
|
|
||||||
backtesting with the `--cache none` option to make sure no cached results are used.
|
|
||||||
|
|
||||||
If all goes well, you should now see a `backtest-result-{timestamp}_signals.pkl` file in the
|
|
||||||
`user_data/backtest_results` folder.
|
|
||||||
|
|
||||||
To analyze the entry/exit tags, we now need to use the `freqtrade backtesting-analysis` command
|
|
||||||
with `--analysis-groups` option provided with space-separated arguments (default `0 1 2`):
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 1 2 3 4 5
|
|
||||||
```
|
|
||||||
|
|
||||||
This command will read from the last backtesting results. The `--analysis-groups` option is
|
|
||||||
used to specify the various tabular outputs showing the profit fo each group or trade,
|
|
||||||
ranging from the simplest (0) to the most detailed per pair, per buy and per sell tag (4):
|
|
||||||
|
|
||||||
* 1: profit summaries grouped by enter_tag
|
|
||||||
* 2: profit summaries grouped by enter_tag and exit_tag
|
|
||||||
* 3: profit summaries grouped by pair and enter_tag
|
|
||||||
* 4: profit summaries grouped by pair, enter_ and exit_tag (this can get quite large)
|
|
||||||
* 5: profit summaries grouped by exit_tag
|
|
||||||
|
|
||||||
More options are available by running with the `-h` option.
|
|
||||||
|
|
||||||
### Using export-filename
|
|
||||||
|
|
||||||
Normally, `backtesting-analysis` uses the latest backtest results, but if you wanted to go
|
|
||||||
back to a previous backtest output, you need to supply the `--export-filename` option.
|
|
||||||
You can supply the same parameter to `backtest-analysis` with the name of the final backtest
|
|
||||||
output file. This allows you to keep historical versions of backtest results and re-analyse
|
|
||||||
them at a later date:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals --export-filename=/tmp/mystrat_backtest.json
|
|
||||||
```
|
|
||||||
|
|
||||||
You should see some output similar to below in the logs with the name of the timestamped
|
|
||||||
filename that was exported:
|
|
||||||
|
|
||||||
```
|
|
||||||
2022-06-14 16:28:32,698 - freqtrade.misc - INFO - dumping json to "/tmp/mystrat_backtest-2022-06-14_16-28-32.json"
|
|
||||||
```
|
|
||||||
|
|
||||||
You can then use that filename in `backtesting-analysis`:
|
|
||||||
|
|
||||||
```
|
|
||||||
freqtrade backtesting-analysis -c <config.json> --export-filename=/tmp/mystrat_backtest-2022-06-14_16-28-32.json
|
|
||||||
```
|
|
||||||
|
|
||||||
### Tuning the buy tags and sell tags to display
|
|
||||||
|
|
||||||
To show only certain buy and sell tags in the displayed output, use the following two options:
|
|
||||||
|
|
||||||
```
|
|
||||||
--enter-reason-list : Space-separated list of enter signals to analyse. Default: "all"
|
|
||||||
--exit-reason-list : Space-separated list of exit signals to analyse. Default: "all"
|
|
||||||
```
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss
|
|
||||||
```
|
|
||||||
|
|
||||||
### Outputting signal candle indicators
|
|
||||||
|
|
||||||
The real power of `freqtrade backtesting-analysis` comes from the ability to print out the indicator
|
|
||||||
values present on signal candles to allow fine-grained investigation and tuning of buy signal
|
|
||||||
indicators. To print out a column for a given set of indicators, use the `--indicator-list`
|
|
||||||
option:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss --indicator-list rsi rsi_1h bb_lowerband ema_9 macd macdsignal
|
|
||||||
```
|
|
||||||
|
|
||||||
The indicators have to be present in your strategy's main DataFrame (either for your main
|
|
||||||
timeframe or for informative timeframes) otherwise they will simply be ignored in the script
|
|
||||||
output.
|
|
||||||
|
|
||||||
### Filtering the trade output by date
|
|
||||||
|
|
||||||
To show only trades between dates within your backtested timerange, supply the usual `timerange` option in `YYYYMMDD-[YYYYMMDD]` format:
|
|
||||||
|
|
||||||
```
|
|
||||||
--timerange : Timerange to filter output trades, start date inclusive, end date exclusive. e.g. 20220101-20221231
|
|
||||||
```
|
|
||||||
|
|
||||||
For example, if your backtest timerange was `20220101-20221231` but you only want to output trades in January:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade backtesting-analysis -c <config.json> --timerange 20220101-20220201
|
|
||||||
```
|
|
@ -13,11 +13,10 @@ A sample of this can be found below, which is identical to the Default Hyperopt
|
|||||||
|
|
||||||
``` python
|
``` python
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Dict
|
from typing import Dict
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
from freqtrade.constants import Config
|
|
||||||
from freqtrade.optimize.hyperopt import IHyperOptLoss
|
from freqtrade.optimize.hyperopt import IHyperOptLoss
|
||||||
|
|
||||||
TARGET_TRADES = 600
|
TARGET_TRADES = 600
|
||||||
@ -32,8 +31,7 @@ class SuperDuperHyperOptLoss(IHyperOptLoss):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def hyperopt_loss_function(results: DataFrame, trade_count: int,
|
def hyperopt_loss_function(results: DataFrame, trade_count: int,
|
||||||
min_date: datetime, max_date: datetime,
|
min_date: datetime, max_date: datetime,
|
||||||
config: Config, processed: Dict[str, DataFrame],
|
config: Dict, processed: Dict[str, DataFrame],
|
||||||
backtest_stats: Dict[str, Any],
|
|
||||||
*args, **kwargs) -> float:
|
*args, **kwargs) -> float:
|
||||||
"""
|
"""
|
||||||
Objective function, returns smaller number for better results
|
Objective function, returns smaller number for better results
|
||||||
@ -55,155 +53,35 @@ class SuperDuperHyperOptLoss(IHyperOptLoss):
|
|||||||
|
|
||||||
Currently, the arguments are:
|
Currently, the arguments are:
|
||||||
|
|
||||||
* `results`: DataFrame containing the resulting trades.
|
* `results`: DataFrame containing the result
|
||||||
The following columns are available in results (corresponds to the output-file of backtesting when used with `--export trades`):
|
The following columns are available in results (corresponds to the output-file of backtesting when used with `--export trades`):
|
||||||
`pair, profit_ratio, profit_abs, open_date, open_rate, fee_open, close_date, close_rate, fee_close, amount, trade_duration, is_open, exit_reason, stake_amount, min_rate, max_rate, stop_loss_ratio, stop_loss_abs`
|
`pair, profit_ratio, profit_abs, open_date, open_rate, fee_open, close_date, close_rate, fee_close, amount, trade_duration, is_open, sell_reason, stake_amount, min_rate, max_rate, stop_loss_ratio, stop_loss_abs`
|
||||||
* `trade_count`: Amount of trades (identical to `len(results)`)
|
* `trade_count`: Amount of trades (identical to `len(results)`)
|
||||||
* `min_date`: Start date of the timerange used
|
* `min_date`: Start date of the timerange used
|
||||||
* `min_date`: End date of the timerange used
|
* `min_date`: End date of the timerange used
|
||||||
* `config`: Config object used (Note: Not all strategy-related parameters will be updated here if they are part of a hyperopt space).
|
* `config`: Config object used (Note: Not all strategy-related parameters will be updated here if they are part of a hyperopt space).
|
||||||
* `processed`: Dict of Dataframes with the pair as keys containing the data used for backtesting.
|
* `processed`: Dict of Dataframes with the pair as keys containing the data used for backtesting.
|
||||||
* `backtest_stats`: Backtesting statistics using the same format as the backtesting file "strategy" substructure. Available fields can be seen in `generate_strategy_stats()` in `optimize_reports.py`.
|
|
||||||
|
|
||||||
This function needs to return a floating point number (`float`). Smaller numbers will be interpreted as better results. The parameters and balancing for this is up to you.
|
This function needs to return a floating point number (`float`). Smaller numbers will be interpreted as better results. The parameters and balancing for this is up to you.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
This function is called once per epoch - so please make sure to have this as optimized as possible to not slow hyperopt down unnecessarily.
|
This function is called once per iteration - so please make sure to have this as optimized as possible to not slow hyperopt down unnecessarily.
|
||||||
|
|
||||||
!!! Note "`*args` and `**kwargs`"
|
!!! Note
|
||||||
Please keep the arguments `*args` and `**kwargs` in the interface to allow us to extend this interface in the future.
|
Please keep the arguments `*args` and `**kwargs` in the interface to allow us to extend this interface later.
|
||||||
|
|
||||||
## Overriding pre-defined spaces
|
## Overriding pre-defined spaces
|
||||||
|
|
||||||
To override a pre-defined space (`roi_space`, `generate_roi_table`, `stoploss_space`, `trailing_space`, `max_open_trades_space`), define a nested class called Hyperopt and define the required spaces as follows:
|
To override a pre-defined space (`roi_space`, `generate_roi_table`, `stoploss_space`, `trailing_space`), define a nested class called Hyperopt and define the required spaces as follows:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal
|
|
||||||
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
class MyAwesomeStrategy(IStrategy):
|
||||||
class HyperOpt:
|
class HyperOpt:
|
||||||
# Define a custom stoploss space.
|
# Define a custom stoploss space.
|
||||||
def stoploss_space():
|
def stoploss_space(self):
|
||||||
return [SKDecimal(-0.05, -0.01, decimals=3, name='stoploss')]
|
return [SKDecimal(-0.05, -0.01, decimals=3, name='stoploss')]
|
||||||
|
|
||||||
# Define custom ROI space
|
|
||||||
def roi_space() -> List[Dimension]:
|
|
||||||
return [
|
|
||||||
Integer(10, 120, name='roi_t1'),
|
|
||||||
Integer(10, 60, name='roi_t2'),
|
|
||||||
Integer(10, 40, name='roi_t3'),
|
|
||||||
SKDecimal(0.01, 0.04, decimals=3, name='roi_p1'),
|
|
||||||
SKDecimal(0.01, 0.07, decimals=3, name='roi_p2'),
|
|
||||||
SKDecimal(0.01, 0.20, decimals=3, name='roi_p3'),
|
|
||||||
]
|
|
||||||
|
|
||||||
def generate_roi_table(params: Dict) -> Dict[int, float]:
|
|
||||||
|
|
||||||
roi_table = {}
|
|
||||||
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
|
||||||
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
|
|
||||||
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
|
|
||||||
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
|
|
||||||
|
|
||||||
return roi_table
|
|
||||||
|
|
||||||
def trailing_space() -> List[Dimension]:
|
|
||||||
# All parameters here are mandatory, you can only modify their type or the range.
|
|
||||||
return [
|
|
||||||
# Fixed to true, if optimizing trailing_stop we assume to use trailing stop at all times.
|
|
||||||
Categorical([True], name='trailing_stop'),
|
|
||||||
|
|
||||||
SKDecimal(0.01, 0.35, decimals=3, name='trailing_stop_positive'),
|
|
||||||
# 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',
|
|
||||||
# so this intermediate parameter is used as the value of the difference between
|
|
||||||
# them. The value of the 'trailing_stop_positive_offset' is constructed in the
|
|
||||||
# generate_trailing_params() method.
|
|
||||||
# This is similar to the hyperspace dimensions used for constructing the ROI tables.
|
|
||||||
SKDecimal(0.001, 0.1, decimals=3, name='trailing_stop_positive_offset_p1'),
|
|
||||||
|
|
||||||
Categorical([True, False], name='trailing_only_offset_is_reached'),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Define a custom max_open_trades space
|
|
||||||
def max_open_trades_space(self) -> List[Dimension]:
|
|
||||||
return [
|
|
||||||
Integer(-1, 10, name='max_open_trades'),
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
|
||||||
All overrides are optional and can be mixed/matched as necessary.
|
|
||||||
|
|
||||||
### Dynamic parameters
|
|
||||||
|
|
||||||
Parameters can also be defined dynamically, but must be available to the instance once the * [`bot_start()` callback](strategy-callbacks.md#bot-start) has been called.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
def bot_start(self, **kwargs) -> None:
|
|
||||||
self.buy_adx = IntParameter(20, 30, default=30, optimize=True)
|
|
||||||
|
|
||||||
# ...
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Parameters created this way will not show up in the `list-strategies` parameter count.
|
|
||||||
|
|
||||||
### Overriding Base estimator
|
|
||||||
|
|
||||||
You can define your own estimator for Hyperopt by implementing `generate_estimator()` in the Hyperopt subclass.
|
|
||||||
|
|
||||||
```python
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
class HyperOpt:
|
|
||||||
def generate_estimator(dimensions: List['Dimension'], **kwargs):
|
|
||||||
return "RF"
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Possible values are either one of "GP", "RF", "ET", "GBRT" (Details can be found in the [scikit-optimize documentation](https://scikit-optimize.github.io/)), or "an instance of a class that inherits from `RegressorMixin` (from sklearn) and where the `predict` method has an optional `return_std` argument, which returns `std(Y | x)` along with `E[Y | x]`".
|
|
||||||
|
|
||||||
Some research will be necessary to find additional Regressors.
|
|
||||||
|
|
||||||
Example for `ExtraTreesRegressor` ("ET") with additional parameters:
|
|
||||||
|
|
||||||
```python
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
class HyperOpt:
|
|
||||||
def generate_estimator(dimensions: List['Dimension'], **kwargs):
|
|
||||||
from skopt.learning import ExtraTreesRegressor
|
|
||||||
# Corresponds to "ET" - but allows additional parameters.
|
|
||||||
return ExtraTreesRegressor(n_estimators=100)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
The `dimensions` parameter is the list of `skopt.space.Dimension` objects corresponding to the parameters to be optimized. It can be used to create isotropic kernels for the `skopt.learning.GaussianProcessRegressor` estimator. Here's an example:
|
|
||||||
|
|
||||||
```python
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
class HyperOpt:
|
|
||||||
def generate_estimator(dimensions: List['Dimension'], **kwargs):
|
|
||||||
from skopt.utils import cook_estimator
|
|
||||||
from skopt.learning.gaussian_process.kernels import (Matern, ConstantKernel)
|
|
||||||
kernel_bounds = (0.0001, 10000)
|
|
||||||
kernel = (
|
|
||||||
ConstantKernel(1.0, kernel_bounds) *
|
|
||||||
Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=2.5)
|
|
||||||
)
|
|
||||||
kernel += (
|
|
||||||
ConstantKernel(1.0, kernel_bounds) *
|
|
||||||
Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=1.5)
|
|
||||||
)
|
|
||||||
|
|
||||||
return cook_estimator("GP", space=dimensions, kernel=kernel, n_restarts_optimizer=2)
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
While custom estimators can be provided, it's up to you as User to do research on possible parameters and analyze / understand which ones should be used.
|
|
||||||
If you're unsure about this, best use one of the Defaults (`"ET"` has proven to be the most versatile) without further parameters.
|
|
||||||
|
|
||||||
## Space options
|
## Space options
|
||||||
|
|
||||||
For the additional spaces, scikit-optimize (in combination with Freqtrade) provides the following space types:
|
For the additional spaces, scikit-optimize (in combination with Freqtrade) provides the following space types:
|
||||||
@ -225,3 +103,281 @@ from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal,
|
|||||||
Assuming the definition of a rather small space (`SKDecimal(0.10, 0.15, decimals=2, name='xxx')`) - SKDecimal will have 5 possibilities (`[0.10, 0.11, 0.12, 0.13, 0.14, 0.15]`).
|
Assuming the definition of a rather small space (`SKDecimal(0.10, 0.15, decimals=2, name='xxx')`) - SKDecimal will have 5 possibilities (`[0.10, 0.11, 0.12, 0.13, 0.14, 0.15]`).
|
||||||
|
|
||||||
A corresponding real space `Real(0.10, 0.15 name='xxx')` on the other hand has an almost unlimited number of possibilities (`[0.10, 0.010000000001, 0.010000000002, ... 0.014999999999, 0.01500000000]`).
|
A corresponding real space `Real(0.10, 0.15 name='xxx')` on the other hand has an almost unlimited number of possibilities (`[0.10, 0.010000000001, 0.010000000002, ... 0.014999999999, 0.01500000000]`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Legacy Hyperopt
|
||||||
|
|
||||||
|
This Section explains the configuration of an explicit Hyperopt file (separate to the strategy).
|
||||||
|
|
||||||
|
!!! Warning "Deprecated / legacy mode"
|
||||||
|
Since the 2021.4 release you no longer have to write a separate hyperopt class, but all strategies can be hyperopted.
|
||||||
|
Please read the [main hyperopt page](hyperopt.md) for more details.
|
||||||
|
|
||||||
|
### Prepare hyperopt file
|
||||||
|
|
||||||
|
Configuring an explicit hyperopt file is similar to writing your own strategy, and many tasks will be similar.
|
||||||
|
|
||||||
|
!!! Tip "About this page"
|
||||||
|
For this page, we will be using a fictional strategy called `AwesomeStrategy` - which will be optimized using the `AwesomeHyperopt` class.
|
||||||
|
|
||||||
|
#### Create a Custom Hyperopt File
|
||||||
|
|
||||||
|
The simplest way to get started is to use the following command, which will create a new hyperopt file from a template, which will be located under `user_data/hyperopts/AwesomeHyperopt.py`.
|
||||||
|
|
||||||
|
Let assume you want a hyperopt file `AwesomeHyperopt.py`:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
freqtrade new-hyperopt --hyperopt AwesomeHyperopt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Legacy Hyperopt checklist
|
||||||
|
|
||||||
|
Checklist on all tasks / possibilities in hyperopt
|
||||||
|
|
||||||
|
Depending on the space you want to optimize, only some of the below are required:
|
||||||
|
|
||||||
|
* fill `buy_strategy_generator` - for buy signal optimization
|
||||||
|
* fill `indicator_space` - for buy signal optimization
|
||||||
|
* fill `sell_strategy_generator` - for sell signal optimization
|
||||||
|
* fill `sell_indicator_space` - for sell signal optimization
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
`populate_indicators` needs to create all indicators any of thee spaces may use, otherwise hyperopt will not work.
|
||||||
|
|
||||||
|
Optional in hyperopt - can also be loaded from a strategy (recommended):
|
||||||
|
|
||||||
|
* `populate_indicators` - fallback to create indicators
|
||||||
|
* `populate_buy_trend` - fallback if not optimizing for buy space. should come from strategy
|
||||||
|
* `populate_sell_trend` - fallback if not optimizing for sell space. should come from strategy
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
You always have to provide a strategy to Hyperopt, even if your custom Hyperopt class contains all methods.
|
||||||
|
Assuming the optional methods are not in your hyperopt file, please use `--strategy AweSomeStrategy` which contains these methods so hyperopt can use these methods instead.
|
||||||
|
|
||||||
|
Rarely you may also need to override:
|
||||||
|
|
||||||
|
* `roi_space` - for custom ROI optimization (if you need the ranges for the ROI parameters in the optimization hyperspace that differ from default)
|
||||||
|
* `generate_roi_table` - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
|
||||||
|
* `stoploss_space` - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
|
||||||
|
* `trailing_space` - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
|
||||||
|
|
||||||
|
#### Defining a buy signal optimization
|
||||||
|
|
||||||
|
Let's say you are curious: should you use MACD crossings or lower Bollinger
|
||||||
|
Bands to trigger your buys. And you also wonder should you use RSI or ADX to
|
||||||
|
help with those buy decisions. If you decide to use RSI or ADX, which values
|
||||||
|
should I use for them? So let's use hyperparameter optimization to solve this
|
||||||
|
mystery.
|
||||||
|
|
||||||
|
We will start by defining a search space:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def indicator_space() -> List[Dimension]:
|
||||||
|
"""
|
||||||
|
Define your Hyperopt space for searching strategy parameters
|
||||||
|
"""
|
||||||
|
return [
|
||||||
|
Integer(20, 40, name='adx-value'),
|
||||||
|
Integer(20, 40, name='rsi-value'),
|
||||||
|
Categorical([True, False], name='adx-enabled'),
|
||||||
|
Categorical([True, False], name='rsi-enabled'),
|
||||||
|
Categorical(['bb_lower', 'macd_cross_signal'], name='trigger')
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Above definition says: I have five parameters I want you to randomly combine
|
||||||
|
to find the best combination. Two of them are integer values (`adx-value` and `rsi-value`) and I want you test in the range of values 20 to 40.
|
||||||
|
Then we have three category variables. First two are either `True` or `False`.
|
||||||
|
We use these to either enable or disable the ADX and RSI guards.
|
||||||
|
The last one we call `trigger` and use it to decide which buy trigger we want to use.
|
||||||
|
|
||||||
|
So let's write the buy strategy generator using these values:
|
||||||
|
|
||||||
|
```python
|
||||||
|
@staticmethod
|
||||||
|
def buy_strategy_generator(params: Dict[str, Any]) -> Callable:
|
||||||
|
"""
|
||||||
|
Define the buy strategy parameters to be used by Hyperopt.
|
||||||
|
"""
|
||||||
|
def populate_buy_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
conditions = []
|
||||||
|
# GUARDS AND TRENDS
|
||||||
|
if 'adx-enabled' in params and params['adx-enabled']:
|
||||||
|
conditions.append(dataframe['adx'] > params['adx-value'])
|
||||||
|
if 'rsi-enabled' in params and params['rsi-enabled']:
|
||||||
|
conditions.append(dataframe['rsi'] < params['rsi-value'])
|
||||||
|
|
||||||
|
# TRIGGERS
|
||||||
|
if 'trigger' in params:
|
||||||
|
if params['trigger'] == 'bb_lower':
|
||||||
|
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
|
||||||
|
if params['trigger'] == 'macd_cross_signal':
|
||||||
|
conditions.append(qtpylib.crossed_above(
|
||||||
|
dataframe['macd'], dataframe['macdsignal']
|
||||||
|
))
|
||||||
|
|
||||||
|
# Check that volume is not 0
|
||||||
|
conditions.append(dataframe['volume'] > 0)
|
||||||
|
|
||||||
|
if conditions:
|
||||||
|
dataframe.loc[
|
||||||
|
reduce(lambda x, y: x & y, conditions),
|
||||||
|
'buy'] = 1
|
||||||
|
|
||||||
|
return dataframe
|
||||||
|
|
||||||
|
return populate_buy_trend
|
||||||
|
```
|
||||||
|
|
||||||
|
Hyperopt will now call `populate_buy_trend()` many times (`epochs`) with different value combinations.
|
||||||
|
It will use the given historical data and make buys based on the buy signals generated with the above function.
|
||||||
|
Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured [loss function](#loss-functions)).
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
The above setup expects to find ADX, RSI and Bollinger Bands in the populated indicators.
|
||||||
|
When you want to test an indicator that isn't used by the bot currently, remember to
|
||||||
|
add it to the `populate_indicators()` method in your strategy or hyperopt file.
|
||||||
|
|
||||||
|
#### Sell optimization
|
||||||
|
|
||||||
|
Similar to the buy-signal above, sell-signals can also be optimized.
|
||||||
|
Place the corresponding settings into the following methods
|
||||||
|
|
||||||
|
* Inside `sell_indicator_space()` - the parameters hyperopt shall be optimizing.
|
||||||
|
* Within `sell_strategy_generator()` - populate the nested method `populate_sell_trend()` to apply the parameters.
|
||||||
|
|
||||||
|
The configuration and rules are the same than for buy signals.
|
||||||
|
To avoid naming collisions in the search-space, please prefix all sell-spaces with `sell-`.
|
||||||
|
|
||||||
|
### Execute Hyperopt
|
||||||
|
|
||||||
|
Once you have updated your hyperopt configuration you can run it.
|
||||||
|
Because hyperopt tries a lot of combinations to find the best parameters it will take time to get a good result. More time usually results in better results.
|
||||||
|
|
||||||
|
We strongly recommend to use `screen` or `tmux` to prevent any connection loss.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
freqtrade hyperopt --config config.json --hyperopt <hyperoptname> --hyperopt-loss <hyperoptlossname> --strategy <strategyname> -e 500 --spaces all
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `<hyperoptname>` as the name of the custom hyperopt used.
|
||||||
|
|
||||||
|
The `-e` option will set how many evaluations hyperopt will do. Since hyperopt uses Bayesian search, running too many epochs at once may not produce greater results. Experience has shown that best results are usually not improving much after 500-1000 epochs.
|
||||||
|
Doing multiple runs (executions) with a few 1000 epochs and different random state will most likely produce different results.
|
||||||
|
|
||||||
|
The `--spaces all` option determines that all possible parameters should be optimized. Possibilities are listed below.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Hyperopt will store hyperopt results with the timestamp of the hyperopt start time.
|
||||||
|
Reading commands (`hyperopt-list`, `hyperopt-show`) can use `--hyperopt-filename <filename>` to read and display older hyperopt results.
|
||||||
|
You can find a list of filenames with `ls -l user_data/hyperopt_results/`.
|
||||||
|
|
||||||
|
#### Running Hyperopt using methods from a strategy
|
||||||
|
|
||||||
|
Hyperopt can reuse `populate_indicators`, `populate_buy_trend`, `populate_sell_trend` from your strategy, assuming these methods are **not** in your custom hyperopt file, and a strategy is provided.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
freqtrade hyperopt --hyperopt AwesomeHyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy AwesomeStrategy
|
||||||
|
```
|
||||||
|
|
||||||
|
### Understand the Hyperopt Result
|
||||||
|
|
||||||
|
Once Hyperopt is completed you can use the result to create a new strategy.
|
||||||
|
Given the following result from hyperopt:
|
||||||
|
|
||||||
|
```
|
||||||
|
Best result:
|
||||||
|
|
||||||
|
44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367
|
||||||
|
|
||||||
|
Buy hyperspace params:
|
||||||
|
{ 'adx-value': 44,
|
||||||
|
'rsi-value': 29,
|
||||||
|
'adx-enabled': False,
|
||||||
|
'rsi-enabled': True,
|
||||||
|
'trigger': 'bb_lower'}
|
||||||
|
```
|
||||||
|
|
||||||
|
You should understand this result like:
|
||||||
|
|
||||||
|
* The buy trigger that worked best was `bb_lower`.
|
||||||
|
* You should not use ADX because `adx-enabled: False`)
|
||||||
|
* You should **consider** using the RSI indicator (`rsi-enabled: True` and the best value is `29.0` (`rsi-value: 29.0`)
|
||||||
|
|
||||||
|
You have to look inside your strategy file into `buy_strategy_generator()`
|
||||||
|
method, what those values match to.
|
||||||
|
|
||||||
|
So for example you had `rsi-value: 29.0` so we would look at `rsi`-block, that translates to the following code block:
|
||||||
|
|
||||||
|
```python
|
||||||
|
(dataframe['rsi'] < 29.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
Translating your whole hyperopt result as the new buy-signal would then look like:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
|
||||||
|
dataframe.loc[
|
||||||
|
(
|
||||||
|
(dataframe['rsi'] < 29.0) & # rsi-value
|
||||||
|
dataframe['close'] < dataframe['bb_lowerband'] # trigger
|
||||||
|
),
|
||||||
|
'buy'] = 1
|
||||||
|
return dataframe
|
||||||
|
```
|
||||||
|
|
||||||
|
### Validate backtesting results
|
||||||
|
|
||||||
|
Once the optimized parameters and conditions have been implemented into your strategy, you should backtest the strategy to make sure everything is working as expected.
|
||||||
|
|
||||||
|
To achieve same results (number of trades, their durations, profit, etc.) than during Hyperopt, please use same configuration and parameters (timerange, timeframe, ...) used for hyperopt `--dmmp`/`--disable-max-market-positions` and `--eps`/`--enable-position-stacking` for Backtesting.
|
||||||
|
|
||||||
|
Should results don't match, please double-check to make sure you transferred all conditions correctly.
|
||||||
|
Pay special care to the stoploss (and trailing stoploss) parameters, as these are often set in configuration files, which override changes to the strategy.
|
||||||
|
You should also carefully review the log of your backtest to ensure that there were no parameters inadvertently set by the configuration (like `stoploss` or `trailing_stop`).
|
||||||
|
|
||||||
|
### Sharing methods with your strategy
|
||||||
|
|
||||||
|
Hyperopt classes provide access to the Strategy via the `strategy` class attribute.
|
||||||
|
This can be a great way to reduce code duplication if used correctly, but will also complicate usage for inexperienced users.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from pandas import DataFrame
|
||||||
|
from freqtrade.strategy.interface import IStrategy
|
||||||
|
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||||
|
|
||||||
|
class MyAwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
buy_params = {
|
||||||
|
'rsi-value': 30,
|
||||||
|
'adx-value': 35,
|
||||||
|
}
|
||||||
|
|
||||||
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
return self.buy_strategy_generator(self.buy_params, dataframe, metadata)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def buy_strategy_generator(params, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
dataframe.loc[
|
||||||
|
(
|
||||||
|
qtpylib.crossed_above(dataframe['rsi'], params['rsi-value']) &
|
||||||
|
dataframe['adx'] > params['adx-value']) &
|
||||||
|
dataframe['volume'] > 0
|
||||||
|
)
|
||||||
|
, 'buy'] = 1
|
||||||
|
return dataframe
|
||||||
|
|
||||||
|
class MyAwesomeHyperOpt(IHyperOpt):
|
||||||
|
...
|
||||||
|
@staticmethod
|
||||||
|
def buy_strategy_generator(params: Dict[str, Any]) -> Callable:
|
||||||
|
"""
|
||||||
|
Define the buy strategy parameters to be used by Hyperopt.
|
||||||
|
"""
|
||||||
|
def populate_buy_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
# Call strategy's buy strategy generator
|
||||||
|
return self.StrategyClass.buy_strategy_generator(params, dataframe, metadata)
|
||||||
|
|
||||||
|
return populate_buy_trend
|
||||||
|
```
|
||||||
|
@ -52,71 +52,6 @@ freqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user
|
|||||||
|
|
||||||
For more information regarding usage of the sqlite databases, for example to manually enter or remove trades, please refer to the [SQL Cheatsheet](sql_cheatsheet.md).
|
For more information regarding usage of the sqlite databases, for example to manually enter or remove trades, please refer to the [SQL Cheatsheet](sql_cheatsheet.md).
|
||||||
|
|
||||||
### Multiple instances using docker
|
|
||||||
|
|
||||||
To run multiple instances of freqtrade using docker you will need to edit the docker-compose.yml file and add all the instances you want as separate services. Remember, you can separate your configuration into multiple files, so it's a good idea to think about making them modular, then if you need to edit something common to all bots, you can do that in a single config file.
|
|
||||||
``` yml
|
|
||||||
---
|
|
||||||
version: '3'
|
|
||||||
services:
|
|
||||||
freqtrade1:
|
|
||||||
image: freqtradeorg/freqtrade:stable
|
|
||||||
# image: freqtradeorg/freqtrade:develop
|
|
||||||
# Use plotting image
|
|
||||||
# image: freqtradeorg/freqtrade:develop_plot
|
|
||||||
# Build step - only needed when additional dependencies are needed
|
|
||||||
# build:
|
|
||||||
# context: .
|
|
||||||
# dockerfile: "./docker/Dockerfile.custom"
|
|
||||||
restart: always
|
|
||||||
container_name: freqtrade1
|
|
||||||
volumes:
|
|
||||||
- "./user_data:/freqtrade/user_data"
|
|
||||||
# Expose api on port 8080 (localhost only)
|
|
||||||
# Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation
|
|
||||||
# before enabling this.
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8080:8080"
|
|
||||||
# Default command used when running `docker compose up`
|
|
||||||
command: >
|
|
||||||
trade
|
|
||||||
--logfile /freqtrade/user_data/logs/freqtrade1.log
|
|
||||||
--db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade1.sqlite
|
|
||||||
--config /freqtrade/user_data/config.json
|
|
||||||
--config /freqtrade/user_data/config.freqtrade1.json
|
|
||||||
--strategy SampleStrategy
|
|
||||||
|
|
||||||
freqtrade2:
|
|
||||||
image: freqtradeorg/freqtrade:stable
|
|
||||||
# image: freqtradeorg/freqtrade:develop
|
|
||||||
# Use plotting image
|
|
||||||
# image: freqtradeorg/freqtrade:develop_plot
|
|
||||||
# Build step - only needed when additional dependencies are needed
|
|
||||||
# build:
|
|
||||||
# context: .
|
|
||||||
# dockerfile: "./docker/Dockerfile.custom"
|
|
||||||
restart: always
|
|
||||||
container_name: freqtrade2
|
|
||||||
volumes:
|
|
||||||
- "./user_data:/freqtrade/user_data"
|
|
||||||
# Expose api on port 8080 (localhost only)
|
|
||||||
# Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation
|
|
||||||
# before enabling this.
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8081:8080"
|
|
||||||
# Default command used when running `docker compose up`
|
|
||||||
command: >
|
|
||||||
trade
|
|
||||||
--logfile /freqtrade/user_data/logs/freqtrade2.log
|
|
||||||
--db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade2.sqlite
|
|
||||||
--config /freqtrade/user_data/config.json
|
|
||||||
--config /freqtrade/user_data/config.freqtrade2.json
|
|
||||||
--strategy SampleStrategy
|
|
||||||
|
|
||||||
```
|
|
||||||
You can use whatever naming convention you want, freqtrade1 and 2 are arbitrary. Note, that you will need to use different database files, port mappings and telegram configurations for each instance, as mentioned above.
|
|
||||||
|
|
||||||
|
|
||||||
## Configure the bot running as a systemd service
|
## Configure the bot running as a systemd service
|
||||||
|
|
||||||
Copy the `freqtrade.service` file to your systemd user directory (usually `~/.config/systemd/user`) and update `WorkingDirectory` and `ExecStart` to match your setup.
|
Copy the `freqtrade.service` file to your systemd user directory (usually `~/.config/systemd/user`) and update `WorkingDirectory` and `ExecStart` to match your setup.
|
||||||
@ -176,15 +111,12 @@ Log messages are send to `syslog` with the `user` facility. So you can see them
|
|||||||
On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
|
On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
|
||||||
|
|
||||||
For `rsyslog` the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add
|
For `rsyslog` the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add
|
||||||
|
|
||||||
```
|
```
|
||||||
if $programname startswith "freqtrade" then -/var/log/freqtrade.log
|
if $programname startswith "freqtrade" then -/var/log/freqtrade.log
|
||||||
```
|
```
|
||||||
|
|
||||||
to one of the rsyslog configuration files, for example at the end of the `/etc/rsyslog.d/50-default.conf`.
|
to one of the rsyslog configuration files, for example at the end of the `/etc/rsyslog.d/50-default.conf`.
|
||||||
|
|
||||||
For `syslog` (`rsyslog`), the reduction mode can be switched on. This will reduce the number of repeating messages. For instance, multiple bot Heartbeat messages will be reduced to a single message when nothing else happens with the bot. To achieve this, set in `/etc/rsyslog.conf`:
|
For `syslog` (`rsyslog`), the reduction mode can be switched on. This will reduce the number of repeating messages. For instance, multiple bot Heartbeat messages will be reduced to a single message when nothing else happens with the bot. To achieve this, set in `/etc/rsyslog.conf`:
|
||||||
|
|
||||||
```
|
```
|
||||||
# Filter duplicated messages
|
# Filter duplicated messages
|
||||||
$RepeatedMsgReduction on
|
$RepeatedMsgReduction on
|
||||||
@ -192,7 +124,7 @@ $RepeatedMsgReduction on
|
|||||||
|
|
||||||
### Logging to journald
|
### Logging to journald
|
||||||
|
|
||||||
This needs the `cysystemd` python package installed as dependency (`pip install cysystemd`), which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.
|
This needs the `systemd` python package installed as the dependency, which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.
|
||||||
|
|
||||||
To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:
|
To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 307 KiB |
Before Width: | Height: | Size: 345 KiB |
Before Width: | Height: | Size: 490 KiB |
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 2.0 MiB |
Before Width: | Height: | Size: 458 KiB |
Before Width: | Height: | Size: 270 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 185 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 121 KiB |
Before Width: | Height: | Size: 362 KiB |
Before Width: | Height: | Size: 92 KiB |
@ -18,22 +18,18 @@ usage: freqtrade backtesting [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
|||||||
[-p PAIRS [PAIRS ...]] [--eps] [--dmmp]
|
[-p PAIRS [PAIRS ...]] [--eps] [--dmmp]
|
||||||
[--enable-protections]
|
[--enable-protections]
|
||||||
[--dry-run-wallet DRY_RUN_WALLET]
|
[--dry-run-wallet DRY_RUN_WALLET]
|
||||||
[--timeframe-detail TIMEFRAME_DETAIL]
|
|
||||||
[--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]
|
[--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]
|
||||||
[--export {none,trades,signals}]
|
[--export {none,trades}] [--export-filename PATH]
|
||||||
[--export-filename PATH]
|
|
||||||
[--breakdown {day,week,month} [{day,week,month} ...]]
|
|
||||||
[--cache {none,day,week,month}]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-i TIMEFRAME, --timeframe TIMEFRAME
|
-i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
|
||||||
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
--data-format-ohlcv {json,jsongz,hdf5}
|
--data-format-ohlcv {json,jsongz,hdf5}
|
||||||
Storage format for downloaded candle (OHLCV) data.
|
Storage format for downloaded candle (OHLCV) data.
|
||||||
(default: `json`).
|
(default: `None`).
|
||||||
--max-open-trades INT
|
--max-open-trades INT
|
||||||
Override the value of the `max_open_trades`
|
Override the value of the `max_open_trades`
|
||||||
configuration setting.
|
configuration setting.
|
||||||
@ -59,27 +55,21 @@ optional arguments:
|
|||||||
--dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
|
--dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
|
||||||
Starting balance, used for backtesting / hyperopt and
|
Starting balance, used for backtesting / hyperopt and
|
||||||
dry-runs.
|
dry-runs.
|
||||||
--timeframe-detail TIMEFRAME_DETAIL
|
|
||||||
Specify detail timeframe for backtesting (`1m`, `5m`,
|
|
||||||
`30m`, `1h`, `1d`).
|
|
||||||
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
|
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
|
||||||
Provide a space-separated list of strategies to
|
Provide a space-separated list of strategies to
|
||||||
backtest. Please note that timeframe needs to be set
|
backtest. Please note that ticker-interval needs to be
|
||||||
either in config or via command line. When using this
|
set either in config or via command line. When using
|
||||||
together with `--export trades`, the strategy-name is
|
this together with `--export trades`, the strategy-
|
||||||
injected into the filename (so `backtest-data.json`
|
name is injected into the filename (so `backtest-
|
||||||
becomes `backtest-data-SampleStrategy.json`
|
data.json` becomes `backtest-data-
|
||||||
--export {none,trades,signals}
|
DefaultStrategy.json`
|
||||||
|
--export {none,trades}
|
||||||
Export backtest results (default: trades).
|
Export backtest results (default: trades).
|
||||||
--export-filename PATH, --backtest-filename PATH
|
--export-filename PATH
|
||||||
Use this filename for backtest results.Requires
|
Save backtest results to the file with this filename.
|
||||||
`--export` to be set as well. Example: `--export-filen
|
Requires `--export` to be set as well. Example:
|
||||||
ame=user_data/backtest_results/backtest_today.json`
|
`--export-filename=user_data/backtest_results/backtest
|
||||||
--breakdown {day,week,month} [{day,week,month} ...]
|
_today.json`
|
||||||
Show backtesting breakdown per [day, week, month].
|
|
||||||
--cache {none,day,week,month}
|
|
||||||
Load a cached backtest result no older than specified
|
|
||||||
age (default: day).
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -107,7 +97,7 @@ Strategy arguments:
|
|||||||
|
|
||||||
## Test your strategy with Backtesting
|
## Test your strategy with Backtesting
|
||||||
|
|
||||||
Now you have good Entry and exit strategies and some historic data, you want to test it against
|
Now you have good Buy and Sell strategies and some historic data, you want to test it against
|
||||||
real data. This is what we call [backtesting](https://en.wikipedia.org/wiki/Backtesting).
|
real data. This is what we call [backtesting](https://en.wikipedia.org/wiki/Backtesting).
|
||||||
|
|
||||||
Backtesting will use the crypto-currencies (pairs) from your config file and load historical candle (OHLCV) data from `user_data/data/<exchange>` by default.
|
Backtesting will use the crypto-currencies (pairs) from your config file and load historical candle (OHLCV) data from `user_data/data/<exchange>` by default.
|
||||||
@ -119,7 +109,7 @@ The result of backtesting will confirm if your bot has better odds of making a p
|
|||||||
All profit calculations include fees, and freqtrade will use the exchange's default fees for the calculation.
|
All profit calculations include fees, and freqtrade will use the exchange's default fees for the calculation.
|
||||||
|
|
||||||
!!! Warning "Using dynamic pairlists for backtesting"
|
!!! Warning "Using dynamic pairlists for backtesting"
|
||||||
Using dynamic pairlists is possible (not all of the handlers are allowed to be used in backtest mode), however it relies on the current market conditions - which will not reflect the historic status of the pairlist.
|
Using dynamic pairlists is possible, however it relies on the current market conditions - which will not reflect the historic status of the pairlist.
|
||||||
Also, when using pairlists other than StaticPairlist, reproducibility of backtesting-results cannot be guaranteed.
|
Also, when using pairlists other than StaticPairlist, reproducibility of backtesting-results cannot be guaranteed.
|
||||||
Please read the [pairlists documentation](plugins.md#pairlists) for more information.
|
Please read the [pairlists documentation](plugins.md#pairlists) for more information.
|
||||||
|
|
||||||
@ -215,7 +205,7 @@ Sometimes your account has certain fee rebates (fee reductions starting with a c
|
|||||||
To account for this in backtesting, you can use the `--fee` command line option to supply this value to backtesting.
|
To account for this in backtesting, you can use the `--fee` command line option to supply this value to backtesting.
|
||||||
This fee must be a ratio, and will be applied twice (once for trade entry, and once for trade exit).
|
This fee must be a ratio, and will be applied twice (once for trade entry, and once for trade exit).
|
||||||
|
|
||||||
For example, if the commission fee per order is 0.1% (i.e., 0.001 written as ratio), then you would run backtesting as the following:
|
For example, if the buying and selling commission fee is 0.1% (i.e., 0.001 written as ratio), then you would run backtesting as the following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
freqtrade backtesting --fee 0.001
|
freqtrade backtesting --fee 0.001
|
||||||
@ -252,95 +242,79 @@ The most important in the backtesting is to understand the result.
|
|||||||
A backtesting result will look like that:
|
A backtesting result will look like that:
|
||||||
|
|
||||||
```
|
```
|
||||||
========================================================= BACKTESTING REPORT =========================================================
|
========================================================= BACKTESTING REPORT ==========================================================
|
||||||
| Pair | Entries | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins Draws Loss Win% |
|
| Pair | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins Draws Loss Win% |
|
||||||
|:---------|--------:|---------------:|---------------:|-----------------:|---------------:|:-------------|-------------------------:|
|
|:---------|-------:|---------------:|---------------:|-----------------:|---------------:|:-------------|-------------------------:|
|
||||||
| ADA/BTC | 35 | -0.11 | -3.88 | -0.00019428 | -1.94 | 4:35:00 | 14 0 21 40.0 |
|
| ADA/BTC | 35 | -0.11 | -3.88 | -0.00019428 | -1.94 | 4:35:00 | 14 0 21 40.0 |
|
||||||
| ARK/BTC | 11 | -0.41 | -4.52 | -0.00022647 | -2.26 | 2:03:00 | 3 0 8 27.3 |
|
| ARK/BTC | 11 | -0.41 | -4.52 | -0.00022647 | -2.26 | 2:03:00 | 3 0 8 27.3 |
|
||||||
| BTS/BTC | 32 | 0.31 | 9.78 | 0.00048938 | 4.89 | 5:05:00 | 18 0 14 56.2 |
|
| BTS/BTC | 32 | 0.31 | 9.78 | 0.00048938 | 4.89 | 5:05:00 | 18 0 14 56.2 |
|
||||||
| DASH/BTC | 13 | -0.08 | -1.07 | -0.00005343 | -0.53 | 4:39:00 | 6 0 7 46.2 |
|
| DASH/BTC | 13 | -0.08 | -1.07 | -0.00005343 | -0.53 | 4:39:00 | 6 0 7 46.2 |
|
||||||
| ENG/BTC | 18 | 1.36 | 24.54 | 0.00122807 | 12.27 | 2:50:00 | 8 0 10 44.4 |
|
| ENG/BTC | 18 | 1.36 | 24.54 | 0.00122807 | 12.27 | 2:50:00 | 8 0 10 44.4 |
|
||||||
| EOS/BTC | 36 | 0.08 | 3.06 | 0.00015304 | 1.53 | 3:34:00 | 16 0 20 44.4 |
|
| EOS/BTC | 36 | 0.08 | 3.06 | 0.00015304 | 1.53 | 3:34:00 | 16 0 20 44.4 |
|
||||||
| ETC/BTC | 26 | 0.37 | 9.51 | 0.00047576 | 4.75 | 6:14:00 | 11 0 15 42.3 |
|
| ETC/BTC | 26 | 0.37 | 9.51 | 0.00047576 | 4.75 | 6:14:00 | 11 0 15 42.3 |
|
||||||
| ETH/BTC | 33 | 0.30 | 9.96 | 0.00049856 | 4.98 | 7:31:00 | 16 0 17 48.5 |
|
| ETH/BTC | 33 | 0.30 | 9.96 | 0.00049856 | 4.98 | 7:31:00 | 16 0 17 48.5 |
|
||||||
| IOTA/BTC | 32 | 0.03 | 1.09 | 0.00005444 | 0.54 | 3:12:00 | 14 0 18 43.8 |
|
| IOTA/BTC | 32 | 0.03 | 1.09 | 0.00005444 | 0.54 | 3:12:00 | 14 0 18 43.8 |
|
||||||
| LSK/BTC | 15 | 1.75 | 26.26 | 0.00131413 | 13.13 | 2:58:00 | 6 0 9 40.0 |
|
| LSK/BTC | 15 | 1.75 | 26.26 | 0.00131413 | 13.13 | 2:58:00 | 6 0 9 40.0 |
|
||||||
| LTC/BTC | 32 | -0.04 | -1.38 | -0.00006886 | -0.69 | 4:49:00 | 11 0 21 34.4 |
|
| LTC/BTC | 32 | -0.04 | -1.38 | -0.00006886 | -0.69 | 4:49:00 | 11 0 21 34.4 |
|
||||||
| NANO/BTC | 17 | 1.26 | 21.39 | 0.00107058 | 10.70 | 1:55:00 | 10 0 7 58.5 |
|
| NANO/BTC | 17 | 1.26 | 21.39 | 0.00107058 | 10.70 | 1:55:00 | 10 0 7 58.5 |
|
||||||
| NEO/BTC | 23 | 0.82 | 18.97 | 0.00094936 | 9.48 | 2:59:00 | 10 0 13 43.5 |
|
| NEO/BTC | 23 | 0.82 | 18.97 | 0.00094936 | 9.48 | 2:59:00 | 10 0 13 43.5 |
|
||||||
| REQ/BTC | 9 | 1.17 | 10.54 | 0.00052734 | 5.27 | 3:47:00 | 4 0 5 44.4 |
|
| REQ/BTC | 9 | 1.17 | 10.54 | 0.00052734 | 5.27 | 3:47:00 | 4 0 5 44.4 |
|
||||||
| XLM/BTC | 16 | 1.22 | 19.54 | 0.00097800 | 9.77 | 3:15:00 | 7 0 9 43.8 |
|
| XLM/BTC | 16 | 1.22 | 19.54 | 0.00097800 | 9.77 | 3:15:00 | 7 0 9 43.8 |
|
||||||
| XMR/BTC | 23 | -0.18 | -4.13 | -0.00020696 | -2.07 | 5:30:00 | 12 0 11 52.2 |
|
| XMR/BTC | 23 | -0.18 | -4.13 | -0.00020696 | -2.07 | 5:30:00 | 12 0 11 52.2 |
|
||||||
| XRP/BTC | 35 | 0.66 | 22.96 | 0.00114897 | 11.48 | 3:49:00 | 12 0 23 34.3 |
|
| XRP/BTC | 35 | 0.66 | 22.96 | 0.00114897 | 11.48 | 3:49:00 | 12 0 23 34.3 |
|
||||||
| ZEC/BTC | 22 | -0.46 | -10.18 | -0.00050971 | -5.09 | 2:22:00 | 7 0 15 31.8 |
|
| ZEC/BTC | 22 | -0.46 | -10.18 | -0.00050971 | -5.09 | 2:22:00 | 7 0 15 31.8 |
|
||||||
| TOTAL | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 0 243 43.4 |
|
| TOTAL | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 0 243 43.4 |
|
||||||
====================================================== LEFT OPEN TRADES REPORT ======================================================
|
========================================================= SELL REASON STATS ==========================================================
|
||||||
| Pair | Entries | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Win Draw Loss Win% |
|
| Sell Reason | Sells | Wins | Draws | Losses |
|
||||||
|:---------|---------:|---------------:|---------------:|-----------------:|---------------:|:---------------|--------------------:|
|
|
||||||
| ADA/BTC | 1 | 0.89 | 0.89 | 0.00004434 | 0.44 | 6:00:00 | 1 0 0 100 |
|
|
||||||
| LTC/BTC | 1 | 0.68 | 0.68 | 0.00003421 | 0.34 | 2:00:00 | 1 0 0 100 |
|
|
||||||
| TOTAL | 2 | 0.78 | 1.57 | 0.00007855 | 0.78 | 4:00:00 | 2 0 0 100 |
|
|
||||||
==================== EXIT REASON STATS ====================
|
|
||||||
| Exit Reason | Exits | Wins | Draws | Losses |
|
|
||||||
|:-------------------|--------:|------:|-------:|--------:|
|
|:-------------------|--------:|------:|-------:|--------:|
|
||||||
| trailing_stop_loss | 205 | 150 | 0 | 55 |
|
| trailing_stop_loss | 205 | 150 | 0 | 55 |
|
||||||
| stop_loss | 166 | 0 | 0 | 166 |
|
| stop_loss | 166 | 0 | 0 | 166 |
|
||||||
| exit_signal | 56 | 36 | 0 | 20 |
|
| sell_signal | 56 | 36 | 0 | 20 |
|
||||||
| force_exit | 2 | 0 | 0 | 2 |
|
| force_sell | 2 | 0 | 0 | 2 |
|
||||||
|
====================================================== LEFT OPEN TRADES REPORT ======================================================
|
||||||
================== SUMMARY METRICS ==================
|
| Pair | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Win Draw Loss Win% |
|
||||||
| Metric | Value |
|
|:---------|-------:|---------------:|---------------:|-----------------:|---------------:|:---------------|--------------------:|
|
||||||
|-----------------------------+---------------------|
|
| ADA/BTC | 1 | 0.89 | 0.89 | 0.00004434 | 0.44 | 6:00:00 | 1 0 0 100 |
|
||||||
| Backtesting from | 2019-01-01 00:00:00 |
|
| LTC/BTC | 1 | 0.68 | 0.68 | 0.00003421 | 0.34 | 2:00:00 | 1 0 0 100 |
|
||||||
| Backtesting to | 2019-05-01 00:00:00 |
|
| TOTAL | 2 | 0.78 | 1.57 | 0.00007855 | 0.78 | 4:00:00 | 2 0 0 100 |
|
||||||
| Max open trades | 3 |
|
=============== SUMMARY METRICS ===============
|
||||||
| | |
|
| Metric | Value |
|
||||||
| Total/Daily Avg Trades | 429 / 3.575 |
|
|-----------------------+---------------------|
|
||||||
| Starting balance | 0.01000000 BTC |
|
| Backtesting from | 2019-01-01 00:00:00 |
|
||||||
| Final balance | 0.01762792 BTC |
|
| Backtesting to | 2019-05-01 00:00:00 |
|
||||||
| Absolute profit | 0.00762792 BTC |
|
| Max open trades | 3 |
|
||||||
| Total profit % | 76.2% |
|
| | |
|
||||||
| CAGR % | 460.87% |
|
| Total/Daily Avg Trades| 429 / 3.575 |
|
||||||
| Sortino | 1.88 |
|
| Starting balance | 0.01000000 BTC |
|
||||||
| Sharpe | 2.97 |
|
| Final balance | 0.01762792 BTC |
|
||||||
| Calmar | 6.29 |
|
| Absolute profit | 0.00762792 BTC |
|
||||||
| Profit factor | 1.11 |
|
| Total profit % | 76.2% |
|
||||||
| Expectancy | -0.15 |
|
| Trades per day | 3.575 |
|
||||||
| Avg. stake amount | 0.001 BTC |
|
| Avg. stake amount | 0.001 BTC |
|
||||||
| Total trade volume | 0.429 BTC |
|
| Total trade volume | 0.429 BTC |
|
||||||
| | |
|
| | |
|
||||||
| Long / Short | 352 / 77 |
|
| Best Pair | LSK/BTC 26.26% |
|
||||||
| Total profit Long % | 1250.58% |
|
| Worst Pair | ZEC/BTC -10.18% |
|
||||||
| Total profit Short % | -15.02% |
|
| Best Trade | LSK/BTC 4.25% |
|
||||||
| Absolute profit Long | 0.00838792 BTC |
|
| Worst Trade | ZEC/BTC -10.25% |
|
||||||
| Absolute profit Short | -0.00076 BTC |
|
| Best day | 0.00076 BTC |
|
||||||
| | |
|
| Worst day | -0.00036 BTC |
|
||||||
| Best Pair | LSK/BTC 26.26% |
|
| Days win/draw/lose | 12 / 82 / 25 |
|
||||||
| Worst Pair | ZEC/BTC -10.18% |
|
| Avg. Duration Winners | 4:23:00 |
|
||||||
| Best Trade | LSK/BTC 4.25% |
|
| Avg. Duration Loser | 6:55:00 |
|
||||||
| Worst Trade | ZEC/BTC -10.25% |
|
| Zero Duration Trades | 4.6% (20) |
|
||||||
| Best day | 0.00076 BTC |
|
| Rejected Buy signals | 3089 |
|
||||||
| Worst day | -0.00036 BTC |
|
| | |
|
||||||
| Days win/draw/lose | 12 / 82 / 25 |
|
| Min balance | 0.00945123 BTC |
|
||||||
| Avg. Duration Winners | 4:23:00 |
|
| Max balance | 0.01846651 BTC |
|
||||||
| Avg. Duration Loser | 6:55:00 |
|
| Drawdown | 50.63% |
|
||||||
| Rejected Entry signals | 3089 |
|
| Drawdown | 0.0015 BTC |
|
||||||
| Entry/Exit Timeouts | 0 / 0 |
|
| Drawdown high | 0.0013 BTC |
|
||||||
| Canceled Trade Entries | 34 |
|
| Drawdown low | -0.0002 BTC |
|
||||||
| Canceled Entry Orders | 123 |
|
| Drawdown Start | 2019-02-15 14:10:00 |
|
||||||
| Replaced Entry Orders | 89 |
|
| Drawdown End | 2019-04-11 18:15:00 |
|
||||||
| | |
|
| Market change | -5.88% |
|
||||||
| Min balance | 0.00945123 BTC |
|
===============================================
|
||||||
| Max balance | 0.01846651 BTC |
|
|
||||||
| Max % of account underwater | 25.19% |
|
|
||||||
| Absolute Drawdown (Account) | 13.33% |
|
|
||||||
| Drawdown | 0.0015 BTC |
|
|
||||||
| Drawdown high | 0.0013 BTC |
|
|
||||||
| Drawdown low | -0.0002 BTC |
|
|
||||||
| Drawdown Start | 2019-02-15 14:10:00 |
|
|
||||||
| Drawdown End | 2019-04-11 18:15:00 |
|
|
||||||
| Market change | -5.88% |
|
|
||||||
=====================================================
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Backtesting report table
|
### Backtesting report table
|
||||||
@ -361,9 +335,9 @@ The column `Avg Profit %` shows the average profit for all trades made while the
|
|||||||
The column `Tot Profit %` shows instead the total profit % in relation to the starting balance.
|
The column `Tot Profit %` shows instead the total profit % in relation to the starting balance.
|
||||||
In the above results, we have a starting balance of 0.01 BTC and an absolute profit of 0.00762792 BTC - so the `Tot Profit %` will be `(0.00762792 / 0.01) * 100 ~= 76.2%`.
|
In the above results, we have a starting balance of 0.01 BTC and an absolute profit of 0.00762792 BTC - so the `Tot Profit %` will be `(0.00762792 / 0.01) * 100 ~= 76.2%`.
|
||||||
|
|
||||||
Your strategy performance is influenced by your entry strategy, your exit strategy, and also by the `minimal_roi` and `stop_loss` you have set.
|
Your strategy performance is influenced by your buy strategy, your sell strategy, and also by the `minimal_roi` and `stop_loss` you have set.
|
||||||
|
|
||||||
For example, if your `minimal_roi` is only `"0": 0.01` you cannot expect the bot to make more profit than 1% (because it will exit every time a trade reaches 1%).
|
For 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 reaches 1%).
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"minimal_roi": {
|
"minimal_roi": {
|
||||||
@ -375,14 +349,14 @@ On the other hand, if you set a too high `minimal_roi` like `"0": 0.55`
|
|||||||
(55%), there is almost no chance that the bot will ever reach this profit.
|
(55%), there is almost no chance that the bot will ever reach this profit.
|
||||||
Hence, keep in mind that your performance is an integral mix of all different elements of the strategy, your configuration, and the crypto-currency pairs you have set up.
|
Hence, keep in mind that your performance is an integral mix of all different elements of the strategy, your configuration, and the crypto-currency pairs you have set up.
|
||||||
|
|
||||||
### Exit reasons table
|
### Sell reasons table
|
||||||
|
|
||||||
The 2nd table contains a recap of exit reasons.
|
The 2nd table contains a recap of sell reasons.
|
||||||
This table can tell you which area needs some additional work (e.g. all or many of the `exit_signal` trades are losses, so you should work on improving the exit signal, or consider disabling it).
|
This table can tell you which area needs some additional work (e.g. all or many of the `sell_signal` trades are losses, so you should work on improving the sell signal, or consider disabling it).
|
||||||
|
|
||||||
### Left open trades table
|
### Left open trades table
|
||||||
|
|
||||||
The 3rd table contains all trades the bot had to `force_exit` at the end of the backtesting period to present you the full picture.
|
The 3rd table contains all trades the bot had to `forcesell` at the end of the backtesting period to present you the full picture.
|
||||||
This is necessary to simulate realistic behavior, since the backtest period has to end at some point, while realistically, you could leave the bot running forever.
|
This is necessary to simulate realistic behavior, since the backtest period has to end at some point, while realistically, you could leave the bot running forever.
|
||||||
These trades are also included in the first table, but are also shown separately in this table for clarity.
|
These trades are also included in the first table, but are also shown separately in this table for clarity.
|
||||||
|
|
||||||
@ -392,59 +366,43 @@ The last element of the backtest report is the summary metrics table.
|
|||||||
It contains some useful key metrics about performance of your strategy on backtesting data.
|
It contains some useful key metrics about performance of your strategy on backtesting data.
|
||||||
|
|
||||||
```
|
```
|
||||||
================== SUMMARY METRICS ==================
|
=============== SUMMARY METRICS ===============
|
||||||
| Metric | Value |
|
| Metric | Value |
|
||||||
|-----------------------------+---------------------|
|
|-----------------------+---------------------|
|
||||||
| Backtesting from | 2019-01-01 00:00:00 |
|
| Backtesting from | 2019-01-01 00:00:00 |
|
||||||
| Backtesting to | 2019-05-01 00:00:00 |
|
| Backtesting to | 2019-05-01 00:00:00 |
|
||||||
| Max open trades | 3 |
|
| Max open trades | 3 |
|
||||||
| | |
|
| | |
|
||||||
| Total/Daily Avg Trades | 429 / 3.575 |
|
| Total/Daily Avg Trades| 429 / 3.575 |
|
||||||
| Starting balance | 0.01000000 BTC |
|
| Starting balance | 0.01000000 BTC |
|
||||||
| Final balance | 0.01762792 BTC |
|
| Final balance | 0.01762792 BTC |
|
||||||
| Absolute profit | 0.00762792 BTC |
|
| Absolute profit | 0.00762792 BTC |
|
||||||
| Total profit % | 76.2% |
|
| Total profit % | 76.2% |
|
||||||
| CAGR % | 460.87% |
|
| Avg. stake amount | 0.001 BTC |
|
||||||
| Sortino | 1.88 |
|
| Total trade volume | 0.429 BTC |
|
||||||
| Sharpe | 2.97 |
|
| | |
|
||||||
| Calmar | 6.29 |
|
| Best Pair | LSK/BTC 26.26% |
|
||||||
| Profit factor | 1.11 |
|
| Worst Pair | ZEC/BTC -10.18% |
|
||||||
| Expectancy | -0.15 |
|
| Best Trade | LSK/BTC 4.25% |
|
||||||
| Avg. stake amount | 0.001 BTC |
|
| Worst Trade | ZEC/BTC -10.25% |
|
||||||
| Total trade volume | 0.429 BTC |
|
| Best day | 0.00076 BTC |
|
||||||
| | |
|
| Worst day | -0.00036 BTC |
|
||||||
| Long / Short | 352 / 77 |
|
| Days win/draw/lose | 12 / 82 / 25 |
|
||||||
| Total profit Long % | 1250.58% |
|
| Avg. Duration Winners | 4:23:00 |
|
||||||
| Total profit Short % | -15.02% |
|
| Avg. Duration Loser | 6:55:00 |
|
||||||
| Absolute profit Long | 0.00838792 BTC |
|
| Zero Duration Trades | 4.6% (20) |
|
||||||
| Absolute profit Short | -0.00076 BTC |
|
| Rejected Buy signals | 3089 |
|
||||||
| | |
|
| | |
|
||||||
| Best Pair | LSK/BTC 26.26% |
|
| Min balance | 0.00945123 BTC |
|
||||||
| Worst Pair | ZEC/BTC -10.18% |
|
| Max balance | 0.01846651 BTC |
|
||||||
| Best Trade | LSK/BTC 4.25% |
|
| Drawdown | 50.63% |
|
||||||
| Worst Trade | ZEC/BTC -10.25% |
|
| Drawdown | 0.0015 BTC |
|
||||||
| Best day | 0.00076 BTC |
|
| Drawdown high | 0.0013 BTC |
|
||||||
| Worst day | -0.00036 BTC |
|
| Drawdown low | -0.0002 BTC |
|
||||||
| Days win/draw/lose | 12 / 82 / 25 |
|
| Drawdown Start | 2019-02-15 14:10:00 |
|
||||||
| Avg. Duration Winners | 4:23:00 |
|
| Drawdown End | 2019-04-11 18:15:00 |
|
||||||
| Avg. Duration Loser | 6:55:00 |
|
| Market change | -5.88% |
|
||||||
| Rejected Entry signals | 3089 |
|
===============================================
|
||||||
| Entry/Exit Timeouts | 0 / 0 |
|
|
||||||
| Canceled Trade Entries | 34 |
|
|
||||||
| Canceled Entry Orders | 123 |
|
|
||||||
| Replaced Entry Orders | 89 |
|
|
||||||
| | |
|
|
||||||
| Min balance | 0.00945123 BTC |
|
|
||||||
| Max balance | 0.01846651 BTC |
|
|
||||||
| Max % of account underwater | 25.19% |
|
|
||||||
| Absolute Drawdown (Account) | 13.33% |
|
|
||||||
| Drawdown | 0.0015 BTC |
|
|
||||||
| Drawdown high | 0.0013 BTC |
|
|
||||||
| Drawdown low | -0.0002 BTC |
|
|
||||||
| Drawdown Start | 2019-02-15 14:10:00 |
|
|
||||||
| Drawdown End | 2019-04-11 18:15:00 |
|
|
||||||
| Market change | -5.88% |
|
|
||||||
=====================================================
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -455,11 +413,6 @@ It contains some useful key metrics about performance of your strategy on backte
|
|||||||
- `Final balance`: Final balance - starting balance + absolute profit.
|
- `Final balance`: Final balance - starting balance + absolute profit.
|
||||||
- `Absolute profit`: Profit made in stake currency.
|
- `Absolute profit`: Profit made in stake currency.
|
||||||
- `Total profit %`: Total profit. Aligned to the `TOTAL` row's `Tot Profit %` from the first table. Calculated as `(End capital − Starting capital) / Starting capital`.
|
- `Total profit %`: Total profit. Aligned to the `TOTAL` row's `Tot Profit %` from the first table. Calculated as `(End capital − Starting capital) / Starting capital`.
|
||||||
- `CAGR %`: Compound annual growth rate.
|
|
||||||
- `Sortino`: Annualized Sortino ratio.
|
|
||||||
- `Sharpe`: Annualized Sharpe ratio.
|
|
||||||
- `Calmar`: Annualized Calmar ratio.
|
|
||||||
- `Profit factor`: profit / loss.
|
|
||||||
- `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount.
|
- `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount.
|
||||||
- `Total trade volume`: Volume generated on the exchange to reach the above profit.
|
- `Total trade volume`: Volume generated on the exchange to reach the above profit.
|
||||||
- `Best Pair` / `Worst Pair`: Best and worst performing pair, and it's corresponding `Cum Profit %`.
|
- `Best Pair` / `Worst Pair`: Best and worst performing pair, and it's corresponding `Cum Profit %`.
|
||||||
@ -467,145 +420,49 @@ It contains some useful key metrics about performance of your strategy on backte
|
|||||||
- `Best day` / `Worst day`: Best and worst day based on daily profit.
|
- `Best day` / `Worst day`: Best and worst day based on daily profit.
|
||||||
- `Days win/draw/lose`: Winning / Losing days (draws are usually days without closed trade).
|
- `Days win/draw/lose`: Winning / Losing days (draws are usually days without closed trade).
|
||||||
- `Avg. Duration Winners` / `Avg. Duration Loser`: Average durations for winning and losing trades.
|
- `Avg. Duration Winners` / `Avg. Duration Loser`: Average durations for winning and losing trades.
|
||||||
- `Rejected Entry signals`: Trade entry signals that could not be acted upon due to `max_open_trades` being reached.
|
- `Zero Duration Trades`: A number of trades that completed within same candle as they opened and had `trailing_stop_loss` sell reason. A significant amount of such trades may indicate that strategy is exploiting trailing stoploss behavior in backtesting and produces unrealistic results.
|
||||||
- `Entry/Exit Timeouts`: Entry/exit orders which did not fill (only applicable if custom pricing is used).
|
- `Rejected Buy signals`: Buy signals that could not be acted upon due to max_open_trades being reached.
|
||||||
- `Canceled Trade Entries`: Number of trades that have been canceled by user request via `adjust_entry_price`.
|
|
||||||
- `Canceled Entry Orders`: Number of entry orders that have been canceled by user request via `adjust_entry_price`.
|
|
||||||
- `Replaced Entry Orders`: Number of entry orders that have been replaced by user request via `adjust_entry_price`.
|
|
||||||
- `Min balance` / `Max balance`: Lowest and Highest Wallet balance during the backtest period.
|
- `Min balance` / `Max balance`: Lowest and Highest Wallet balance during the backtest period.
|
||||||
- `Max % of account underwater`: Maximum percentage your account has decreased from the top since the simulation started.
|
- `Drawdown`: Maximum drawdown experienced. For example, the value of 50% means that from highest to subsequent lowest point, a 50% drop was experienced).
|
||||||
Calculated as the maximum of `(Max Balance - Current Balance) / (Max Balance)`.
|
|
||||||
- `Absolute Drawdown (Account)`: Maximum Account Drawdown experienced. Calculated as `(Absolute Drawdown) / (DrawdownHigh + startingBalance)`.
|
|
||||||
- `Drawdown`: Maximum, absolute drawdown experienced. Difference between Drawdown High and Subsequent Low point.
|
|
||||||
- `Drawdown high` / `Drawdown low`: Profit at the beginning and end of the largest drawdown period. A negative low value means initial capital lost.
|
- `Drawdown high` / `Drawdown low`: Profit at the beginning and end of the largest drawdown period. A negative low value means initial capital lost.
|
||||||
- `Drawdown Start` / `Drawdown End`: Start and end datetime for this largest drawdown (can also be visualized via the `plot-dataframe` sub-command).
|
- `Drawdown Start` / `Drawdown End`: Start and end datetime for this largest drawdown (can also be visualized via the `plot-dataframe` sub-command).
|
||||||
- `Market change`: Change of the market during the backtest period. Calculated as average of all pairs changes from the first to the last candle using the "close" column.
|
- `Market change`: Change of the market during the backtest period. Calculated as average of all pairs changes from the first to the last candle using the "close" column.
|
||||||
- `Long / Short`: Split long/short values (Only shown when short trades were made).
|
|
||||||
- `Total profit Long %` / `Absolute profit Long`: Profit long trades only (Only shown when short trades were made).
|
|
||||||
- `Total profit Short %` / `Absolute profit Short`: Profit short trades only (Only shown when short trades were made).
|
|
||||||
|
|
||||||
### Daily / Weekly / Monthly breakdown
|
### Assumptions made by backtesting
|
||||||
|
|
||||||
You can get an overview over daily / weekly or monthly results by using the `--breakdown <>` switch.
|
|
||||||
|
|
||||||
To visualize daily and weekly breakdowns, you can use the following:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade backtesting --strategy MyAwesomeStrategy --breakdown day week
|
|
||||||
```
|
|
||||||
|
|
||||||
``` output
|
|
||||||
======================== DAY BREAKDOWN =========================
|
|
||||||
| Day | Tot Profit USDT | Wins | Draws | Losses |
|
|
||||||
|------------+-------------------+--------+---------+----------|
|
|
||||||
| 03/07/2021 | 200.0 | 2 | 0 | 0 |
|
|
||||||
| 04/07/2021 | -50.31 | 0 | 0 | 2 |
|
|
||||||
| 05/07/2021 | 220.611 | 3 | 2 | 0 |
|
|
||||||
| 06/07/2021 | 150.974 | 3 | 0 | 2 |
|
|
||||||
| 07/07/2021 | -70.193 | 1 | 0 | 2 |
|
|
||||||
| 08/07/2021 | 212.413 | 2 | 0 | 3 |
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
The output will show a table containing the realized absolute Profit (in stake currency) for the given timeperiod, as well as wins, draws and losses that materialized (closed) on this day. Below that there will be a second table for the summarized values of weeks indicated by the date of the closing Sunday. The same would apply to a monthly breakdown indicated by the last day of the month.
|
|
||||||
|
|
||||||
### Backtest result caching
|
|
||||||
|
|
||||||
To save time, by default backtest will reuse a cached result from within the last day when the backtested strategy and config match that of a previous backtest. To force a new backtest despite existing result for an identical run specify `--cache none` parameter.
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Caching is automatically disabled for open-ended timeranges (`--timerange 20210101-`), as freqtrade cannot ensure reliably that the underlying data didn't change. It can also use cached results where it shouldn't if the original backtest had missing data at the end, which was fixed by downloading more data.
|
|
||||||
In this instance, please use `--cache none` once to force a fresh backtest.
|
|
||||||
|
|
||||||
### Further backtest-result analysis
|
|
||||||
|
|
||||||
To further analyze your backtest results, you can [export the trades](#exporting-trades-to-file).
|
|
||||||
You can then load the trades to perform further analysis as shown in the [data analysis](data-analysis.md#backtesting) backtesting section.
|
|
||||||
|
|
||||||
## Assumptions made by backtesting
|
|
||||||
|
|
||||||
Since backtesting lacks some detailed information about what happens within a candle, it needs to take a few assumptions:
|
Since backtesting lacks some detailed information about what happens within a candle, it needs to take a few assumptions:
|
||||||
|
|
||||||
- Exchange [trading limits](#trading-limits-in-backtesting) are respected
|
- Buys happen at open-price
|
||||||
- Entries happen at open-price
|
|
||||||
- All orders are filled at the requested price (no slippage, no unfilled orders)
|
- All orders are filled at the requested price (no slippage, no unfilled orders)
|
||||||
- Exit-signal exits happen at open-price of the consecutive candle
|
- Sell-signal sells happen at open-price of the consecutive candle
|
||||||
- Exit-signal is favored over Stoploss, because exit-signals are assumed to trigger on candle's open
|
- Sell-signal is favored over Stoploss, because sell-signals are assumed to trigger on candle's open
|
||||||
- ROI
|
- ROI
|
||||||
- exits are compared to high - but the ROI value is used (e.g. ROI = 2%, high=5% - so the exit will be at 2%)
|
- sells are compared to high - but the ROI value is used (e.g. ROI = 2%, high=5% - so the sell will be at 2%)
|
||||||
- exits are never "below the candle", so a ROI of 2% may result in a exit at 2.4% if low was at 2.4% profit
|
- sells are never "below the candle", so a ROI of 2% may result in a sell at 2.4% if low was at 2.4% profit
|
||||||
- Force-exits caused by `<N>=-1` ROI entries use low as exit value, unless N falls on the candle open (e.g. `120: -1` for 1h candles)
|
- Forcesells caused by `<N>=-1` ROI entries use low as sell value, unless N falls on the candle open (e.g. `120: -1` for 1h candles)
|
||||||
- Stoploss exits happen exactly at stoploss price, even if low was lower, but the loss will be `2 * fees` higher than the stoploss price
|
- Stoploss sells happen exactly at stoploss price, even if low was lower, but the loss will be `2 * fees` higher than the stoploss price
|
||||||
- Stoploss is evaluated before ROI within one candle. So you can often see more trades with the `stoploss` exit reason comparing to the results obtained with the same strategy in the Dry Run/Live Trade modes
|
- Stoploss is evaluated before ROI within one candle. So you can often see more trades with the `stoploss` sell reason comparing to the results obtained with the same strategy in the Dry Run/Live Trade modes
|
||||||
- Low happens before high for stoploss, protecting capital first
|
- Low happens before high for stoploss, protecting capital first
|
||||||
- Trailing stoploss
|
- Trailing stoploss
|
||||||
- Trailing Stoploss is only adjusted if it's below the candle's low (otherwise it would be triggered)
|
- Trailing Stoploss is only adjusted if it's below the candle's low (otherwise it would be triggered)
|
||||||
- On trade entry candles that trigger trailing stoploss, the "minimum offset" (`stop_positive_offset`) is assumed (instead of high) - and the stop is calculated from this point. This rule is NOT applicable to custom-stoploss scenarios, since there's no information about the stoploss logic available.
|
|
||||||
- High happens first - adjusting stoploss
|
- High happens first - adjusting stoploss
|
||||||
- Low uses the adjusted stoploss (so exits with large high-low difference are backtested correctly)
|
- Low uses the adjusted stoploss (so sells with large high-low difference are backtested correctly)
|
||||||
- ROI applies before trailing-stop, ensuring profits are "top-capped" at ROI if both ROI and trailing stop applies
|
- ROI applies before trailing-stop, ensuring profits are "top-capped" at ROI if both ROI and trailing stop applies
|
||||||
- Exit-reason does not explain if a trade was positive or negative, just what triggered the exit (this can look odd if negative ROI values are used)
|
- Sell-reason does not explain if a trade was positive or negative, just what triggered the sell (this can look odd if negative ROI values are used)
|
||||||
- Evaluation sequence (if multiple signals happen on the same candle)
|
- Evaluation sequence (if multiple signals happen on the same candle)
|
||||||
- Exit-signal
|
- ROI (if not stoploss)
|
||||||
|
- Sell-signal
|
||||||
- Stoploss
|
- Stoploss
|
||||||
- ROI
|
|
||||||
- Trailing stoploss
|
|
||||||
|
|
||||||
Taking these assumptions, backtesting tries to mirror real trading as closely as possible. However, backtesting will **never** replace running a strategy in dry-run mode.
|
Taking these assumptions, backtesting tries to mirror real trading as closely as possible. However, backtesting will **never** replace running a strategy in dry-run mode.
|
||||||
Also, keep in mind that past results don't guarantee future success.
|
Also, keep in mind that past results don't guarantee future success.
|
||||||
|
|
||||||
In addition to the above assumptions, strategy authors should carefully read the [Common Mistakes](strategy-customization.md#common-mistakes-when-developing-strategies) section, to avoid using data in backtesting which is not available in real market conditions.
|
In addition to the above assumptions, strategy authors should carefully read the [Common Mistakes](strategy-customization.md#common-mistakes-when-developing-strategies) section, to avoid using data in backtesting which is not available in real market conditions.
|
||||||
|
|
||||||
### Trading limits in backtesting
|
### Further backtest-result analysis
|
||||||
|
|
||||||
Exchanges have certain trading limits, like minimum (and maximum) base currency, or minimum/maximum stake (quote) currency.
|
To further analyze your backtest results, you can [export the trades](#exporting-trades-to-file).
|
||||||
These limits are usually listed in the exchange documentation as "trading rules" or similar and can be quite different between different pairs.
|
You can then load the trades to perform further analysis as shown in our [data analysis](data-analysis.md#backtesting) backtesting section.
|
||||||
|
|
||||||
Backtesting (as well as live and dry-run) does honor these limits, and will ensure that a stoploss can be placed below this value - so the value will be slightly higher than what the exchange specifies.
|
|
||||||
Freqtrade has however no information about historic limits.
|
|
||||||
|
|
||||||
This can lead to situations where trading-limits are inflated by using a historic price, resulting in minimum amounts > 50$.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
BTC minimum tradable amount is 0.001.
|
|
||||||
BTC trades at 22.000\$ today (0.001 BTC is related to this) - but the backtesting period includes prices as high as 50.000\$.
|
|
||||||
Today's minimum would be `0.001 * 22_000` - or 22\$.
|
|
||||||
However the limit could also be 50$ - based on `0.001 * 50_000` in some historic setting.
|
|
||||||
|
|
||||||
#### Trading precision limits
|
|
||||||
|
|
||||||
Most exchanges pose precision limits on both price and amounts, so you cannot buy 1.0020401 of a pair, or at a price of 1.24567123123.
|
|
||||||
Instead, these prices and amounts will be rounded or truncated (based on the exchange definition) to the defined trading precision.
|
|
||||||
The above values may for example be rounded to an amount of 1.002, and a price of 1.24567.
|
|
||||||
|
|
||||||
These precision values are based on current exchange limits (as described in the [above section](#trading-limits-in-backtesting)), as historic precision limits are not available.
|
|
||||||
|
|
||||||
## Improved backtest accuracy
|
|
||||||
|
|
||||||
One big limitation of backtesting is it's inability to know how prices moved intra-candle (was high before close, or viceversa?).
|
|
||||||
So assuming you run backtesting with a 1h timeframe, there will be 4 prices for that candle (Open, High, Low, Close).
|
|
||||||
|
|
||||||
While backtesting does take some assumptions (read above) about this - this can never be perfect, and will always be biased in one way or the other.
|
|
||||||
To mitigate this, freqtrade can use a lower (faster) timeframe to simulate intra-candle movements.
|
|
||||||
|
|
||||||
To utilize this, you can append `--timeframe-detail 5m` to your regular backtesting command.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade backtesting --strategy AwesomeStrategy --timeframe 1h --timeframe-detail 5m
|
|
||||||
```
|
|
||||||
|
|
||||||
This will load 1h data as well as 5m data for the timeframe. The strategy will be analyzed with the 1h timeframe, and Entry orders will only be placed at the main timeframe, however Order fills and exit signals will be evaluated at the 5m candle, simulating intra-candle movements.
|
|
||||||
|
|
||||||
All callback functions (`custom_exit()`, `custom_stoploss()`, ... ) will be running for each 5m candle once the trade is opened (so 12 times in the above example of 1h timeframe, and 5m detailed timeframe).
|
|
||||||
|
|
||||||
`--timeframe-detail` must be smaller than the original timeframe, otherwise backtesting will fail to start.
|
|
||||||
|
|
||||||
Obviously this will require more memory (5m data is bigger than 1h data), and will also impact runtime (depending on the amount of trades and trade durations).
|
|
||||||
Also, data must be available / downloaded already.
|
|
||||||
|
|
||||||
!!! Tip
|
|
||||||
You can use this function as the last part of strategy development, to ensure your strategy is not exploiting one of the [backtesting assumptions](#assumptions-made-by-backtesting). Strategies that perform similarly well with this mode have a good chance to perform well in dry/live modes too (although only forward-testing (dry-mode) can really confirm a strategy).
|
|
||||||
|
|
||||||
## Backtesting multiple strategies
|
## Backtesting multiple strategies
|
||||||
|
|
||||||
@ -625,11 +482,11 @@ There will be an additional table comparing win/losses of the different strategi
|
|||||||
Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy.
|
Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy.
|
||||||
|
|
||||||
```
|
```
|
||||||
=========================================================== STRATEGY SUMMARY ===========================================================================
|
=========================================================== STRATEGY SUMMARY =========================================================================
|
||||||
| Strategy | Entries | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses | Drawdown % |
|
| Strategy | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses | Drawdown % |
|
||||||
|:------------|---------:|---------------:|---------------:|-----------------:|---------------:|:---------------|------:|-------:|-------:|-----------:|
|
|:------------|-------:|---------------:|---------------:|-----------------:|---------------:|:---------------|------:|-------:|-------:|-----------:|
|
||||||
| Strategy1 | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 | 0 | 243 | 45.2 |
|
| Strategy1 | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 | 0 | 243 | 45.2 |
|
||||||
| Strategy2 | 1487 | -0.13 | -197.58 | -0.00988917 | -98.79 | 4:43:00 | 662 | 0 | 825 | 241.68 |
|
| Strategy2 | 1487 | -0.13 | -197.58 | -0.00988917 | -98.79 | 4:43:00 | 662 | 0 | 825 | 241.68 |
|
||||||
```
|
```
|
||||||
|
|
||||||
## Next step
|
## Next step
|
||||||
|
@ -7,14 +7,11 @@ This page provides you some basic concepts on how Freqtrade works and operates.
|
|||||||
* **Strategy**: Your trading strategy, telling the bot what to do.
|
* **Strategy**: Your trading strategy, telling the bot what to do.
|
||||||
* **Trade**: Open position.
|
* **Trade**: Open position.
|
||||||
* **Open Order**: Order which is currently placed on the exchange, and is not yet complete.
|
* **Open Order**: Order which is currently placed on the exchange, and is not yet complete.
|
||||||
* **Pair**: Tradable pair, usually in the format of Base/Quote (e.g. XRP/USDT).
|
* **Pair**: Tradable pair, usually in the format of Quote/Base (e.g. XRP/USDT).
|
||||||
* **Timeframe**: Candle length to use (e.g. `"5m"`, `"1h"`, ...).
|
* **Timeframe**: Candle length to use (e.g. `"5m"`, `"1h"`, ...).
|
||||||
* **Indicators**: Technical indicators (SMA, EMA, RSI, ...).
|
* **Indicators**: Technical indicators (SMA, EMA, RSI, ...).
|
||||||
* **Limit order**: Limit orders which execute at the defined limit price or better.
|
* **Limit order**: Limit orders which execute at the defined limit price or better.
|
||||||
* **Market order**: Guaranteed to fill, may move price depending on the order size.
|
* **Market order**: Guaranteed to fill, may move price depending on the order size.
|
||||||
* **Current Profit**: Currently pending (unrealized) profit for this trade. This is mainly used throughout the bot and UI.
|
|
||||||
* **Realized Profit**: Already realized profit. Only relevant in combination with [partial exits](strategy-callbacks.md#adjust-trade-position) - which also explains the calculation logic for this.
|
|
||||||
* **Total Profit**: Combined realized and unrealized profit. The relative number (%) is calculated against the total investment in this trade.
|
|
||||||
|
|
||||||
## Fee handling
|
## Fee handling
|
||||||
|
|
||||||
@ -23,34 +20,28 @@ All profit calculations of Freqtrade include fees. For Backtesting / Hyperopt /
|
|||||||
## Bot execution logic
|
## Bot execution logic
|
||||||
|
|
||||||
Starting freqtrade in dry-run or live mode (using `freqtrade trade`) will start the bot and start the bot iteration loop.
|
Starting freqtrade in dry-run or live mode (using `freqtrade trade`) will start the bot and start the bot iteration loop.
|
||||||
This will also run the `bot_start()` callback.
|
By default, loop runs every few seconds (`internals.process_throttle_secs`) and does roughly the following in the following sequence:
|
||||||
|
|
||||||
By default, the bot loop runs every few seconds (`internals.process_throttle_secs`) and performs the following actions:
|
|
||||||
|
|
||||||
* Fetch open trades from persistence.
|
* Fetch open trades from persistence.
|
||||||
* Calculate current list of tradable pairs.
|
* Calculate current list of tradable pairs.
|
||||||
* Download OHLCV data for the pairlist including all [informative pairs](strategy-customization.md#get-data-for-non-tradeable-pairs)
|
* Download ohlcv data for the pairlist including all [informative pairs](strategy-customization.md#get-data-for-non-tradeable-pairs)
|
||||||
This step is only executed once per Candle to avoid unnecessary network traffic.
|
This step is only executed once per Candle to avoid unnecessary network traffic.
|
||||||
* Call `bot_loop_start()` strategy callback.
|
* Call `bot_loop_start()` strategy callback.
|
||||||
* Analyze strategy per pair.
|
* Analyze strategy per pair.
|
||||||
* Call `populate_indicators()`
|
* Call `populate_indicators()`
|
||||||
* Call `populate_entry_trend()`
|
* Call `populate_buy_trend()`
|
||||||
* Call `populate_exit_trend()`
|
* Call `populate_sell_trend()`
|
||||||
* Check timeouts for open orders.
|
* Check timeouts for open orders.
|
||||||
* Calls `check_entry_timeout()` strategy callback for open entry orders.
|
* Calls `check_buy_timeout()` strategy callback for open buy orders.
|
||||||
* Calls `check_exit_timeout()` strategy callback for open exit orders.
|
* Calls `check_sell_timeout()` strategy callback for open sell orders.
|
||||||
* Calls `adjust_entry_price()` strategy callback for open entry orders.
|
* Verifies existing positions and eventually places sell orders.
|
||||||
* Verifies existing positions and eventually places exit orders.
|
* Considers stoploss, ROI and sell-signal.
|
||||||
* Considers stoploss, ROI and exit-signal, `custom_exit()` and `custom_stoploss()`.
|
* Determine sell-price based on `ask_strategy` configuration setting.
|
||||||
* Determine exit-price based on `exit_pricing` configuration setting or by using the `custom_exit_price()` callback.
|
* Before a sell order is placed, `confirm_trade_exit()` strategy callback is called.
|
||||||
* Before a exit order is placed, `confirm_trade_exit()` strategy callback is called.
|
|
||||||
* Check position adjustments for open trades if enabled by calling `adjust_trade_position()` and place additional order if required.
|
|
||||||
* Check if trade-slots are still available (if `max_open_trades` is reached).
|
* Check if trade-slots are still available (if `max_open_trades` is reached).
|
||||||
* Verifies entry signal trying to enter new positions.
|
* Verifies buy signal trying to enter new positions.
|
||||||
* Determine entry-price based on `entry_pricing` configuration setting, or by using the `custom_entry_price()` callback.
|
* Determine buy-price based on `bid_strategy` configuration setting.
|
||||||
* In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage.
|
* Before a buy order is placed, `confirm_trade_entry()` strategy callback is called.
|
||||||
* Determine stake size by calling the `custom_stake_amount()` callback.
|
|
||||||
* Before an entry order is placed, `confirm_trade_entry()` strategy callback is called.
|
|
||||||
|
|
||||||
This loop will be repeated again and again until the bot is stopped.
|
This loop will be repeated again and again until the bot is stopped.
|
||||||
|
|
||||||
@ -59,26 +50,12 @@ This loop will be repeated again and again until the bot is stopped.
|
|||||||
[backtesting](backtesting.md) or [hyperopt](hyperopt.md) do only part of the above logic, since most of the trading operations are fully simulated.
|
[backtesting](backtesting.md) or [hyperopt](hyperopt.md) do only part of the above logic, since most of the trading operations are fully simulated.
|
||||||
|
|
||||||
* Load historic data for configured pairlist.
|
* Load historic data for configured pairlist.
|
||||||
* Calls `bot_start()` once.
|
* Calls `bot_loop_start()` once.
|
||||||
* Calculate indicators (calls `populate_indicators()` once per pair).
|
* Calculate indicators (calls `populate_indicators()` once per pair).
|
||||||
* Calculate entry / exit signals (calls `populate_entry_trend()` and `populate_exit_trend()` once per pair).
|
* Calculate buy / sell signals (calls `populate_buy_trend()` and `populate_sell_trend()` once per pair)
|
||||||
|
* Confirm trade buy / sell (calls `confirm_trade_entry()` and `confirm_trade_exit()` if implemented in the strategy)
|
||||||
* Loops per candle simulating entry and exit points.
|
* Loops per candle simulating entry and exit points.
|
||||||
* Calls `bot_loop_start()` strategy callback.
|
|
||||||
* Check for Order timeouts, either via the `unfilledtimeout` configuration, or via `check_entry_timeout()` / `check_exit_timeout()` strategy callbacks.
|
|
||||||
* Calls `adjust_entry_price()` strategy callback for open entry orders.
|
|
||||||
* Check for trade entry signals (`enter_long` / `enter_short` columns).
|
|
||||||
* Confirm trade entry / exits (calls `confirm_trade_entry()` and `confirm_trade_exit()` if implemented in the strategy).
|
|
||||||
* Call `custom_entry_price()` (if implemented in the strategy) to determine entry price (Prices are moved to be within the opening candle).
|
|
||||||
* In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage.
|
|
||||||
* Determine stake size by calling the `custom_stake_amount()` callback.
|
|
||||||
* Check position adjustments for open trades if enabled and call `adjust_trade_position()` to determine if an additional order is requested.
|
|
||||||
* Call `custom_stoploss()` and `custom_exit()` to find custom exit points.
|
|
||||||
* For exits based on exit-signal, custom-exit and partial exits: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle).
|
|
||||||
* Generate backtest report output
|
* Generate backtest report output
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
Both Backtesting and Hyperopt include exchange default Fees in the calculation. Custom fees can be passed to backtesting / hyperopt by specifying the `--fee` argument.
|
Both Backtesting and Hyperopt include exchange default Fees in the calculation. Custom fees can be passed to backtesting / hyperopt by specifying the `--fee` argument.
|
||||||
|
|
||||||
!!! Warning "Callback call frequency"
|
|
||||||
Backtesting will call each callback at max. once per candle (`--timeframe-detail` modifies this behavior to once per detailed candle).
|
|
||||||
Most callbacks will be called once per iteration in live (usually every ~5s) - which can cause backtesting mismatches.
|
|
||||||
|
@ -12,22 +12,22 @@ This page explains the different parameters of the bot and how to run it.
|
|||||||
|
|
||||||
```
|
```
|
||||||
usage: freqtrade [-h] [-V]
|
usage: freqtrade [-h] [-V]
|
||||||
{trade,create-userdir,new-config,new-strategy,download-data,convert-data,convert-trade-data,list-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,install-ui,plot-dataframe,plot-profit,webserver}
|
{trade,create-userdir,new-config,new-hyperopt,new-strategy,download-data,convert-data,convert-trade-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,plot-dataframe,plot-profit}
|
||||||
...
|
...
|
||||||
|
|
||||||
Free, open source crypto trading bot
|
Free, open source crypto trading bot
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{trade,create-userdir,new-config,new-strategy,download-data,convert-data,convert-trade-data,list-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,install-ui,plot-dataframe,plot-profit,webserver}
|
{trade,create-userdir,new-config,new-hyperopt,new-strategy,download-data,convert-data,convert-trade-data,backtesting,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-hyperopts,list-markets,list-pairs,list-strategies,list-timeframes,show-trades,test-pairlist,plot-dataframe,plot-profit}
|
||||||
trade Trade module.
|
trade Trade module.
|
||||||
create-userdir Create user-data directory.
|
create-userdir Create user-data directory.
|
||||||
new-config Create new config
|
new-config Create new config
|
||||||
|
new-hyperopt Create new hyperopt
|
||||||
new-strategy Create new strategy
|
new-strategy Create new strategy
|
||||||
download-data Download backtesting data.
|
download-data Download backtesting data.
|
||||||
convert-data Convert candle (OHLCV) data from one format to
|
convert-data Convert candle (OHLCV) data from one format to
|
||||||
another.
|
another.
|
||||||
convert-trade-data Convert trade data from one format to another.
|
convert-trade-data Convert trade data from one format to another.
|
||||||
list-data List downloaded data.
|
|
||||||
backtesting Backtesting module.
|
backtesting Backtesting module.
|
||||||
edge Edge module.
|
edge Edge module.
|
||||||
hyperopt Hyperopt module.
|
hyperopt Hyperopt module.
|
||||||
@ -41,10 +41,8 @@ positional arguments:
|
|||||||
list-timeframes Print available timeframes for the exchange.
|
list-timeframes Print available timeframes for the exchange.
|
||||||
show-trades Show trades.
|
show-trades Show trades.
|
||||||
test-pairlist Test your pairlist configuration.
|
test-pairlist Test your pairlist configuration.
|
||||||
install-ui Install FreqUI
|
|
||||||
plot-dataframe Plot candles with indicators.
|
plot-dataframe Plot candles with indicators.
|
||||||
plot-profit Generate plot showing profits.
|
plot-profit Generate plot showing profits.
|
||||||
webserver Webserver module.
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
@ -5,265 +5,148 @@ By default, these settings are configured via the configuration file (see below)
|
|||||||
|
|
||||||
## The Freqtrade configuration file
|
## The Freqtrade configuration file
|
||||||
|
|
||||||
The bot uses a set of configuration parameters during its operation that all together conform to the bot configuration. It normally reads its configuration from a file (Freqtrade configuration file).
|
The bot uses a set of configuration parameters during its operation that all together conform the bot configuration. It normally reads its configuration from a file (Freqtrade configuration file).
|
||||||
|
|
||||||
Per default, the bot loads the configuration from the `config.json` file, located in the current working directory.
|
Per default, the bot loads the configuration from the `config.json` file, located in the current working directory.
|
||||||
|
|
||||||
You can specify a different configuration file used by the bot with the `-c/--config` command-line option.
|
You can specify a different configuration file used by the bot with the `-c/--config` command line option.
|
||||||
|
|
||||||
If you used the [Quick start](docker_quickstart.md#docker-quick-start) method for installing
|
|
||||||
the bot, the installation script should have already created the default configuration file (`config.json`) for you.
|
|
||||||
|
|
||||||
If the default configuration file is not created we recommend to use `freqtrade new-config --config config.json` to generate a basic configuration file.
|
|
||||||
|
|
||||||
The Freqtrade configuration file is to be written in JSON format.
|
|
||||||
|
|
||||||
Additionally to the standard JSON syntax, you may use one-line `// ...` and multi-line `/* ... */` comments in your configuration files and trailing commas in the lists of parameters.
|
|
||||||
|
|
||||||
Do not worry if you are not familiar with JSON format -- simply open the configuration file with an editor of your choice, make some changes to the parameters you need, save your changes and, finally, restart the bot or, if it was previously stopped, run it again with the changes you made to the configuration. The bot validates the syntax of the configuration file at startup and will warn you if you made any errors editing it, pointing out problematic lines.
|
|
||||||
|
|
||||||
### Environment variables
|
|
||||||
|
|
||||||
Set options in the Freqtrade configuration via environment variables.
|
|
||||||
This takes priority over the corresponding value in configuration or strategy.
|
|
||||||
|
|
||||||
Environment variables must be prefixed with `FREQTRADE__` to be loaded to the freqtrade configuration.
|
|
||||||
|
|
||||||
`__` serves as level separator, so the format used should correspond to `FREQTRADE__{section}__{key}`.
|
|
||||||
As such - an environment variable defined as `export FREQTRADE__STAKE_AMOUNT=200` would result in `{stake_amount: 200}`.
|
|
||||||
|
|
||||||
A more complex example might be `export FREQTRADE__EXCHANGE__KEY=<yourExchangeKey>` to keep your exchange key secret. This will move the value to the `exchange.key` section of the configuration.
|
|
||||||
Using this scheme, all configuration settings will also be available as environment variables.
|
|
||||||
|
|
||||||
Please note that Environment variables will overwrite corresponding settings in your configuration, but command line Arguments will always win.
|
|
||||||
|
|
||||||
Common example:
|
|
||||||
|
|
||||||
```
|
|
||||||
FREQTRADE__TELEGRAM__CHAT_ID=<telegramchatid>
|
|
||||||
FREQTRADE__TELEGRAM__TOKEN=<telegramToken>
|
|
||||||
FREQTRADE__EXCHANGE__KEY=<yourExchangeKey>
|
|
||||||
FREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Environment variables detected are logged at startup - so if you can't find why a value is not what you think it should be based on the configuration, make sure it's not loaded from an environment variable.
|
|
||||||
|
|
||||||
### Multiple configuration files
|
|
||||||
|
|
||||||
Multiple configuration files can be specified and used by the bot or the bot can read its configuration parameters from the process standard input stream.
|
Multiple configuration files can be specified and used by the bot or the bot can read its configuration parameters from the process standard input stream.
|
||||||
|
|
||||||
You can specify additional configuration files in `add_config_files`. Files specified in this parameter will be loaded and merged with the initial config file. The files are resolved relative to the initial configuration file.
|
|
||||||
This is similar to using multiple `--config` parameters, but simpler in usage as you don't have to specify all files for all commands.
|
|
||||||
|
|
||||||
!!! Tip "Use multiple configuration files to keep secrets secret"
|
!!! Tip "Use multiple configuration files to keep secrets secret"
|
||||||
You can use a 2nd configuration file containing your secrets. That way you can share your "primary" configuration file, while still keeping your API keys for yourself.
|
You can use a 2nd configuration file containing your secrets. That way you can share your "primary" configuration file, while still keeping your API keys for yourself.
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
freqtrade trade --config user_data/config.json --config user_data/config-private.json <...>
|
||||||
|
```
|
||||||
The 2nd file should only specify what you intend to override.
|
The 2nd file should only specify what you intend to override.
|
||||||
If a key is in more than one of the configurations, then the "last specified configuration" wins (in the above example, `config-private.json`).
|
If a key is in more than one of the configurations, then the "last specified configuration" wins (in the above example, `config-private.json`).
|
||||||
|
|
||||||
For one-off commands, you can also use the below syntax by specifying multiple "--config" parameters.
|
If you used the [Quick start](installation.md/#quick-start) method for installing
|
||||||
|
the bot, the installation script should have already created the default configuration file (`config.json`) for you.
|
||||||
|
|
||||||
``` bash
|
If default configuration file is not created we recommend you to use `freqtrade new-config --config config.json` to generate a basic configuration file.
|
||||||
freqtrade trade --config user_data/config1.json --config user_data/config-private.json <...>
|
|
||||||
```
|
|
||||||
|
|
||||||
The below is equivalent to the example above - but having 2 configuration files in the configuration, for easier reuse.
|
The Freqtrade configuration file is to be written in the JSON format.
|
||||||
|
|
||||||
``` json title="user_data/config.json"
|
Additionally to the standard JSON syntax, you may use one-line `// ...` and multi-line `/* ... */` comments in your configuration files and trailing commas in the lists of parameters.
|
||||||
"add_config_files": [
|
|
||||||
"config1.json",
|
|
||||||
"config-private.json"
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
``` bash
|
Do not worry if you are not familiar with JSON format -- simply open the configuration file with an editor of your choice, make some changes to the parameters you need, save your changes and, finally, restart the bot or, if it was previously stopped, run it again with the changes you made to the configuration. The bot validates syntax of the configuration file at startup and will warn you if you made any errors editing it, pointing out problematic lines.
|
||||||
freqtrade trade --config user_data/config.json <...>
|
|
||||||
```
|
|
||||||
|
|
||||||
??? Note "config collision handling"
|
|
||||||
If the same configuration setting takes place in both `config.json` and `config-import.json`, then the parent configuration wins.
|
|
||||||
In the below case, `max_open_trades` would be 3 after the merging - as the reusable "import" configuration has this key overwritten.
|
|
||||||
|
|
||||||
``` json title="user_data/config.json"
|
|
||||||
{
|
|
||||||
"max_open_trades": 3,
|
|
||||||
"stake_currency": "USDT",
|
|
||||||
"add_config_files": [
|
|
||||||
"config-import.json"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
``` json title="user_data/config-import.json"
|
|
||||||
{
|
|
||||||
"max_open_trades": 10,
|
|
||||||
"stake_amount": "unlimited",
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Resulting combined configuration:
|
|
||||||
|
|
||||||
``` json title="Result"
|
|
||||||
{
|
|
||||||
"max_open_trades": 3,
|
|
||||||
"stake_currency": "USDT",
|
|
||||||
"stake_amount": "unlimited"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If multiple files are in the `add_config_files` section, then they will be assumed to be at identical levels, having the last occurrence override the earlier config (unless a parent already defined such a key).
|
|
||||||
|
|
||||||
## Configuration parameters
|
## Configuration parameters
|
||||||
|
|
||||||
The table below will list all configuration parameters available.
|
The table below will list all configuration parameters available.
|
||||||
|
|
||||||
Freqtrade can also load many options via command line (CLI) arguments (check out the commands `--help` output for details).
|
Freqtrade can also load many options via command line (CLI) arguments (check out the commands `--help` output for details).
|
||||||
|
The prevelance for all Options is as follows:
|
||||||
### Configuration option prevalence
|
|
||||||
|
|
||||||
The prevalence for all Options is as follows:
|
|
||||||
|
|
||||||
- CLI arguments override any other option
|
- CLI arguments override any other option
|
||||||
- [Environment Variables](#environment-variables)
|
- Configuration files are used in sequence (last file wins), and override Strategy configurations.
|
||||||
- Configuration files are used in sequence (the last file wins) and override Strategy configurations.
|
- Strategy configurations are only used if they are not set via configuration or via command line arguments. These options are marked with [Strategy Override](#parameters-in-the-strategy) in the below table.
|
||||||
- Strategy configurations are only used if they are not set via configuration or command-line arguments. These options are marked with [Strategy Override](#parameters-in-the-strategy) in the below table.
|
|
||||||
|
|
||||||
### Parameters table
|
|
||||||
|
|
||||||
Mandatory parameters are marked as **Required**, which means that they are required to be set in one of the possible ways.
|
Mandatory parameters are marked as **Required**, which means that they are required to be set in one of the possible ways.
|
||||||
|
|
||||||
| Parameter | Description |
|
| Parameter | Description |
|
||||||
|------------|-------------|
|
|------------|-------------|
|
||||||
| `max_open_trades` | **Required.** Number of open trades your bot is allowed to have. Only one open trade per pair is possible, so the length of your pairlist is another limitation that can apply. If -1 then it is ignored (i.e. potentially unlimited open trades, limited by the pairlist). [More information below](#configuring-amount-per-trade). [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Positive integer or -1.
|
| `max_open_trades` | **Required.** Number of open trades your bot is allowed to have. Only one open trade per pair is possible, so the length of your pairlist is another limitation which can apply. If -1 then it is ignored (i.e. potentially unlimited open trades, limited by the pairlist). [More information below](#configuring-amount-per-trade).<br> **Datatype:** Positive integer or -1.
|
||||||
| `stake_currency` | **Required.** Crypto-currency used for trading. <br> **Datatype:** String
|
| `stake_currency` | **Required.** Crypto-currency used for trading. <br> **Datatype:** String
|
||||||
| `stake_amount` | **Required.** Amount of crypto-currency your bot will use for each trade. Set it to `"unlimited"` to allow the bot to use all available balance. [More information below](#configuring-amount-per-trade). <br> **Datatype:** Positive float or `"unlimited"`.
|
| `stake_amount` | **Required.** Amount of crypto-currency your bot will use for each trade. Set it to `"unlimited"` to allow the bot to use all available balance. [More information below](#configuring-amount-per-trade). <br> **Datatype:** Positive float or `"unlimited"`.
|
||||||
| `tradable_balance_ratio` | Ratio of the total account balance the bot is allowed to trade. [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.99` 99%).*<br> **Datatype:** Positive float between `0.1` and `1.0`.
|
| `tradable_balance_ratio` | Ratio of the total account balance the bot is allowed to trade. [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.99` 99%).*<br> **Datatype:** Positive float between `0.1` and `1.0`.
|
||||||
| `available_capital` | Available starting capital for the bot. Useful when running multiple bots on the same exchange account.[More information below](#configuring-amount-per-trade). <br> **Datatype:** Positive float.
|
|
||||||
| `amend_last_stake_amount` | Use reduced last stake amount if necessary. [More information below](#configuring-amount-per-trade). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `amend_last_stake_amount` | Use reduced last stake amount if necessary. [More information below](#configuring-amount-per-trade). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `last_stake_amount_min_ratio` | Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if `amend_last_stake_amount` is set to `true`). [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.5`.* <br> **Datatype:** Float (as ratio)
|
| `last_stake_amount_min_ratio` | Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if `amend_last_stake_amount` is set to `true`). [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.5`.* <br> **Datatype:** Float (as ratio)
|
||||||
| `amount_reserve_percent` | Reserve some amount in min pair stake amount. The bot will reserve `amount_reserve_percent` + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals. <br>*Defaults to `0.05` (5%).* <br> **Datatype:** Positive Float as ratio.
|
| `amount_reserve_percent` | Reserve some amount in min pair stake amount. The bot will reserve `amount_reserve_percent` + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals. <br>*Defaults to `0.05` (5%).* <br> **Datatype:** Positive Float as ratio.
|
||||||
| `timeframe` | The timeframe to use (e.g `1m`, `5m`, `15m`, `30m`, `1h` ...). Usually missing in configuration, and specified in the strategy. [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** String
|
| `timeframe` | The timeframe (former ticker interval) to use (e.g `1m`, `5m`, `15m`, `30m`, `1h` ...). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** String
|
||||||
| `fiat_display_currency` | Fiat currency used to show your profits. [More information below](#what-values-can-be-used-for-fiat_display_currency). <br> **Datatype:** String
|
| `fiat_display_currency` | Fiat currency used to show your profits. [More information below](#what-values-can-be-used-for-fiat_display_currency). <br> **Datatype:** String
|
||||||
| `dry_run` | **Required.** Define if the bot must be in Dry Run or production mode. <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
| `dry_run` | **Required.** Define if the bot must be in Dry Run or production mode. <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
||||||
| `dry_run_wallet` | Define the starting amount in stake currency for the simulated wallet used by the bot running in Dry Run mode.<br>*Defaults to `1000`.* <br> **Datatype:** Float
|
| `dry_run_wallet` | Define the starting amount in stake currency for the simulated wallet used by the bot running in Dry Run mode.<br>*Defaults to `1000`.* <br> **Datatype:** Float
|
||||||
| `cancel_open_orders_on_exit` | Cancel open orders when the `/stop` RPC command is issued, `Ctrl+C` is pressed or the bot dies unexpectedly. When set to `true`, this allows you to use `/stop` to cancel unfilled and partially filled orders in the event of a market crash. It does not impact open positions. <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `cancel_open_orders_on_exit` | Cancel open orders when the `/stop` RPC command is issued, `Ctrl+C` is pressed or the bot dies unexpectedly. When set to `true`, this allows you to use `/stop` to cancel unfilled and partially filled orders in the event of a market crash. It does not impact open positions. <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `process_only_new_candles` | Enable processing of indicators only when new candles arrive. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
| `process_only_new_candles` | Enable processing of indicators only when new candles arrive. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `minimal_roi` | **Required.** Set the threshold as ratio the bot will use to exit a trade. [More information below](#understand-minimal_roi). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
| `minimal_roi` | **Required.** Set the threshold as ratio the bot will use to sell a trade. [More information below](#understand-minimal_roi). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
||||||
| `stoploss` | **Required.** Value as ratio of the stoploss used by the bot. More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float (as ratio)
|
| `stoploss` | **Required.** Value as ratio of the stoploss used by the bot. More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float (as ratio)
|
||||||
| `trailing_stop` | Enables trailing stoploss (based on `stoploss` in either configuration or strategy file). More details in the [stoploss documentation](stoploss.md#trailing-stop-loss). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Boolean
|
| `trailing_stop` | Enables trailing stoploss (based on `stoploss` in either configuration or strategy file). More details in the [stoploss documentation](stoploss.md#trailing-stop-loss). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Boolean
|
||||||
| `trailing_stop_positive` | Changes stoploss once profit has been reached. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-custom-positive-loss). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float
|
| `trailing_stop_positive` | Changes stoploss once profit has been reached. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-custom-positive-loss). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float
|
||||||
| `trailing_stop_positive_offset` | Offset on when to apply `trailing_stop_positive`. Percentage value which should be positive. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0` (no offset).* <br> **Datatype:** Float
|
| `trailing_stop_positive_offset` | Offset on when to apply `trailing_stop_positive`. Percentage value which should be positive. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0` (no offset).* <br> **Datatype:** Float
|
||||||
| `trailing_only_offset_is_reached` | Only apply trailing stoploss when the offset is reached. [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `trailing_only_offset_is_reached` | Only apply trailing stoploss when the offset is reached. [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `fee` | Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling. <br> **Datatype:** Float (as ratio)
|
| `fee` | Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling. <br> **Datatype:** Float (as ratio)
|
||||||
| `futures_funding_rate` | User-specified funding rate to be used when historical funding rates are not available from the exchange. This does not overwrite real historical rates. It is recommended that this be set to 0 unless you are testing a specific coin and you understand how the funding rate will affect freqtrade's profit calculations. [More information here](leverage.md#unavailable-funding-rates) <br>*Defaults to None.*<br> **Datatype:** Float
|
| `unfilledtimeout.buy` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled buy order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||||
| `trading_mode` | Specifies if you want to trade regularly, trade with leverage, or trade contracts whose prices are derived from matching cryptocurrency prices. [leverage documentation](leverage.md). <br>*Defaults to `"spot"`.* <br> **Datatype:** String
|
| `unfilledtimeout.sell` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled sell order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||||
| `margin_mode` | When trading with leverage, this determines if the collateral owned by the trader will be shared or isolated to each trading pair [leverage documentation](leverage.md). <br> **Datatype:** String
|
|
||||||
| `liquidation_buffer` | A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price [leverage documentation](leverage.md). <br>*Defaults to `0.05`.* <br> **Datatype:** Float
|
|
||||||
| | **Unfilled timeout**
|
|
||||||
| `unfilledtimeout.entry` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled entry order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
|
||||||
| `unfilledtimeout.exit` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled exit order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
|
||||||
| `unfilledtimeout.unit` | Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to "seconds", "internals.process_throttle_secs" must be inferior or equal to timeout [Strategy Override](#parameters-in-the-strategy). <br> *Defaults to `minutes`.* <br> **Datatype:** String
|
| `unfilledtimeout.unit` | Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to "seconds", "internals.process_throttle_secs" must be inferior or equal to timeout [Strategy Override](#parameters-in-the-strategy). <br> *Defaults to `minutes`.* <br> **Datatype:** String
|
||||||
| `unfilledtimeout.exit_timeout_count` | How many times can exit orders time out. Once this number of timeouts is reached, an emergency exit is triggered. 0 to disable and allow unlimited order cancels. [Strategy Override](#parameters-in-the-strategy).<br>*Defaults to `0`.* <br> **Datatype:** Integer
|
| `bid_strategy.price_side` | Select the side of the spread the bot should look at to get the buy rate. [More information below](#buy-price-side).<br> *Defaults to `bid`.* <br> **Datatype:** String (either `ask` or `bid`).
|
||||||
| | **Pricing**
|
| `bid_strategy.ask_last_balance` | **Required.** Interpolate the bidding price. More information [below](#buy-price-without-orderbook-enabled).
|
||||||
| `entry_pricing.price_side` | Select the side of the spread the bot should look at to get the entry rate. [More information below](#buy-price-side).<br> *Defaults to `same`.* <br> **Datatype:** String (either `ask`, `bid`, `same` or `other`).
|
| `bid_strategy.use_order_book` | Enable buying using the rates in [Order Book Bids](#buy-price-with-orderbook-enabled). <br> **Datatype:** Boolean
|
||||||
| `entry_pricing.price_last_balance` | **Required.** Interpolate the bidding price. More information [below](#entry-price-without-orderbook-enabled).
|
| `bid_strategy.order_book_top` | Bot will use the top N rate in Order Book Bids to buy. I.e. a value of 2 will allow the bot to pick the 2nd bid rate in [Order Book Bids](#buy-price-with-orderbook-enabled). <br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
||||||
| `entry_pricing.use_order_book` | Enable entering using the rates in [Order Book Entry](#entry-price-with-orderbook-enabled). <br> *Defaults to `True`.*<br> **Datatype:** Boolean
|
| `bid_strategy. check_depth_of_market.enabled` | Do not buy if the difference of buy orders and sell orders is met in Order Book. [Check market depth](#check-depth-of-market). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `entry_pricing.order_book_top` | Bot will use the top N rate in Order Book "price_side" to enter a trade. I.e. a value of 2 will allow the bot to pick the 2nd entry in [Order Book Entry](#entry-price-with-orderbook-enabled). <br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
| `bid_strategy. check_depth_of_market.bids_to_ask_delta` | The difference ratio of buy orders and sell orders found in Order Book. A value below 1 means sell order size is greater, while value greater than 1 means buy order size is higher. [Check market depth](#check-depth-of-market) <br> *Defaults to `0`.* <br> **Datatype:** Float (as ratio)
|
||||||
| `entry_pricing. check_depth_of_market.enabled` | Do not enter if the difference of buy orders and sell orders is met in Order Book. [Check market depth](#check-depth-of-market). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `ask_strategy.price_side` | Select the side of the spread the bot should look at to get the sell rate. [More information below](#sell-price-side).<br> *Defaults to `ask`.* <br> **Datatype:** String (either `ask` or `bid`).
|
||||||
| `entry_pricing. check_depth_of_market.bids_to_ask_delta` | The difference ratio of buy orders and sell orders found in Order Book. A value below 1 means sell order size is greater, while value greater than 1 means buy order size is higher. [Check market depth](#check-depth-of-market) <br> *Defaults to `0`.* <br> **Datatype:** Float (as ratio)
|
| `ask_strategy.bid_last_balance` | Interpolate the selling price. More information [below](#sell-price-without-orderbook-enabled).
|
||||||
| `exit_pricing.price_side` | Select the side of the spread the bot should look at to get the exit rate. [More information below](#exit-price-side).<br> *Defaults to `same`.* <br> **Datatype:** String (either `ask`, `bid`, `same` or `other`).
|
| `ask_strategy.use_order_book` | Enable selling of open trades using [Order Book Asks](#sell-price-with-orderbook-enabled). <br> **Datatype:** Boolean
|
||||||
| `exit_pricing.price_last_balance` | Interpolate the exiting price. More information [below](#exit-price-without-orderbook-enabled).
|
| `ask_strategy.order_book_min` | Bot will scan from the top min to max Order Book Asks searching for a profitable rate. <br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
||||||
| `exit_pricing.use_order_book` | Enable exiting of open trades using [Order Book Exit](#exit-price-with-orderbook-enabled). <br> *Defaults to `True`.*<br> **Datatype:** Boolean
|
| `ask_strategy.order_book_max` | Bot will scan from the top min to max Order Book Asks searching for a profitable rate. <br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
||||||
| `exit_pricing.order_book_top` | Bot will use the top N rate in Order Book "price_side" to exit. I.e. a value of 2 will allow the bot to pick the 2nd ask rate in [Order Book Exit](#exit-price-with-orderbook-enabled)<br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
| `ask_strategy.use_sell_signal` | Use sell signals produced by the strategy in addition to the `minimal_roi`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
||||||
| `custom_price_max_distance_ratio` | Configure maximum distance ratio between current and custom entry or exit price. <br>*Defaults to `0.02` 2%).*<br> **Datatype:** Positive float
|
| `ask_strategy.sell_profit_only` | Wait until the bot reaches `ask_strategy.sell_profit_offset` before taking a sell decision. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| | **TODO**
|
| `ask_strategy.sell_profit_offset` | Sell-signal is only active above this value. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0`.* <br> **Datatype:** Float (as ratio)
|
||||||
| `use_exit_signal` | Use exit signals produced by the strategy in addition to the `minimal_roi`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
| `ask_strategy.ignore_roi_if_buy_signal` | Do not sell if the buy signal is still active. This setting takes preference over `minimal_roi` and `use_sell_signal`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `exit_profit_only` | Wait until the bot reaches `exit_profit_offset` before taking an exit decision. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `ask_strategy.ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used. <br> **Datatype:** Integer
|
||||||
| `exit_profit_offset` | Exit-signal is only active above this value. Only active in combination with `exit_profit_only=True`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0`.* <br> **Datatype:** Float (as ratio)
|
| `order_types` | Configure order-types depending on the action (`"buy"`, `"sell"`, `"stoploss"`, `"stoploss_on_exchange"`). [More information below](#understand-order_types). [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Dict
|
||||||
| `ignore_roi_if_entry_signal` | Do not exit if the entry signal is still active. This setting takes preference over `minimal_roi` and `use_exit_signal`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `order_time_in_force` | Configure time in force for buy and sell orders. [More information below](#understand-order_time_in_force). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
||||||
| `ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used. <br> **Datatype:** Integer
|
|
||||||
| `order_types` | Configure order-types depending on the action (`"entry"`, `"exit"`, `"stoploss"`, `"stoploss_on_exchange"`). [More information below](#understand-order_types). [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Dict
|
|
||||||
| `order_time_in_force` | Configure time in force for entry and exit orders. [More information below](#understand-order_time_in_force). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
|
||||||
| `position_adjustment_enable` | Enables the strategy to use position adjustments (additional buys or sells). [More information here](strategy-callbacks.md#adjust-trade-position). <br> [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.*<br> **Datatype:** Boolean
|
|
||||||
| `max_entry_position_adjustment` | Maximum additional order(s) for each open trade on top of the first entry Order. Set it to `-1` for unlimited additional orders. [More information here](strategy-callbacks.md#adjust-trade-position). <br> [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `-1`.*<br> **Datatype:** Positive Integer or -1
|
|
||||||
| | **Exchange**
|
|
||||||
| `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename). <br> **Datatype:** String
|
| `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename). <br> **Datatype:** String
|
||||||
| `exchange.sandbox` | Use the 'sandbox' version of the exchange, where the exchange provides a sandbox for risk-free integration. See [here](sandbox-testing.md) in more details.<br> **Datatype:** Boolean
|
| `exchange.sandbox` | Use the 'sandbox' version of the exchange, where the exchange provides a sandbox for risk-free integration. See [here](sandbox-testing.md) in more details.<br> **Datatype:** Boolean
|
||||||
| `exchange.key` | API key to use for the exchange. Only required when you are in production mode.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
| `exchange.key` | API key to use for the exchange. Only required when you are in production mode.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
||||||
| `exchange.secret` | API secret to use for the exchange. Only required when you are in production mode.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
| `exchange.secret` | API secret to use for the exchange. Only required when you are in production mode.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
||||||
| `exchange.password` | API password to use for the exchange. Only required when you are in production mode and for exchanges that use password for API requests.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
| `exchange.password` | API password to use for the exchange. Only required when you are in production mode and for exchanges that use password for API requests.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
||||||
| `exchange.uid` | API uid to use for the exchange. Only required when you are in production mode and for exchanges that use uid for API requests.<br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
|
||||||
| `exchange.pair_whitelist` | List of pairs to use by the bot for trading and to check for potential trades during backtesting. Supports regex pairs as `.*/BTC`. Not used by VolumePairList. [More information](plugins.md#pairlists-and-pairlist-handlers). <br> **Datatype:** List
|
| `exchange.pair_whitelist` | List of pairs to use by the bot for trading and to check for potential trades during backtesting. Supports regex pairs as `.*/BTC`. Not used by VolumePairList. [More information](plugins.md#pairlists-and-pairlist-handlers). <br> **Datatype:** List
|
||||||
| `exchange.pair_blacklist` | List of pairs the bot must absolutely avoid for trading and backtesting. [More information](plugins.md#pairlists-and-pairlist-handlers). <br> **Datatype:** List
|
| `exchange.pair_blacklist` | List of pairs the bot must absolutely avoid for trading and backtesting. [More information](plugins.md#pairlists-and-pairlist-handlers). <br> **Datatype:** List
|
||||||
| `exchange.ccxt_config` | Additional CCXT parameters passed to both ccxt instances (sync and async). This is usually the correct place for additional ccxt configurations. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation). Please avoid adding exchange secrets here (use the dedicated fields instead), as they may be contained in logs. <br> **Datatype:** Dict
|
| `exchange.ccxt_config` | Additional CCXT parameters passed to both ccxt instances (sync and async). This is usually the correct place for ccxt configurations. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation) <br> **Datatype:** Dict
|
||||||
| `exchange.ccxt_sync_config` | Additional CCXT parameters passed to the regular (sync) ccxt instance. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation) <br> **Datatype:** Dict
|
| `exchange.ccxt_sync_config` | Additional CCXT parameters passed to the regular (sync) ccxt instance. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation) <br> **Datatype:** Dict
|
||||||
| `exchange.ccxt_async_config` | Additional CCXT parameters passed to the async ccxt instance. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation) <br> **Datatype:** Dict
|
| `exchange.ccxt_async_config` | Additional CCXT parameters passed to the async ccxt instance. Parameters may differ from exchange to exchange and are documented in the [ccxt documentation](https://ccxt.readthedocs.io/en/latest/manual.html#instantiation) <br> **Datatype:** Dict
|
||||||
| `exchange.markets_refresh_interval` | The interval in minutes in which markets are reloaded. <br>*Defaults to `60` minutes.* <br> **Datatype:** Positive Integer
|
| `exchange.markets_refresh_interval` | The interval in minutes in which markets are reloaded. <br>*Defaults to `60` minutes.* <br> **Datatype:** Positive Integer
|
||||||
| `exchange.skip_pair_validation` | Skip pairlist validation on startup.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
| `exchange.skip_pair_validation` | Skip pairlist validation on startup.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
||||||
| `exchange.skip_open_order_update` | Skips open order updates on startup should the exchange cause problems. Only relevant in live conditions.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
| `exchange.skip_open_order_update` | Skips open order updates on startup should the exchange cause problems. Only relevant in live conditions.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
||||||
| `exchange.unknown_fee_rate` | Fallback value to use when calculating trading fees. This can be useful for exchanges which have fees in non-tradable currencies. The value provided here will be multiplied with the "fee cost".<br>*Defaults to `None`<br> **Datatype:** float
|
|
||||||
| `exchange.log_responses` | Log relevant exchange responses. For debug mode only - use with care.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
| `exchange.log_responses` | Log relevant exchange responses. For debug mode only - use with care.<br>*Defaults to `false`<br> **Datatype:** Boolean
|
||||||
|
| `edge.*` | Please refer to [edge configuration document](edge.md) for detailed explanation.
|
||||||
| `experimental.block_bad_exchanges` | Block exchanges known to not work with freqtrade. Leave on default unless you want to test if that exchange works now. <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
| `experimental.block_bad_exchanges` | Block exchanges known to not work with freqtrade. Leave on default unless you want to test if that exchange works now. <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
||||||
| | **Plugins**
|
|
||||||
| `edge.*` | Please refer to [edge configuration document](edge.md) for detailed explanation of all possible configuration options.
|
|
||||||
| `pairlists` | Define one or more pairlists to be used. [More information](plugins.md#pairlists-and-pairlist-handlers). <br>*Defaults to `StaticPairList`.* <br> **Datatype:** List of Dicts
|
| `pairlists` | Define one or more pairlists to be used. [More information](plugins.md#pairlists-and-pairlist-handlers). <br>*Defaults to `StaticPairList`.* <br> **Datatype:** List of Dicts
|
||||||
| `protections` | Define one or more protections to be used. [More information](plugins.md#protections). <br> **Datatype:** List of Dicts
|
| `protections` | Define one or more protections to be used. [More information](plugins.md#protections). <br> **Datatype:** List of Dicts
|
||||||
| | **Telegram**
|
|
||||||
| `telegram.enabled` | Enable the usage of Telegram. <br> **Datatype:** Boolean
|
| `telegram.enabled` | Enable the usage of Telegram. <br> **Datatype:** Boolean
|
||||||
| `telegram.token` | Your Telegram bot token. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
| `telegram.token` | Your Telegram bot token. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
||||||
| `telegram.chat_id` | Your personal Telegram account id. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
| `telegram.chat_id` | Your personal Telegram account id. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
||||||
| `telegram.balance_dust_level` | Dust-level (in stake currency) - currencies with a balance below this will not be shown by `/balance`. <br> **Datatype:** float
|
| `telegram.balance_dust_level` | Dust-level (in stake currency) - currencies with a balance below this will not be shown by `/balance`. <br> **Datatype:** float
|
||||||
| `telegram.reload` | Allow "reload" buttons on telegram messages. <br>*Defaults to `True`.<br> **Datatype:** boolean
|
|
||||||
| `telegram.notification_settings.*` | Detailed notification settings. Refer to the [telegram documentation](telegram-usage.md) for details.<br> **Datatype:** dictionary
|
|
||||||
| `telegram.allow_custom_messages` | Enable the sending of Telegram messages from strategies via the dataprovider.send_msg() function. <br> **Datatype:** Boolean
|
|
||||||
| | **Webhook**
|
|
||||||
| `webhook.enabled` | Enable usage of Webhook notifications <br> **Datatype:** Boolean
|
| `webhook.enabled` | Enable usage of Webhook notifications <br> **Datatype:** Boolean
|
||||||
| `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.entry` | Payload to send on entry. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.webhookbuy` | Payload to send on buy. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.entry_cancel` | Payload to send on entry order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.webhookbuycancel` | Payload to send on buy order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.entry_fill` | Payload to send on entry order filled. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.webhooksell` | Payload to send on sell. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.exit` | Payload to send on exit. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.webhooksellcancel` | Payload to send on sell order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.exit_cancel` | Payload to send on exit order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
| `webhook.webhookstatus` | Payload to send on status calls. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
||||||
| `webhook.exit_fill` | Payload to send on exit order filled. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
|
||||||
| `webhook.status` | Payload to send on status calls. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
|
|
||||||
| `webhook.allow_custom_messages` | Enable the sending of Webhook messages from strategies via the dataprovider.send_msg() function. <br> **Datatype:** Boolean
|
|
||||||
| | **Rest API / FreqUI / Producer-Consumer**
|
|
||||||
| `api_server.enabled` | Enable usage of API Server. See the [API Server documentation](rest-api.md) for more details. <br> **Datatype:** Boolean
|
| `api_server.enabled` | Enable usage of API Server. See the [API Server documentation](rest-api.md) for more details. <br> **Datatype:** Boolean
|
||||||
| `api_server.listen_ip_address` | Bind IP address. See the [API Server documentation](rest-api.md) for more details. <br> **Datatype:** IPv4
|
| `api_server.listen_ip_address` | Bind IP address. See the [API Server documentation](rest-api.md) for more details. <br> **Datatype:** IPv4
|
||||||
| `api_server.listen_port` | Bind Port. See the [API Server documentation](rest-api.md) for more details. <br>**Datatype:** Integer between 1024 and 65535
|
| `api_server.listen_port` | Bind Port. See the [API Server documentation](rest-api.md) for more details. <br>**Datatype:** Integer between 1024 and 65535
|
||||||
| `api_server.verbosity` | Logging verbosity. `info` will print all RPC Calls, while "error" will only display errors. <br>**Datatype:** Enum, either `info` or `error`. Defaults to `info`.
|
| `api_server.verbosity` | Logging verbosity. `info` will print all RPC Calls, while "error" will only display errors. <br>**Datatype:** Enum, either `info` or `error`. Defaults to `info`.
|
||||||
| `api_server.username` | Username for API server. See the [API Server documentation](rest-api.md) for more details. <br>**Keep it in secret, do not disclose publicly.**<br> **Datatype:** String
|
| `api_server.username` | Username for API server. See the [API Server documentation](rest-api.md) for more details. <br>**Keep it in secret, do not disclose publicly.**<br> **Datatype:** String
|
||||||
| `api_server.password` | Password for API server. See the [API Server documentation](rest-api.md) for more details. <br>**Keep it in secret, do not disclose publicly.**<br> **Datatype:** String
|
| `api_server.password` | Password for API server. See the [API Server documentation](rest-api.md) for more details. <br>**Keep it in secret, do not disclose publicly.**<br> **Datatype:** String
|
||||||
| `api_server.ws_token` | API token for the Message WebSocket. See the [API Server documentation](rest-api.md) for more details. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
|
|
||||||
| `bot_name` | Name of the bot. Passed via API to a client - can be shown to distinguish / name bots.<br> *Defaults to `freqtrade`*<br> **Datatype:** String
|
| `bot_name` | Name of the bot. Passed via API to a client - can be shown to distinguish / name bots.<br> *Defaults to `freqtrade`*<br> **Datatype:** String
|
||||||
| `external_message_consumer` | Enable [Producer/Consumer mode](producer-consumer.md) for more details. <br> **Datatype:** Dict
|
| `db_url` | Declares database URL to use. NOTE: This defaults to `sqlite:///tradesv3.dryrun.sqlite` if `dry_run` is `true`, and to `sqlite:///tradesv3.sqlite` for production instances. <br> **Datatype:** String, SQLAlchemy connect string
|
||||||
| | **Other**
|
|
||||||
| `initial_state` | Defines the initial application state. If set to stopped, then the bot has to be explicitly started via `/start` RPC command. <br>*Defaults to `stopped`.* <br> **Datatype:** Enum, either `stopped` or `running`
|
| `initial_state` | Defines the initial application state. If set to stopped, then the bot has to be explicitly started via `/start` RPC command. <br>*Defaults to `stopped`.* <br> **Datatype:** Enum, either `stopped` or `running`
|
||||||
| `force_entry_enable` | Enables the RPC Commands to force a Trade entry. More information below. <br> **Datatype:** Boolean
|
| `forcebuy_enable` | Enables the RPC Commands to force a buy. More information below. <br> **Datatype:** Boolean
|
||||||
| `disable_dataframe_checks` | Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. [Strategy Override](#parameters-in-the-strategy).<br> *Defaults to `False`*. <br> **Datatype:** Boolean
|
| `disable_dataframe_checks` | Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. [Strategy Override](#parameters-in-the-strategy).<br> *Defaults to `False`*. <br> **Datatype:** Boolean
|
||||||
|
| `strategy` | **Required** Defines Strategy class to use. Recommended to be set via `--strategy NAME`. <br> **Datatype:** ClassName
|
||||||
|
| `strategy_path` | Adds an additional strategy lookup path (must be a directory). <br> **Datatype:** String
|
||||||
| `internals.process_throttle_secs` | Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second. <br>*Defaults to `5` seconds.* <br> **Datatype:** Positive Integer
|
| `internals.process_throttle_secs` | Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second. <br>*Defaults to `5` seconds.* <br> **Datatype:** Positive Integer
|
||||||
| `internals.heartbeat_interval` | Print heartbeat message every N seconds. Set to 0 to disable heartbeat messages. <br>*Defaults to `60` seconds.* <br> **Datatype:** Positive Integer or 0
|
| `internals.heartbeat_interval` | Print heartbeat message every N seconds. Set to 0 to disable heartbeat messages. <br>*Defaults to `60` seconds.* <br> **Datatype:** Positive Integer or 0
|
||||||
| `internals.sd_notify` | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details. <br> **Datatype:** Boolean
|
| `internals.sd_notify` | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details. <br> **Datatype:** Boolean
|
||||||
| `strategy` | **Required** Defines Strategy class to use. Recommended to be set via `--strategy NAME`. <br> **Datatype:** ClassName
|
|
||||||
| `strategy_path` | Adds an additional strategy lookup path (must be a directory). <br> **Datatype:** String
|
|
||||||
| `recursive_strategy_search` | Set to `true` to recursively search sub-directories inside `user_data/strategies` for a strategy. <br> **Datatype:** Boolean
|
|
||||||
| `user_data_dir` | Directory containing user data. <br> *Defaults to `./user_data/`*. <br> **Datatype:** String
|
|
||||||
| `db_url` | Declares database URL to use. NOTE: This defaults to `sqlite:///tradesv3.dryrun.sqlite` if `dry_run` is `true`, and to `sqlite:///tradesv3.sqlite` for production instances. <br> **Datatype:** String, SQLAlchemy connect string
|
|
||||||
| `logfile` | Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file. <br> **Datatype:** String
|
| `logfile` | Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file. <br> **Datatype:** String
|
||||||
| `add_config_files` | Additional config files. These files will be loaded and merged with the current config file. The files are resolved relative to the initial file.<br> *Defaults to `[]`*. <br> **Datatype:** List of strings
|
| `user_data_dir` | Directory containing user data. <br> *Defaults to `./user_data/`*. <br> **Datatype:** String
|
||||||
| `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data. <br> *Defaults to `json`*. <br> **Datatype:** String
|
| `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data. <br> *Defaults to `json`*. <br> **Datatype:** String
|
||||||
| `dataformat_trades` | Data format to use to store historical trades data. <br> *Defaults to `jsongz`*. <br> **Datatype:** String
|
| `dataformat_trades` | Data format to use to store historical trades data. <br> *Defaults to `jsongz`*. <br> **Datatype:** String
|
||||||
| `reduce_df_footprint` | Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage (and decreasing train/inference timing in FreqAI). (Currently only affects FreqAI use-cases) <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
||||||
|
|
||||||
### Parameters in the strategy
|
### Parameters in the strategy
|
||||||
|
|
||||||
The following parameters can be set in the configuration file or strategy.
|
The following parameters can be set in configuration file or strategy.
|
||||||
Values set in the configuration file always overwrite values set in the strategy.
|
Values set in the configuration file always overwrite values set in the strategy.
|
||||||
|
|
||||||
* `minimal_roi`
|
* `minimal_roi`
|
||||||
* `timeframe`
|
* `timeframe`
|
||||||
* `stoploss`
|
* `stoploss`
|
||||||
* `max_open_trades`
|
|
||||||
* `trailing_stop`
|
* `trailing_stop`
|
||||||
* `trailing_stop_positive`
|
* `trailing_stop_positive`
|
||||||
* `trailing_stop_positive_offset`
|
* `trailing_stop_positive_offset`
|
||||||
@ -274,68 +157,51 @@ Values set in the configuration file always overwrite values set in the strategy
|
|||||||
* `order_time_in_force`
|
* `order_time_in_force`
|
||||||
* `unfilledtimeout`
|
* `unfilledtimeout`
|
||||||
* `disable_dataframe_checks`
|
* `disable_dataframe_checks`
|
||||||
- `use_exit_signal`
|
* `use_sell_signal` (ask_strategy)
|
||||||
* `exit_profit_only`
|
* `sell_profit_only` (ask_strategy)
|
||||||
- `exit_profit_offset`
|
* `sell_profit_offset` (ask_strategy)
|
||||||
- `ignore_roi_if_entry_signal`
|
* `ignore_roi_if_buy_signal` (ask_strategy)
|
||||||
* `ignore_buying_expired_candle_after`
|
* `ignore_buying_expired_candle_after` (ask_strategy)
|
||||||
* `position_adjustment_enable`
|
|
||||||
* `max_entry_position_adjustment`
|
|
||||||
|
|
||||||
### Configuring amount per trade
|
### Configuring amount per trade
|
||||||
|
|
||||||
There are several methods to configure how much of the stake currency the bot will use to enter a trade. All methods respect the [available balance configuration](#tradable-balance) as explained below.
|
There are several methods to configure how much of the stake currency the bot will use to enter a trade. All methods respect the [available balance configuration](#available-balance) as explained below.
|
||||||
|
|
||||||
#### Minimum trade stake
|
#### Minimum trade stake
|
||||||
|
|
||||||
The minimum stake amount will depend on exchange and pair and is usually listed in the exchange support pages.
|
The minimum stake amount will depend by exchange and pair, and is usually listed in the exchange support pages.
|
||||||
|
Assuming the minimum tradable amount for XRP/USD is 20 XRP (given by the exchange), and the price is 0.6$.
|
||||||
|
|
||||||
Assuming the minimum tradable amount for XRP/USD is 20 XRP (given by the exchange), and the price is 0.6$, the minimum stake amount to buy this pair is `20 * 0.6 ~= 12`.
|
The minimum stake amount to buy this pair is therefore `20 * 0.6 ~= 12`.
|
||||||
This exchange has also a limit on USD - where all orders must be > 10$ - which however does not apply in this case.
|
This exchange has also a limit on USD - where all orders must be > 10$ - which however does not apply in this case.
|
||||||
|
|
||||||
To guarantee safe execution, freqtrade will not allow buying with a stake-amount of 10.1$, instead, it'll make sure that there's enough space to place a stoploss below the pair (+ an offset, defined by `amount_reserve_percent`, which defaults to 5%).
|
To guarantee safe execution, freqtrade will not allow buying with a stake-amount of 10.1$, instead, it'll make sure that there's enough space to place a stoploss below the pair (+ an offset, defined by `amount_reserve_percent`, which defaults to 5%).
|
||||||
|
|
||||||
With a reserve of 5%, the minimum stake amount would be ~12.6$ (`12 * (1 + 0.05)`). If we take into account a stoploss of 10% on top of that - we'd end up with a value of ~14$ (`12.6 / (1 - 0.1)`).
|
With a reserve of 5%, the minimum stake amount would be ~12.6$ (`12 * (1 + 0.05)`). If we take in account a stoploss of 10% on top of that - we'd end up with a value of ~14$ (`12.6 / (1 - 0.1)`).
|
||||||
|
|
||||||
To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit.
|
To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit.
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange. Freqtrade adjusts the stake-amount to this value, unless it's > 30% more than the calculated/desired stake-amount - in which case the trade is rejected.
|
Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange.
|
||||||
|
|
||||||
#### Tradable balance
|
#### Available balance
|
||||||
|
|
||||||
By default, the bot assumes that the `complete amount - 1%` is at it's disposal, and when using [dynamic stake amount](#dynamic-stake-amount), it will split the complete balance into `max_open_trades` buckets per trade.
|
By default, the bot assumes that the `complete amount - 1%` is at it's disposal, and when using [dynamic stake amount](#dynamic-stake-amount), it will split the complete balance into `max_open_trades` buckets per trade.
|
||||||
Freqtrade will reserve 1% for eventual fees when entering a trade and will therefore not touch that by default.
|
Freqtrade will reserve 1% for eventual fees when entering a trade and will therefore not touch that by default.
|
||||||
|
|
||||||
You can configure the "untouched" amount by using the `tradable_balance_ratio` setting.
|
You can configure the "untouched" amount by using the `tradable_balance_ratio` setting.
|
||||||
|
|
||||||
For example, if you have 10 ETH available in your wallet on the exchange and `tradable_balance_ratio=0.5` (which is 50%), then the bot will use a maximum amount of 5 ETH for trading and considers this as an available balance. The rest of the wallet is untouched by the trades.
|
For example, if you have 10 ETH available in your wallet on the exchange and `tradable_balance_ratio=0.5` (which is 50%), then the bot will use a maximum amount of 5 ETH for trading and considers this as available balance. The rest of the wallet is untouched by the trades.
|
||||||
|
|
||||||
!!! Danger
|
|
||||||
This setting should **not** be used when running multiple bots on the same account. Please look at [Available Capital to the bot](#assign-available-capital) instead.
|
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
The `tradable_balance_ratio` setting applies to the current balance (free balance + tied up in trades). Therefore, assuming the starting balance of 1000, a configuration with `tradable_balance_ratio=0.99` will not guarantee that 10 currency units will always remain available on the exchange. For example, the free amount may reduce to 5 units if the total balance is reduced to 500 (either by a losing streak or by withdrawing balance).
|
The `tradable_balance_ratio` setting applies to the current balance (free balance + tied up in trades). Therefore, assuming the starting balance of 1000, a configuration with `tradable_balance_ratio=0.99` will not guarantee that 10 currency units will always remain available on the exchange. For example, the free amount may reduce to 5 units if the total balance is reduced to 500 (either by a losing streak, or by withdrawing balance).
|
||||||
|
|
||||||
#### Assign available Capital
|
|
||||||
|
|
||||||
To fully utilize compounding profits when using multiple bots on the same exchange account, you'll want to limit each bot to a certain starting balance.
|
|
||||||
This can be accomplished by setting `available_capital` to the desired starting balance.
|
|
||||||
|
|
||||||
Assuming your account has 10.000 USDT and you want to run 2 different strategies on this exchange.
|
|
||||||
You'd set `available_capital=5000` - granting each bot an initial capital of 5000 USDT.
|
|
||||||
The bot will then split this starting balance equally into `max_open_trades` buckets.
|
|
||||||
Profitable trades will result in increased stake-sizes for this bot - without affecting the stake-sizes of the other bot.
|
|
||||||
|
|
||||||
!!! Warning "Incompatible with `tradable_balance_ratio`"
|
|
||||||
Setting this option will replace any configuration of `tradable_balance_ratio`.
|
|
||||||
|
|
||||||
#### Amend last stake amount
|
#### Amend last stake amount
|
||||||
|
|
||||||
Assuming we have the tradable balance of 1000 USDT, `stake_amount=400`, and `max_open_trades=3`.
|
Assuming we have the tradable balance of 1000 USDT, `stake_amount=400`, and `max_open_trades=3`.
|
||||||
The bot would open 2 trades and will be unable to fill the last trading slot, since the requested 400 USDT are no longer available since 800 USDT are already tied in other trades.
|
The bot would open 2 trades, and will be unable to fill the last trading slot, since the requested 400 USDT are no longer available, since 800 USDT are already tied in other trades.
|
||||||
|
|
||||||
To overcome this, the option `amend_last_stake_amount` can be set to `True`, which will enable the bot to reduce stake_amount to the available balance to fill the last trade slot.
|
To overcome this, the option `amend_last_stake_amount` can be set to `True`, which will enable the bot to reduce stake_amount to the available balance in order to fill the last trade slot.
|
||||||
|
|
||||||
In the example above this would mean:
|
In the example above this would mean:
|
||||||
|
|
||||||
@ -363,7 +229,7 @@ For example, the bot will at most use (0.05 BTC x 3) = 0.15 BTC, assuming a conf
|
|||||||
|
|
||||||
#### Dynamic stake amount
|
#### Dynamic stake amount
|
||||||
|
|
||||||
Alternatively, you can use a dynamic stake amount, which will use the available balance on the exchange, and divide that equally by the number of allowed trades (`max_open_trades`).
|
Alternatively, you can use a dynamic stake amount, which will use the available balance on the exchange, and divide that equally by the amount of allowed trades (`max_open_trades`).
|
||||||
|
|
||||||
To configure this, set `stake_amount="unlimited"`. We also recommend to set `tradable_balance_ratio=0.99` (99%) - to keep a minimum balance for eventual fees.
|
To configure this, set `stake_amount="unlimited"`. We also recommend to set `tradable_balance_ratio=0.99` (99%) - to keep a minimum balance for eventual fees.
|
||||||
|
|
||||||
@ -381,51 +247,42 @@ To allow the bot to trade all the available `stake_currency` in your account (mi
|
|||||||
```
|
```
|
||||||
|
|
||||||
!!! Tip "Compounding profits"
|
!!! Tip "Compounding profits"
|
||||||
This configuration will allow increasing/decreasing stakes depending on the performance of the bot (lower stake if the bot is losing, higher stakes if the bot has a winning record since higher balances are available), and will result in profit compounding.
|
This configuration will allow increasing / decreasing stakes depending on the performance of the bot (lower stake if bot is loosing, higher stakes if the bot has a winning record, since higher balances are available), and will result in profit compounding.
|
||||||
|
|
||||||
!!! Note "When using Dry-Run Mode"
|
!!! Note "When using Dry-Run Mode"
|
||||||
When using `"stake_amount" : "unlimited",` in combination with Dry-Run, Backtesting or Hyperopt, the balance will be simulated starting with a stake of `dry_run_wallet` which will evolve.
|
When using `"stake_amount" : "unlimited",` in combination with Dry-Run, Backtesting or Hyperopt, the balance will be simulated starting with a stake of `dry_run_wallet` which will evolve over time.
|
||||||
It is therefore important to set `dry_run_wallet` to a sensible value (like 0.05 or 0.01 for BTC and 1000 or 100 for USDT, for example), otherwise, it may simulate trades with 100 BTC (or more) or 0.05 USDT (or less) at once - which may not correspond to your real available balance or is less than the exchange minimal limit for the order amount for the stake currency.
|
It is therefore important to set `dry_run_wallet` to a sensible value (like 0.05 or 0.01 for BTC and 1000 or 100 for USDT, for example), otherwise it may simulate trades with 100 BTC (or more) or 0.05 USDT (or less) at once - which may not correspond to your real available balance or is less than the exchange minimal limit for the order amount for the stake currency.
|
||||||
|
|
||||||
#### Dynamic stake amount with position adjustment
|
|
||||||
|
|
||||||
When you want to use position adjustment with unlimited stakes, you must also implement `custom_stake_amount` to a return a value depending on your strategy.
|
|
||||||
Typical value would be in the range of 25% - 50% of the proposed stakes, but depends highly on your strategy and how much you wish to leave into the wallet as position adjustment buffer.
|
|
||||||
|
|
||||||
For example if your position adjustment assumes it can do 2 additional buys with the same stake amounts then your buffer should be 66.6667% of the initially proposed unlimited stake amount.
|
|
||||||
|
|
||||||
Or another example if your position adjustment assumes it can do 1 additional buy with 3x the original stake amount then `custom_stake_amount` should return 25% of proposed stake amount and leave 75% for possible later position adjustments.
|
|
||||||
|
|
||||||
--8<-- "includes/pricing.md"
|
--8<-- "includes/pricing.md"
|
||||||
|
|
||||||
### Understand minimal_roi
|
### Understand minimal_roi
|
||||||
|
|
||||||
The `minimal_roi` configuration parameter is a JSON object where the key is a duration
|
The `minimal_roi` configuration parameter is a JSON object where the key is a duration
|
||||||
in minutes and the value is the minimum ROI as a ratio.
|
in minutes and the value is the minimum ROI as ratio.
|
||||||
See the example below:
|
See the example below:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"minimal_roi": {
|
"minimal_roi": {
|
||||||
"40": 0.0, # Exit after 40 minutes if the profit is not negative
|
"40": 0.0, # Sell after 40 minutes if the profit is not negative
|
||||||
"30": 0.01, # Exit after 30 minutes if there is at least 1% profit
|
"30": 0.01, # Sell after 30 minutes if there is at least 1% profit
|
||||||
"20": 0.02, # Exit after 20 minutes if there is at least 2% profit
|
"20": 0.02, # Sell after 20 minutes if there is at least 2% profit
|
||||||
"0": 0.04 # Exit immediately if there is at least 4% profit
|
"0": 0.04 # Sell immediately if there is at least 4% profit
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
Most of the strategy files already include the optimal `minimal_roi` value.
|
Most of the strategy files already include the optimal `minimal_roi` value.
|
||||||
This parameter can be set in either Strategy or Configuration file. If you use it in the configuration file, it will override the
|
This parameter can be set in either Strategy or Configuration file. If you use it in the configuration file, it will override the
|
||||||
`minimal_roi` value from the strategy file.
|
`minimal_roi` value from the strategy file.
|
||||||
If it is not set in either Strategy or Configuration, a default of 1000% `{"0": 10}` is used, and minimal ROI is disabled unless your trade generates 1000% profit.
|
If it is not set in either Strategy or Configuration, a default of 1000% `{"0": 10}` is used, and minimal roi is disabled unless your trade generates 1000% profit.
|
||||||
|
|
||||||
!!! Note "Special case to forceexit after a specific time"
|
!!! Note "Special case to forcesell after a specific time"
|
||||||
A special case presents using `"<N>": -1` as ROI. This forces the bot to exit a trade after N Minutes, no matter if it's positive or negative, so represents a time-limited force-exit.
|
A special case presents using `"<N>": -1` as ROI. This forces the bot to sell a trade after N Minutes, no matter if it's positive or negative, so represents a time-limited force-sell.
|
||||||
|
|
||||||
### Understand force_entry_enable
|
### Understand forcebuy_enable
|
||||||
|
|
||||||
The `force_entry_enable` configuration parameter enables the usage of force-enter (`/forcelong`, `/forceshort`) commands via Telegram and REST API.
|
The `forcebuy_enable` configuration parameter enables the usage of forcebuy commands via Telegram and REST API.
|
||||||
For security reasons, it's disabled by default, and freqtrade will show a warning message on startup if enabled.
|
For security reasons, it's disabled by default, and freqtrade will show a warning message on startup if enabled.
|
||||||
For example, you can send `/forceenter ETH/BTC` to the bot, which will result in freqtrade buying the pair and holds it until a regular exit-signal (ROI, stoploss, /forceexit) appears.
|
For example, you can send `/forcebuy ETH/BTC` to the bot, which will result in freqtrade buying the pair and holds it until a regular sell-signal (ROI, stoploss, /forcesell) appears.
|
||||||
|
|
||||||
This can be dangerous with some strategies, so use with care.
|
This can be dangerous with some strategies, so use with care.
|
||||||
|
|
||||||
@ -435,16 +292,16 @@ See [the telegram documentation](telegram-usage.md) for details on usage.
|
|||||||
|
|
||||||
When working with larger timeframes (for example 1h or more) and using a low `max_open_trades` value, the last candle can be processed as soon as a trade slot becomes available. When processing the last candle, this can lead to a situation where it may not be desirable to use the buy signal on that candle. For example, when using a condition in your strategy where you use a cross-over, that point may have passed too long ago for you to start a trade on it.
|
When working with larger timeframes (for example 1h or more) and using a low `max_open_trades` value, the last candle can be processed as soon as a trade slot becomes available. When processing the last candle, this can lead to a situation where it may not be desirable to use the buy signal on that candle. For example, when using a condition in your strategy where you use a cross-over, that point may have passed too long ago for you to start a trade on it.
|
||||||
|
|
||||||
In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting `ignore_buying_expired_candle_after` to a positive number, indicating the number of seconds after which the buy signal becomes expired.
|
In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting `ask_strategy.ignore_buying_expired_candle_after` to a positive number, indicating the number of seconds after which the buy signal becomes expired.
|
||||||
|
|
||||||
For example, if your strategy is using a 1h timeframe, and you only want to buy within the first 5 minutes when a new candle comes in, you can add the following configuration to your strategy:
|
For example, if your strategy is using a 1h timeframe, and you only want to buy within the first 5 minutes when a new candle comes in, you can add the following configuration to your strategy:
|
||||||
|
|
||||||
``` json
|
``` json
|
||||||
{
|
"ask_strategy":{
|
||||||
//...
|
|
||||||
"ignore_buying_expired_candle_after": 300,
|
"ignore_buying_expired_candle_after": 300,
|
||||||
|
"price_side": "bid",
|
||||||
// ...
|
// ...
|
||||||
}
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
@ -452,27 +309,29 @@ For example, if your strategy is using a 1h timeframe, and you only want to buy
|
|||||||
|
|
||||||
### Understand order_types
|
### Understand order_types
|
||||||
|
|
||||||
The `order_types` configuration parameter maps actions (`entry`, `exit`, `stoploss`, `emergency_exit`, `force_exit`, `force_entry`) to order-types (`market`, `limit`, ...) as well as configures stoploss to be on the exchange and defines stoploss on exchange update interval in seconds.
|
The `order_types` configuration parameter maps actions (`buy`, `sell`, `stoploss`, `emergencysell`, `forcesell`, `forcebuy`) to order-types (`market`, `limit`, ...) as well as configures stoploss to be on the exchange and defines stoploss on exchange update interval in seconds.
|
||||||
|
|
||||||
This allows to enter using limit orders, exit using limit-orders, and create stoplosses using market orders.
|
This allows to buy using limit orders, sell using
|
||||||
It also allows to set the
|
limit-orders, and create stoplosses using market orders. It also allows to set the
|
||||||
stoploss "on exchange" which means stoploss order would be placed immediately once the buy order is fulfilled.
|
stoploss "on exchange" which means stoploss order would be placed immediately once
|
||||||
|
the buy order is fulfilled.
|
||||||
|
|
||||||
`order_types` set in the configuration file overwrites values set in the strategy as a whole, so you need to configure the whole `order_types` dictionary in one place.
|
`order_types` set in the configuration file overwrites values set in the strategy as a whole, so you need to configure the whole `order_types` dictionary in one place.
|
||||||
|
|
||||||
If this is configured, the following 4 values (`entry`, `exit`, `stoploss` and `stoploss_on_exchange`) need to be present, otherwise, the bot will fail to start.
|
If this is configured, the following 4 values (`buy`, `sell`, `stoploss` and
|
||||||
|
`stoploss_on_exchange`) need to be present, otherwise the bot will fail to start.
|
||||||
|
|
||||||
For information on (`emergency_exit`,`force_exit`, `force_entry`, `stoploss_on_exchange`,`stoploss_on_exchange_interval`,`stoploss_on_exchange_limit_ratio`) please see stop loss documentation [stop loss on exchange](stoploss.md)
|
For information on (`emergencysell`,`forcesell`, `forcebuy`, `stoploss_on_exchange`,`stoploss_on_exchange_interval`,`stoploss_on_exchange_limit_ratio`) please see stop loss documentation [stop loss on exchange](stoploss.md)
|
||||||
|
|
||||||
Syntax for Strategy:
|
Syntax for Strategy:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
order_types = {
|
order_types = {
|
||||||
"entry": "limit",
|
"buy": "limit",
|
||||||
"exit": "limit",
|
"sell": "limit",
|
||||||
"emergency_exit": "market",
|
"emergencysell": "market",
|
||||||
"force_entry": "market",
|
"forcebuy": "market",
|
||||||
"force_exit": "market",
|
"forcesell": "market",
|
||||||
"stoploss": "market",
|
"stoploss": "market",
|
||||||
"stoploss_on_exchange": False,
|
"stoploss_on_exchange": False,
|
||||||
"stoploss_on_exchange_interval": 60,
|
"stoploss_on_exchange_interval": 60,
|
||||||
@ -484,11 +343,11 @@ Configuration:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
"order_types": {
|
"order_types": {
|
||||||
"entry": "limit",
|
"buy": "limit",
|
||||||
"exit": "limit",
|
"sell": "limit",
|
||||||
"emergency_exit": "market",
|
"emergencysell": "market",
|
||||||
"force_entry": "market",
|
"forcebuy": "market",
|
||||||
"force_exit": "market",
|
"forcesell": "market",
|
||||||
"stoploss": "market",
|
"stoploss": "market",
|
||||||
"stoploss_on_exchange": false,
|
"stoploss_on_exchange": false,
|
||||||
"stoploss_on_exchange_interval": 60
|
"stoploss_on_exchange_interval": 60
|
||||||
@ -511,7 +370,7 @@ Configuration:
|
|||||||
If `stoploss_on_exchange` is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.
|
If `stoploss_on_exchange` is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.
|
||||||
|
|
||||||
!!! Warning "Warning: stoploss_on_exchange failures"
|
!!! Warning "Warning: stoploss_on_exchange failures"
|
||||||
If stoploss on exchange creation fails for some reason, then an "emergency exit" is initiated. By default, this will exit the trade using a market order. The order-type for the emergency-exit can be changed by setting the `emergency_exit` value in the `order_types` dictionary - however, this is not advised.
|
If stoploss on exchange creation fails for some reason, then an "emergency sell" is initiated. By default, this will sell the asset using a market order. The order-type for the emergency-sell can be changed by setting the `emergencysell` value in the `order_types` dictionary - however this is not advised.
|
||||||
|
|
||||||
### Understand order_time_in_force
|
### Understand order_time_in_force
|
||||||
|
|
||||||
@ -521,41 +380,73 @@ is executed on the exchange. Three commonly used time in force are:
|
|||||||
**GTC (Good Till Canceled):**
|
**GTC (Good Till Canceled):**
|
||||||
|
|
||||||
This is most of the time the default time in force. It means the order will remain
|
This is most of the time the default time in force. It means the order will remain
|
||||||
on exchange till it is cancelled by the user. It can be fully or partially fulfilled.
|
on exchange till it is canceled by user. It can be fully or partially fulfilled.
|
||||||
If partially fulfilled, the remaining will stay on the exchange till cancelled.
|
If partially fulfilled, the remaining will stay on the exchange till cancelled.
|
||||||
|
|
||||||
**FOK (Fill Or Kill):**
|
**FOK (Fill Or Kill):**
|
||||||
|
|
||||||
It means if the order is not executed immediately AND fully then it is cancelled by the exchange.
|
It means if the order is not executed immediately AND fully then it is canceled by the exchange.
|
||||||
|
|
||||||
**IOC (Immediate Or Canceled):**
|
**IOC (Immediate Or Canceled):**
|
||||||
|
|
||||||
It is the same as FOK (above) except it can be partially fulfilled. The remaining part
|
It is the same as FOK (above) except it can be partially fulfilled. The remaining part
|
||||||
is automatically cancelled by the exchange.
|
is automatically cancelled by the exchange.
|
||||||
|
|
||||||
**PO (Post only):**
|
The `order_time_in_force` parameter contains a dict with buy and sell time in force policy values.
|
||||||
|
|
||||||
Post only order. The order is either placed as a maker order, or it is canceled.
|
|
||||||
This means the order must be placed on orderbook for at at least time in an unfilled state.
|
|
||||||
|
|
||||||
#### time_in_force config
|
|
||||||
|
|
||||||
The `order_time_in_force` parameter contains a dict with entry and exit time in force policy values.
|
|
||||||
This can be set in the configuration file or in the strategy.
|
This can be set in the configuration file or in the strategy.
|
||||||
Values set in the configuration file overwrites values set in the strategy.
|
Values set in the configuration file overwrites values set in the strategy.
|
||||||
|
|
||||||
The possible values are: `GTC` (default), `FOK` or `IOC`.
|
The possible values are: `gtc` (default), `fok` or `ioc`.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
"order_time_in_force": {
|
"order_time_in_force": {
|
||||||
"entry": "GTC",
|
"buy": "gtc",
|
||||||
"exit": "GTC"
|
"sell": "gtc"
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
This is ongoing work. For now, it is supported only for binance, gate and kucoin.
|
This is an ongoing work. For now it is supported only for binance.
|
||||||
Please don't change the default value unless you know what you are doing and have researched the impact of using different values for your particular exchange.
|
Please don't change the default value unless you know what you are doing and have researched the impact of using different values.
|
||||||
|
|
||||||
|
### Exchange configuration
|
||||||
|
|
||||||
|
Freqtrade is based on [CCXT library](https://github.com/ccxt/ccxt) that supports over 100 cryptocurrency
|
||||||
|
exchange markets and trading APIs. The complete up-to-date list can be found in the
|
||||||
|
[CCXT repo homepage](https://github.com/ccxt/ccxt/tree/master/python).
|
||||||
|
However, the bot was tested by the development team with only Bittrex, Binance and Kraken,
|
||||||
|
so the these are the only officially supported exchanges:
|
||||||
|
|
||||||
|
- [Bittrex](https://bittrex.com/): "bittrex"
|
||||||
|
- [Binance](https://www.binance.com/): "binance"
|
||||||
|
- [Kraken](https://kraken.com/): "kraken"
|
||||||
|
|
||||||
|
Feel free to test other exchanges and submit your PR to improve the bot.
|
||||||
|
|
||||||
|
Some exchanges require special configuration, which can be found on the [Exchange-specific Notes](exchanges.md) documentation page.
|
||||||
|
|
||||||
|
#### Sample exchange configuration
|
||||||
|
|
||||||
|
A exchange configuration for "binance" would look as follows:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"exchange": {
|
||||||
|
"name": "binance",
|
||||||
|
"key": "your_exchange_key",
|
||||||
|
"secret": "your_exchange_secret",
|
||||||
|
"ccxt_config": {"enableRateLimit": true},
|
||||||
|
"ccxt_async_config": {
|
||||||
|
"enableRateLimit": true,
|
||||||
|
"rateLimit": 200
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
This configuration enables binance, as well as rate limiting to avoid bans from the exchange.
|
||||||
|
`"rateLimit": 200` defines a wait-event of 0.2s between each call. This can also be completely disabled by setting `"enableRateLimit"` to false.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Optimal settings for rate limiting depend on the exchange and the size of the whitelist, so an ideal parameter will vary on many other settings.
|
||||||
|
We try to provide sensible defaults per exchange where possible, if you encounter bans please make sure that `"enableRateLimit"` is enabled and increase the `"rateLimit"` parameter step by step.
|
||||||
|
|
||||||
### What values can be used for fiat_display_currency?
|
### What values can be used for fiat_display_currency?
|
||||||
|
|
||||||
@ -568,7 +459,7 @@ The valid values 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"
|
"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"
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition to fiat currencies, a range of crypto currencies is supported.
|
In addition to fiat currencies, a range of cryto currencies are supported.
|
||||||
|
|
||||||
The valid values are:
|
The valid values are:
|
||||||
|
|
||||||
@ -579,7 +470,7 @@ The valid values are:
|
|||||||
## Using Dry-run mode
|
## Using Dry-run mode
|
||||||
|
|
||||||
We recommend starting the bot in the Dry-run mode to see how your bot will
|
We recommend starting the bot in the Dry-run mode to see how your bot will
|
||||||
behave and what is the performance of your strategy. In the Dry-run mode, the
|
behave and what is the performance of your strategy. In the Dry-run mode the
|
||||||
bot does not engage your money. It only runs a live simulation without
|
bot does not engage your money. It only runs a live simulation without
|
||||||
creating trades on the exchange.
|
creating trades on the exchange.
|
||||||
|
|
||||||
@ -595,17 +486,17 @@ creating trades on the exchange.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "bittrex",
|
"name": "bittrex",
|
||||||
"key": "key",
|
"key": "key",
|
||||||
"secret": "secret",
|
"secret": "secret",
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you will be happy with your bot performance running in the Dry-run mode, you can switch it to production mode.
|
Once you will be happy with your bot performance running in the Dry-run mode, you can switch it to production mode.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
A simulated wallet is available during dry-run mode and will assume a starting capital of `dry_run_wallet` (defaults to 1000).
|
A simulated wallet is available during dry-run mode, and will assume a starting capital of `dry_run_wallet` (defaults to 1000).
|
||||||
|
|
||||||
### Considerations for dry-run
|
### Considerations for dry-run
|
||||||
|
|
||||||
@ -613,21 +504,20 @@ Once you will be happy with your bot performance running in the Dry-run mode, yo
|
|||||||
* Wallets (`/balance`) are simulated based on `dry_run_wallet`.
|
* Wallets (`/balance`) are simulated based on `dry_run_wallet`.
|
||||||
* Orders are simulated, and will not be posted to the exchange.
|
* Orders are simulated, and will not be posted to the exchange.
|
||||||
* Market orders fill based on orderbook volume the moment the order is placed.
|
* Market orders fill based on orderbook volume the moment the order is placed.
|
||||||
* Limit orders fill once the price reaches the defined level - or time out based on `unfilledtimeout` settings.
|
* Limit orders fill once price reaches the defined level - or time out based on `unfilledtimeout` settings.
|
||||||
* In combination with `stoploss_on_exchange`, the stop_loss price is assumed to be filled.
|
* In combination with `stoploss_on_exchange`, the stop_loss price is assumed to be filled.
|
||||||
* Open orders (not trades, which are stored in the database) are kept open after bot restarts, with the assumption that they were not filled while being offline.
|
* Open orders (not trades, which are stored in the database) are reset on bot restart.
|
||||||
|
|
||||||
## Switch to production mode
|
## Switch to production mode
|
||||||
|
|
||||||
In production mode, the bot will engage your money. Be careful, since a wrong strategy can lose all your money.
|
In production mode, the bot will engage your money. Be careful, since a wrong
|
||||||
Be aware of what you are doing when you run it in production mode.
|
strategy can lose all your money. Be aware of what you are doing when
|
||||||
|
you run it in production mode.
|
||||||
When switching to Production mode, please make sure to use a different / fresh database to avoid dry-run trades messing with your exchange money and eventually tainting your statistics.
|
|
||||||
|
|
||||||
### Setup your exchange account
|
### Setup your exchange account
|
||||||
|
|
||||||
You will need to create API Keys (usually you get `key` and `secret`, some exchanges require an additional `password`) from the Exchange website and you'll need to insert this into the appropriate fields in the configuration or when asked by the `freqtrade new-config` command.
|
You will need to create API Keys (usually you get `key` and `secret`, some exchanges require an additional `password`) from the Exchange website and you'll need to insert this into the appropriate fields in the configuration or when asked by the `freqtrade new-config` command.
|
||||||
API Keys are usually only required for live trading (trading for real money, bot running in "production mode", executing real orders on the exchange) and are not required for the bot running in dry-run (trade simulation) mode. When you set up the bot in dry-run mode, you may fill these fields with empty values.
|
API Keys are usually only required for live trading (trading for real money, bot running in "production mode", executing real orders on the exchange) and are not required for the bot running in dry-run (trade simulation) mode. When you setup the bot in dry-run mode, you may fill these fields with empty values.
|
||||||
|
|
||||||
### To switch your bot in production mode
|
### To switch your bot in production mode
|
||||||
|
|
||||||
@ -639,7 +529,7 @@ API Keys are usually only required for live trading (trading for real money, bot
|
|||||||
"dry_run": false,
|
"dry_run": false,
|
||||||
```
|
```
|
||||||
|
|
||||||
**Insert your Exchange API key (change them by fake API keys):**
|
**Insert your Exchange API key (change them by fake api keys):**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -657,7 +547,7 @@ API Keys are usually only required for live trading (trading for real money, bot
|
|||||||
You should also make sure to read the [Exchanges](exchanges.md) section of the documentation to be aware of potential configuration details specific to your exchange.
|
You should also make sure to read the [Exchanges](exchanges.md) section of the documentation to be aware of potential configuration details specific to your exchange.
|
||||||
|
|
||||||
!!! Hint "Keep your secrets secret"
|
!!! Hint "Keep your secrets secret"
|
||||||
To keep your secrets secret, we recommend using a 2nd configuration for your API keys.
|
To keep your secrets secret, we recommend to use a 2nd configuration for your API keys.
|
||||||
Simply use the above snippet in a new configuration file (e.g. `config-private.json`) and keep your settings in this file.
|
Simply use the above snippet in a new configuration file (e.g. `config-private.json`) and keep your settings in this file.
|
||||||
You can then start the bot with `freqtrade trade --config user_data/config.json --config user_data/config-private.json <...>` to have your keys loaded.
|
You can then start the bot with `freqtrade trade --config user_data/config.json --config user_data/config-private.json <...>` to have your keys loaded.
|
||||||
|
|
||||||
@ -665,8 +555,17 @@ You should also make sure to read the [Exchanges](exchanges.md) section of the d
|
|||||||
|
|
||||||
### Using proxy with Freqtrade
|
### Using proxy with Freqtrade
|
||||||
|
|
||||||
To use a proxy with freqtrade, export your proxy settings using the variables `"HTTP_PROXY"` and `"HTTPS_PROXY"` set to the appropriate values.
|
To use a proxy with freqtrade, add the kwarg `"aiohttp_trust_env"=true` to the `"ccxt_async_kwargs"` dict in the exchange section of the configuration.
|
||||||
This will have the proxy settings applied to everything (telegram, coingecko, ...) **except** for exchange requests.
|
|
||||||
|
An example for this can be found in `config_full.json.example`
|
||||||
|
|
||||||
|
``` json
|
||||||
|
"ccxt_async_config": {
|
||||||
|
"aiohttp_trust_env": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, export your proxy settings using the variables `"HTTP_PROXY"` and `"HTTPS_PROXY"` set to the appropriate values
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
export HTTP_PROXY="http://addr:port"
|
export HTTP_PROXY="http://addr:port"
|
||||||
@ -674,24 +573,6 @@ export HTTPS_PROXY="http://addr:port"
|
|||||||
freqtrade
|
freqtrade
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Proxy exchange requests
|
|
||||||
|
|
||||||
To use a proxy for exchange connections - you will have to define the proxies as part of the ccxt configuration.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
{
|
|
||||||
"exchange": {
|
|
||||||
"ccxt_config": {
|
|
||||||
"aiohttp_proxy": "http://addr:port",
|
|
||||||
"proxies": {
|
|
||||||
"http": "http://addr:port",
|
|
||||||
"https": "http://addr:port"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Next step
|
## Next step
|
||||||
|
|
||||||
Now you have configured your config.json, the next step is to [start your bot](bot-usage.md).
|
Now you have configured your config.json, the next step is to [start your bot](bot-usage.md).
|
||||||
|
@ -5,7 +5,7 @@ You can analyze the results of backtests and trading history easily using Jupyte
|
|||||||
## Quick start with docker
|
## Quick start with docker
|
||||||
|
|
||||||
Freqtrade provides a docker-compose file which starts up a jupyter lab server.
|
Freqtrade provides a docker-compose file which starts up a jupyter lab server.
|
||||||
You can run this server using the following command: `docker compose -f docker/docker-compose-jupyter.yml up`
|
You can run this server using the following command: `docker-compose -f docker/docker-compose-jupyter.yml up`
|
||||||
|
|
||||||
This will create a dockercontainer running jupyter lab, which will be accessible using `https://127.0.0.1:8888/lab`.
|
This will create a dockercontainer running jupyter lab, which will be accessible using `https://127.0.0.1:8888/lab`.
|
||||||
Please use the link that's printed in the console after startup for simplified login.
|
Please use the link that's printed in the console after startup for simplified login.
|
||||||
@ -50,22 +50,19 @@ Repetitive tasks | Shell scripts
|
|||||||
Data analysis & visualization | Notebook
|
Data analysis & visualization | Notebook
|
||||||
|
|
||||||
1. Use the CLI to
|
1. Use the CLI to
|
||||||
|
|
||||||
* download historical data
|
* download historical data
|
||||||
* run a backtest
|
* run a backtest
|
||||||
* run with real-time data
|
* run with real-time data
|
||||||
* export results
|
* export results
|
||||||
|
|
||||||
1. Collect these actions in shell scripts
|
1. Collect these actions in shell scripts
|
||||||
|
|
||||||
* save complicated commands with arguments
|
* save complicated commands with arguments
|
||||||
* execute multi-step operations
|
* execute multi-step operations
|
||||||
* automate testing strategies and preparing data for analysis
|
* automate testing strategies and preparing data for analysis
|
||||||
|
|
||||||
1. Use a notebook to
|
1. Use a notebook to
|
||||||
|
|
||||||
* visualize data
|
* visualize data
|
||||||
* mangle and plot to generate insights
|
* munge and plot to generate insights
|
||||||
|
|
||||||
## Example utility snippets
|
## Example utility snippets
|
||||||
|
|
||||||
@ -83,7 +80,7 @@ from pathlib import Path
|
|||||||
project_root = "somedir/freqtrade"
|
project_root = "somedir/freqtrade"
|
||||||
i=0
|
i=0
|
||||||
try:
|
try:
|
||||||
os.chdir(project_root)
|
os.chdirdir(project_root)
|
||||||
assert Path('LICENSE').is_file()
|
assert Path('LICENSE').is_file()
|
||||||
except:
|
except:
|
||||||
while i<4 and (not Path('LICENSE').is_file()):
|
while i<4 and (not Path('LICENSE').is_file()):
|
||||||
@ -122,6 +119,5 @@ Best avoid relative paths, since this starts at the storage location of the jupy
|
|||||||
|
|
||||||
* [Strategy debugging](strategy_analysis_example.md) - also available as Jupyter notebook (`user_data/notebooks/strategy_analysis_example.ipynb`)
|
* [Strategy debugging](strategy_analysis_example.md) - also available as Jupyter notebook (`user_data/notebooks/strategy_analysis_example.ipynb`)
|
||||||
* [Plotting](plotting.md)
|
* [Plotting](plotting.md)
|
||||||
* [Tag Analysis](advanced-backtesting.md)
|
|
||||||
|
|
||||||
Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.
|
Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.
|
||||||
|
@ -11,7 +11,7 @@ Otherwise `--exchange` becomes mandatory.
|
|||||||
You can use a relative timerange (`--days 20`) or an absolute starting point (`--timerange 20200101-`). For incremental downloads, the relative approach should be used.
|
You can use a relative timerange (`--days 20`) or an absolute starting point (`--timerange 20200101-`). For incremental downloads, the relative approach should be used.
|
||||||
|
|
||||||
!!! Tip "Tip: Updating existing data"
|
!!! Tip "Tip: Updating existing data"
|
||||||
If you already have backtesting data available in your data-directory and would like to refresh this data up to today, freqtrade will automatically calculate the data missing for the existing pairs and the download will occur from the latest available point until "now", neither --days or --timerange parameters are required. Freqtrade will keep the available data and only download the missing data.
|
If you already have backtesting data available in your data-directory and would like to refresh this data up to today, do not use `--days` or `--timerange` parameters. Freqtrade will keep the available data and only download the missing data.
|
||||||
If you are updating existing data after inserting new pairs that you have no data for, use `--new-pairs-days xx` parameter. Specified number of days will be downloaded for new pairs while old pairs will be updated with missing data only.
|
If you are updating existing data after inserting new pairs that you have no data for, use `--new-pairs-days xx` parameter. Specified number of days will be downloaded for new pairs while old pairs will be updated with missing data only.
|
||||||
If you use `--days xx` parameter alone - data for specified number of days will be downloaded for _all_ pairs. Be careful, if specified number of days is smaller than gap between now and last downloaded candle - freqtrade will delete all existing data to avoid gaps in candle data.
|
If you use `--days xx` parameter alone - data for specified number of days will be downloaded for _all_ pairs. Be careful, if specified number of days is smaller than gap between now and last downloaded candle - freqtrade will delete all existing data to avoid gaps in candle data.
|
||||||
|
|
||||||
@ -22,27 +22,22 @@ usage: freqtrade download-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
|||||||
[-d PATH] [--userdir PATH]
|
[-d PATH] [--userdir PATH]
|
||||||
[-p PAIRS [PAIRS ...]] [--pairs-file FILE]
|
[-p PAIRS [PAIRS ...]] [--pairs-file FILE]
|
||||||
[--days INT] [--new-pairs-days INT]
|
[--days INT] [--new-pairs-days INT]
|
||||||
[--include-inactive-pairs]
|
|
||||||
[--timerange TIMERANGE] [--dl-trades]
|
[--timerange TIMERANGE] [--dl-trades]
|
||||||
[--exchange EXCHANGE]
|
[--exchange EXCHANGE]
|
||||||
[-t TIMEFRAMES [TIMEFRAMES ...]] [--erase]
|
[-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]]
|
||||||
[--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]
|
[--erase]
|
||||||
|
[--data-format-ohlcv {json,jsongz,hdf5}]
|
||||||
[--data-format-trades {json,jsongz,hdf5}]
|
[--data-format-trades {json,jsongz,hdf5}]
|
||||||
[--trading-mode {spot,margin,futures}]
|
|
||||||
[--prepend]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Limit command to these pairs. Pairs are space-
|
Limit command to these pairs. Pairs are space-
|
||||||
separated.
|
separated.
|
||||||
--pairs-file FILE File containing a list of pairs. Takes precedence over
|
--pairs-file FILE File containing a list of pairs to download.
|
||||||
--pairs or pairs configured in the configuration.
|
|
||||||
--days INT Download data for given number of days.
|
--days INT Download data for given number of days.
|
||||||
--new-pairs-days INT Download data of new pairs for given number of days.
|
--new-pairs-days INT Download data of new pairs for given number of days.
|
||||||
Default: `None`.
|
Default: `None`.
|
||||||
--include-inactive-pairs
|
|
||||||
Also download data from inactive pairs.
|
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
--dl-trades Download trades instead of OHLCV data. The bot will
|
--dl-trades Download trades instead of OHLCV data. The bot will
|
||||||
@ -50,20 +45,17 @@ optional arguments:
|
|||||||
as --timeframes/-t.
|
as --timeframes/-t.
|
||||||
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
||||||
config is provided.
|
config is provided.
|
||||||
-t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]
|
-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...], --timeframes {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]
|
||||||
Specify which tickers to download. Space-separated
|
Specify which tickers to download. Space-separated
|
||||||
list. Default: `1m 5m`.
|
list. Default: `1m 5m`.
|
||||||
--erase Clean all existing data for the selected
|
--erase Clean all existing data for the selected
|
||||||
exchange/pairs/timeframes.
|
exchange/pairs/timeframes.
|
||||||
--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}
|
--data-format-ohlcv {json,jsongz,hdf5}
|
||||||
Storage format for downloaded candle (OHLCV) data.
|
Storage format for downloaded candle (OHLCV) data.
|
||||||
(default: `json`).
|
(default: `None`).
|
||||||
--data-format-trades {json,jsongz,hdf5}
|
--data-format-trades {json,jsongz,hdf5}
|
||||||
Storage format for downloaded trades data. (default:
|
Storage format for downloaded trades data. (default:
|
||||||
`jsongz`).
|
`None`).
|
||||||
--trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}
|
|
||||||
Select Trading mode
|
|
||||||
--prepend Allow data prepending. (Data-appending is disabled)
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -76,7 +68,7 @@ Common arguments:
|
|||||||
`userdir/config.json` or `config.json` whichever
|
`userdir/config.json` or `config.json` whichever
|
||||||
exists). Multiple --config options may be used. Can be
|
exists). Multiple --config options may be used. Can be
|
||||||
set to `-` to read config from stdin.
|
set to `-` to read config from stdin.
|
||||||
-d PATH, --datadir PATH, --data-dir PATH
|
-d PATH, --datadir PATH
|
||||||
Path to directory with historical backtesting data.
|
Path to directory with historical backtesting data.
|
||||||
--userdir PATH, --user-data-dir PATH
|
--userdir PATH, --user-data-dir PATH
|
||||||
Path to userdata directory.
|
Path to userdata directory.
|
||||||
@ -88,107 +80,18 @@ Common arguments:
|
|||||||
|
|
||||||
For that reason, `download-data` does not care about the "startup-period" defined in a strategy. It's up to the user to download additional days if the backtest should start at a specific point in time (while respecting startup period).
|
For that reason, `download-data` does not care about the "startup-period" defined in a strategy. It's up to the user to download additional days if the backtest should start at a specific point in time (while respecting startup period).
|
||||||
|
|
||||||
### Pairs file
|
|
||||||
|
|
||||||
In alternative to the whitelist from `config.json`, a `pairs.json` file can be used.
|
|
||||||
If you are using Binance for example:
|
|
||||||
|
|
||||||
- create a directory `user_data/data/binance` and copy or create the `pairs.json` file in that directory.
|
|
||||||
- update the `pairs.json` file to contain the currency pairs you are interested in.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
mkdir -p user_data/data/binance
|
|
||||||
touch user_data/data/binance/pairs.json
|
|
||||||
```
|
|
||||||
|
|
||||||
The format of the `pairs.json` file is a simple json list.
|
|
||||||
Mixing different stake-currencies is allowed for this file, since it's only used for downloading.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
[
|
|
||||||
"ETH/BTC",
|
|
||||||
"ETH/USDT",
|
|
||||||
"BTC/USDT",
|
|
||||||
"XRP/ETH"
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Tip "Downloading all data for one quote currency"
|
|
||||||
Often, you'll want to download data for all pairs of a specific quote-currency. In such cases, you can use the following shorthand:
|
|
||||||
`freqtrade download-data --exchange binance --pairs .*/USDT <...>`. The provided "pairs" string will be expanded to contain all active pairs on the exchange.
|
|
||||||
To also download data for inactive (delisted) pairs, add `--include-inactive-pairs` to the command.
|
|
||||||
|
|
||||||
??? Note "Permission denied errors"
|
|
||||||
If your configuration directory `user_data` was made by docker, you may get the following error:
|
|
||||||
|
|
||||||
```
|
|
||||||
cp: cannot create regular file 'user_data/data/binance/pairs.json': Permission denied
|
|
||||||
```
|
|
||||||
|
|
||||||
You can fix the permissions of your user-data directory as follows:
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo chown -R $UID:$GID user_data
|
|
||||||
```
|
|
||||||
|
|
||||||
### Start download
|
|
||||||
|
|
||||||
Then run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade download-data --exchange binance
|
|
||||||
```
|
|
||||||
|
|
||||||
This will download historical candle (OHLCV) data for all the currency pairs you defined in `pairs.json`.
|
|
||||||
|
|
||||||
Alternatively, specify the pairs directly
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT
|
|
||||||
```
|
|
||||||
|
|
||||||
or as regex (to download all active USDT pairs)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade download-data --exchange binance --pairs .*/USDT
|
|
||||||
```
|
|
||||||
|
|
||||||
### Other Notes
|
|
||||||
|
|
||||||
- To use a different directory than the exchange specific default, use `--datadir user_data/data/some_directory`.
|
|
||||||
- To change the exchange used to download the historical data from, please use a different configuration file (you'll probably need to adjust rate limits etc.)
|
|
||||||
- To use `pairs.json` from some other directory, use `--pairs-file some_other_dir/pairs.json`.
|
|
||||||
- To download historical candle (OHLCV) data for only 10 days, use `--days 10` (defaults to 30 days).
|
|
||||||
- To download historical candle (OHLCV) data from a fixed starting point, use `--timerange 20200101-` - which will download all data from January 1st, 2020.
|
|
||||||
- Use `--timeframes` to specify what timeframe download the historical candle (OHLCV) data for. Default is `--timeframes 1m 5m` which will download 1-minute and 5-minute data.
|
|
||||||
- To use exchange, timeframe and list of pairs as defined in your configuration file, use the `-c/--config` option. With this, the script uses the whitelist defined in the config as the list of currency pairs to download data for and does not require the pairs.json file. You can combine `-c/--config` with most other options.
|
|
||||||
|
|
||||||
#### Download additional data before the current timerange
|
|
||||||
|
|
||||||
Assuming you downloaded all data from 2022 (`--timerange 20220101-`) - but you'd now like to also backtest with earlier data.
|
|
||||||
You can do so by using the `--prepend` flag, combined with `--timerange` - specifying an end-date.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT --prepend --timerange 20210101-20220101
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Freqtrade will ignore the end-date in this mode if data is available, updating the end-date to the existing data start point.
|
|
||||||
|
|
||||||
### Data format
|
### Data format
|
||||||
|
|
||||||
Freqtrade currently supports the following data-formats:
|
Freqtrade currently supports 3 data-formats for both OHLCV and trades data:
|
||||||
|
|
||||||
* `json` - plain "text" json files
|
* `json` (plain "text" json files)
|
||||||
* `jsongz` - a gzip-zipped version of json files
|
* `jsongz` (a gzip-zipped version of json files)
|
||||||
* `hdf5` - a high performance datastore
|
* `hdf5` (a high performance datastore)
|
||||||
* `feather` - a dataformat based on Apache Arrow (OHLCV only)
|
|
||||||
* `parquet` - columnar datastore (OHLCV only)
|
|
||||||
|
|
||||||
By default, OHLCV data is stored as `json` data, while trades data is stored as `jsongz` data.
|
By default, OHLCV data is stored as `json` data, while trades data is stored as `jsongz` data.
|
||||||
|
|
||||||
This can be changed via the `--data-format-ohlcv` and `--data-format-trades` command line arguments respectively.
|
This can be changed via the `--data-format-ohlcv` and `--data-format-trades` command line arguments respectively.
|
||||||
To persist this change, you should also add the following snippet to your configuration, so you don't have to insert the above arguments each time:
|
To persist this change, you can should also add the following snippet to your configuration, so you don't have to insert the above arguments each time:
|
||||||
|
|
||||||
``` jsonc
|
``` jsonc
|
||||||
// ...
|
// ...
|
||||||
@ -202,75 +105,30 @@ If the default data-format has been changed during download, then the keys `data
|
|||||||
!!! Note
|
!!! Note
|
||||||
You can convert between data-formats using the [convert-data](#sub-command-convert-data) and [convert-trade-data](#sub-command-convert-trade-data) methods.
|
You can convert between data-formats using the [convert-data](#sub-command-convert-data) and [convert-trade-data](#sub-command-convert-trade-data) methods.
|
||||||
|
|
||||||
#### Dataformat comparison
|
|
||||||
|
|
||||||
The following comparisons have been made with the following data, and by using the linux `time` command.
|
|
||||||
|
|
||||||
```
|
|
||||||
Found 6 pair / timeframe combinations.
|
|
||||||
+----------+-------------+--------+---------------------+---------------------+
|
|
||||||
| Pair | Timeframe | Type | From | To |
|
|
||||||
|----------+-------------+--------+---------------------+---------------------|
|
|
||||||
| BTC/USDT | 5m | spot | 2017-08-17 04:00:00 | 2022-09-13 19:25:00 |
|
|
||||||
| ETH/USDT | 1m | spot | 2017-08-17 04:00:00 | 2022-09-13 19:26:00 |
|
|
||||||
| BTC/USDT | 1m | spot | 2017-08-17 04:00:00 | 2022-09-13 19:30:00 |
|
|
||||||
| XRP/USDT | 5m | spot | 2018-05-04 08:10:00 | 2022-09-13 19:15:00 |
|
|
||||||
| XRP/USDT | 1m | spot | 2018-05-04 08:11:00 | 2022-09-13 19:22:00 |
|
|
||||||
| ETH/USDT | 5m | spot | 2017-08-17 04:00:00 | 2022-09-13 19:20:00 |
|
|
||||||
+----------+-------------+--------+---------------------+---------------------+
|
|
||||||
```
|
|
||||||
|
|
||||||
Timings have been taken in a not very scientific way with the following command, which forces reading the data into memory.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
time freqtrade list-data --show-timerange --data-format-ohlcv <dataformat>
|
|
||||||
```
|
|
||||||
|
|
||||||
| Format | Size | timing |
|
|
||||||
|------------|-------------|-------------|
|
|
||||||
| `json` | 149Mb | 25.6s |
|
|
||||||
| `jsongz` | 39Mb | 27s |
|
|
||||||
| `hdf5` | 145Mb | 3.9s |
|
|
||||||
| `feather` | 72Mb | 3.5s |
|
|
||||||
| `parquet` | 83Mb | 3.8s |
|
|
||||||
|
|
||||||
Size has been taken from the BTC/USDT 1m spot combination for the timerange specified above.
|
|
||||||
|
|
||||||
To have a best performance/size mix, we recommend the use of either feather or parquet.
|
|
||||||
|
|
||||||
#### Sub-command convert data
|
#### Sub-command convert data
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: freqtrade convert-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
usage: freqtrade convert-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
||||||
[-d PATH] [--userdir PATH]
|
[-d PATH] [--userdir PATH]
|
||||||
[-p PAIRS [PAIRS ...]] --format-from
|
[-p PAIRS [PAIRS ...]] --format-from
|
||||||
{json,jsongz,hdf5,feather,parquet} --format-to
|
{json,jsongz,hdf5} --format-to
|
||||||
{json,jsongz,hdf5,feather,parquet} [--erase]
|
{json,jsongz,hdf5} [--erase]
|
||||||
[--exchange EXCHANGE]
|
[-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]]
|
||||||
[-t TIMEFRAMES [TIMEFRAMES ...]]
|
|
||||||
[--trading-mode {spot,margin,futures}]
|
|
||||||
[--candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Limit command to these pairs. Pairs are space-
|
Show profits for only these pairs. Pairs are space-
|
||||||
separated.
|
separated.
|
||||||
--format-from {json,jsongz,hdf5,feather,parquet}
|
--format-from {json,jsongz,hdf5}
|
||||||
Source format for data conversion.
|
Source format for data conversion.
|
||||||
--format-to {json,jsongz,hdf5,feather,parquet}
|
--format-to {json,jsongz,hdf5}
|
||||||
Destination format for data conversion.
|
Destination format for data conversion.
|
||||||
--erase Clean all existing data for the selected
|
--erase Clean all existing data for the selected
|
||||||
exchange/pairs/timeframes.
|
exchange/pairs/timeframes.
|
||||||
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...], --timeframes {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]
|
||||||
config is provided.
|
|
||||||
-t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]
|
|
||||||
Specify which tickers to download. Space-separated
|
Specify which tickers to download. Space-separated
|
||||||
list. Default: `1m 5m`.
|
list. Default: `1m 5m`.
|
||||||
--trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}
|
|
||||||
Select Trading mode
|
|
||||||
--candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]
|
|
||||||
Select candle type to use
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -283,11 +141,10 @@ Common arguments:
|
|||||||
`userdir/config.json` or `config.json` whichever
|
`userdir/config.json` or `config.json` whichever
|
||||||
exists). Multiple --config options may be used. Can be
|
exists). Multiple --config options may be used. Can be
|
||||||
set to `-` to read config from stdin.
|
set to `-` to read config from stdin.
|
||||||
-d PATH, --datadir PATH, --data-dir PATH
|
-d PATH, --datadir PATH
|
||||||
Path to directory with historical backtesting data.
|
Path to directory with historical backtesting data.
|
||||||
--userdir PATH, --user-data-dir PATH
|
--userdir PATH, --user-data-dir PATH
|
||||||
Path to userdata directory.
|
Path to userdata directory.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Example converting data
|
##### Example converting data
|
||||||
@ -305,24 +162,20 @@ freqtrade convert-data --format-from json --format-to jsongz --datadir ~/.freqtr
|
|||||||
usage: freqtrade convert-trade-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
usage: freqtrade convert-trade-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
||||||
[-d PATH] [--userdir PATH]
|
[-d PATH] [--userdir PATH]
|
||||||
[-p PAIRS [PAIRS ...]] --format-from
|
[-p PAIRS [PAIRS ...]] --format-from
|
||||||
{json,jsongz,hdf5,feather,parquet}
|
{json,jsongz,hdf5} --format-to
|
||||||
--format-to
|
{json,jsongz,hdf5} [--erase]
|
||||||
{json,jsongz,hdf5,feather,parquet}
|
|
||||||
[--erase] [--exchange EXCHANGE]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Limit command to these pairs. Pairs are space-
|
Show profits for only these pairs. Pairs are space-
|
||||||
separated.
|
separated.
|
||||||
--format-from {json,jsongz,hdf5,feather,parquet}
|
--format-from {json,jsongz,hdf5}
|
||||||
Source format for data conversion.
|
Source format for data conversion.
|
||||||
--format-to {json,jsongz,hdf5,feather,parquet}
|
--format-to {json,jsongz,hdf5}
|
||||||
Destination format for data conversion.
|
Destination format for data conversion.
|
||||||
--erase Clean all existing data for the selected
|
--erase Clean all existing data for the selected
|
||||||
exchange/pairs/timeframes.
|
exchange/pairs/timeframes.
|
||||||
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
|
||||||
config is provided.
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -335,7 +188,7 @@ Common arguments:
|
|||||||
`userdir/config.json` or `config.json` whichever
|
`userdir/config.json` or `config.json` whichever
|
||||||
exists). Multiple --config options may be used. Can be
|
exists). Multiple --config options may be used. Can be
|
||||||
set to `-` to read config from stdin.
|
set to `-` to read config from stdin.
|
||||||
-d PATH, --datadir PATH, --data-dir PATH
|
-d PATH, --datadir PATH
|
||||||
Path to directory with historical backtesting data.
|
Path to directory with historical backtesting data.
|
||||||
--userdir PATH, --user-data-dir PATH
|
--userdir PATH, --user-data-dir PATH
|
||||||
Path to userdata directory.
|
Path to userdata directory.
|
||||||
@ -351,61 +204,6 @@ It'll also remove original jsongz data files (`--erase` parameter).
|
|||||||
freqtrade convert-trade-data --format-from jsongz --format-to json --datadir ~/.freqtrade/data/kraken --erase
|
freqtrade convert-trade-data --format-from jsongz --format-to json --datadir ~/.freqtrade/data/kraken --erase
|
||||||
```
|
```
|
||||||
|
|
||||||
### Sub-command trades to ohlcv
|
|
||||||
|
|
||||||
When you need to use `--dl-trades` (kraken only) to download data, conversion of trades data to ohlcv data is the last step.
|
|
||||||
This command will allow you to repeat this last step for additional timeframes without re-downloading the data.
|
|
||||||
|
|
||||||
```
|
|
||||||
usage: freqtrade trades-to-ohlcv [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
|
||||||
[-d PATH] [--userdir PATH]
|
|
||||||
[-p PAIRS [PAIRS ...]]
|
|
||||||
[-t TIMEFRAMES [TIMEFRAMES ...]]
|
|
||||||
[--exchange EXCHANGE]
|
|
||||||
[--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]
|
|
||||||
[--data-format-trades {json,jsongz,hdf5}]
|
|
||||||
|
|
||||||
optional arguments:
|
|
||||||
-h, --help show this help message and exit
|
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
|
||||||
Limit command to these pairs. Pairs are space-
|
|
||||||
separated.
|
|
||||||
-t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]
|
|
||||||
Specify which tickers to download. Space-separated
|
|
||||||
list. Default: `1m 5m`.
|
|
||||||
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
|
||||||
config is provided.
|
|
||||||
--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}
|
|
||||||
Storage format for downloaded candle (OHLCV) data.
|
|
||||||
(default: `json`).
|
|
||||||
--data-format-trades {json,jsongz,hdf5}
|
|
||||||
Storage format for downloaded trades data. (default:
|
|
||||||
`jsongz`).
|
|
||||||
|
|
||||||
Common arguments:
|
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
|
||||||
--logfile FILE Log to the file specified. Special values are:
|
|
||||||
'syslog', 'journald'. See the documentation for more
|
|
||||||
details.
|
|
||||||
-V, --version show program's version number and exit
|
|
||||||
-c PATH, --config PATH
|
|
||||||
Specify configuration file (default:
|
|
||||||
`userdir/config.json` or `config.json` whichever
|
|
||||||
exists). Multiple --config options may be used. Can be
|
|
||||||
set to `-` to read config from stdin.
|
|
||||||
-d PATH, --datadir PATH, --data-dir PATH
|
|
||||||
Path to directory with historical backtesting data.
|
|
||||||
--userdir PATH, --user-data-dir PATH
|
|
||||||
Path to userdata directory.
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Example trade-to-ohlcv conversion
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
freqtrade trades-to-ohlcv --exchange kraken -t 5m 1h 1d --pairs BTC/EUR ETH/EUR
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sub-command list-data
|
### Sub-command list-data
|
||||||
|
|
||||||
You can get a list of downloaded data using the `list-data` sub-command.
|
You can get a list of downloaded data using the `list-data` sub-command.
|
||||||
@ -413,25 +211,19 @@ You can get a list of downloaded data using the `list-data` sub-command.
|
|||||||
```
|
```
|
||||||
usage: freqtrade list-data [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
|
usage: freqtrade list-data [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
|
||||||
[--userdir PATH] [--exchange EXCHANGE]
|
[--userdir PATH] [--exchange EXCHANGE]
|
||||||
[--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]
|
[--data-format-ohlcv {json,jsongz,hdf5}]
|
||||||
[-p PAIRS [PAIRS ...]]
|
[-p PAIRS [PAIRS ...]]
|
||||||
[--trading-mode {spot,margin,futures}]
|
|
||||||
[--show-timerange]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
--exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
|
||||||
config is provided.
|
config is provided.
|
||||||
--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}
|
--data-format-ohlcv {json,jsongz,hdf5}
|
||||||
Storage format for downloaded candle (OHLCV) data.
|
Storage format for downloaded candle (OHLCV) data.
|
||||||
(default: `json`).
|
(default: `json`).
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Limit command to these pairs. Pairs are space-
|
Show profits for only these pairs. Pairs are space-
|
||||||
separated.
|
separated.
|
||||||
--trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}
|
|
||||||
Select Trading mode
|
|
||||||
--show-timerange Show timerange available for available data. (May take
|
|
||||||
a while to calculate).
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -444,7 +236,7 @@ Common arguments:
|
|||||||
`userdir/config.json` or `config.json` whichever
|
`userdir/config.json` or `config.json` whichever
|
||||||
exists). Multiple --config options may be used. Can be
|
exists). Multiple --config options may be used. Can be
|
||||||
set to `-` to read config from stdin.
|
set to `-` to read config from stdin.
|
||||||
-d PATH, --datadir PATH, --data-dir PATH
|
-d PATH, --datadir PATH
|
||||||
Path to directory with historical backtesting data.
|
Path to directory with historical backtesting data.
|
||||||
--userdir PATH, --user-data-dir PATH
|
--userdir PATH, --user-data-dir PATH
|
||||||
Path to userdata directory.
|
Path to userdata directory.
|
||||||
@ -465,6 +257,64 @@ ETH/BTC 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d
|
|||||||
ETH/USDT 5m, 15m, 30m, 1h, 2h, 4h
|
ETH/USDT 5m, 15m, 30m, 1h, 2h, 4h
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Pairs file
|
||||||
|
|
||||||
|
In alternative to the whitelist from `config.json`, a `pairs.json` file can be used.
|
||||||
|
|
||||||
|
If you are using Binance for example:
|
||||||
|
|
||||||
|
- create a directory `user_data/data/binance` and copy or create the `pairs.json` file in that directory.
|
||||||
|
- update the `pairs.json` file to contain the currency pairs you are interested in.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p user_data/data/binance
|
||||||
|
cp tests/testdata/pairs.json user_data/data/binance
|
||||||
|
```
|
||||||
|
|
||||||
|
If you your configuration directory `user_data` was made by docker, you may get the following error:
|
||||||
|
|
||||||
|
```
|
||||||
|
cp: cannot create regular file 'user_data/data/binance/pairs.json': Permission denied
|
||||||
|
```
|
||||||
|
|
||||||
|
You can fix the permissions of your user-data directory as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo chown -R $UID:$GID user_data
|
||||||
|
```
|
||||||
|
|
||||||
|
The format of the `pairs.json` file is a simple json list.
|
||||||
|
Mixing different stake-currencies is allowed for this file, since it's only used for downloading.
|
||||||
|
|
||||||
|
``` json
|
||||||
|
[
|
||||||
|
"ETH/BTC",
|
||||||
|
"ETH/USDT",
|
||||||
|
"BTC/USDT",
|
||||||
|
"XRP/ETH"
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start download
|
||||||
|
|
||||||
|
Then run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
freqtrade download-data --exchange binance
|
||||||
|
```
|
||||||
|
|
||||||
|
This will download historical candle (OHLCV) data for all the currency pairs you defined in `pairs.json`.
|
||||||
|
|
||||||
|
### Other Notes
|
||||||
|
|
||||||
|
- To use a different directory than the exchange specific default, use `--datadir user_data/data/some_directory`.
|
||||||
|
- To change the exchange used to download the historical data from, please use a different configuration file (you'll probably need to adjust rate limits etc.)
|
||||||
|
- To use `pairs.json` from some other directory, use `--pairs-file some_other_dir/pairs.json`.
|
||||||
|
- To download historical candle (OHLCV) data for only 10 days, use `--days 10` (defaults to 30 days).
|
||||||
|
- To download historical candle (OHLCV) data from a fixed starting point, use `--timerange 20200101-` - which will download all data from January 1st, 2020. Eventually set end dates are ignored.
|
||||||
|
- Use `--timeframes` to specify what timeframe download the historical candle (OHLCV) data for. Default is `--timeframes 1m 5m` which will download 1-minute and 5-minute data.
|
||||||
|
- To use exchange, timeframe and list of pairs as defined in your configuration file, use the `-c/--config` option. With this, the script uses the whitelist defined in the config as the list of currency pairs to download data for and does not require the pairs.json file. You can combine `-c/--config` with most other options.
|
||||||
|
|
||||||
### Trades (tick) data
|
### Trades (tick) data
|
||||||
|
|
||||||
By default, `download-data` sub-command downloads Candles (OHLCV) data. Some exchanges also provide historic trade-data via their API.
|
By default, `download-data` sub-command downloads Candles (OHLCV) data. Some exchanges also provide historic trade-data via their API.
|
||||||
|
@ -15,8 +15,8 @@ This command line option was deprecated in 2019.7-dev (develop branch) and remov
|
|||||||
|
|
||||||
### The **--dynamic-whitelist** command line option
|
### The **--dynamic-whitelist** command line option
|
||||||
|
|
||||||
This command line option was deprecated in 2018 and removed freqtrade 2019.6-dev (develop branch) and in freqtrade 2019.7.
|
This command line option was deprecated in 2018 and removed freqtrade 2019.6-dev (develop branch)
|
||||||
Please refer to [pairlists](plugins.md#pairlists-and-pairlist-handlers) instead.
|
and in freqtrade 2019.7.
|
||||||
|
|
||||||
### the `--live` command line option
|
### the `--live` command line option
|
||||||
|
|
||||||
@ -24,10 +24,6 @@ Please refer to [pairlists](plugins.md#pairlists-and-pairlist-handlers) instead.
|
|||||||
Did only download the latest 500 candles, so was ineffective in getting good backtest data.
|
Did only download the latest 500 candles, so was ineffective in getting good backtest data.
|
||||||
Removed in 2019-7-dev (develop branch) and in freqtrade 2019.8.
|
Removed in 2019-7-dev (develop branch) and in freqtrade 2019.8.
|
||||||
|
|
||||||
### `ticker_interval` (now `timeframe`)
|
|
||||||
|
|
||||||
Support for `ticker_interval` terminology was deprecated in 2020.6 in favor of `timeframe` - and compatibility code was removed in 2022.3.
|
|
||||||
|
|
||||||
### Allow running multiple pairlists in sequence
|
### Allow running multiple pairlists in sequence
|
||||||
|
|
||||||
The former `"pairlist"` section in the configuration has been removed, and is replaced by `"pairlists"` - being a list to specify a sequence of pairlists.
|
The former `"pairlist"` section in the configuration has been removed, and is replaced by `"pairlists"` - being a list to specify a sequence of pairlists.
|
||||||
@ -37,45 +33,3 @@ The old section of configuration parameters (`"pairlist"`) has been deprecated i
|
|||||||
### deprecation of bidVolume and askVolume from volume-pairlist
|
### deprecation of bidVolume and askVolume from volume-pairlist
|
||||||
|
|
||||||
Since only quoteVolume can be compared between assets, the other options (bidVolume, askVolume) have been deprecated in 2020.4, and have been removed in 2020.9.
|
Since only quoteVolume can be compared between assets, the other options (bidVolume, askVolume) have been deprecated in 2020.4, and have been removed in 2020.9.
|
||||||
|
|
||||||
### Using order book steps for exit price
|
|
||||||
|
|
||||||
Using `order_book_min` and `order_book_max` used to allow stepping the orderbook and trying to find the next ROI slot - trying to place sell-orders early.
|
|
||||||
As this does however increase risk and provides no benefit, it's been removed for maintainability purposes in 2021.7.
|
|
||||||
|
|
||||||
### Legacy Hyperopt mode
|
|
||||||
|
|
||||||
Using separate hyperopt files was deprecated in 2021.4 and was removed in 2021.9.
|
|
||||||
Please switch to the new [Parametrized Strategies](hyperopt.md) to benefit from the new hyperopt interface.
|
|
||||||
|
|
||||||
## Strategy changes between V2 and V3
|
|
||||||
|
|
||||||
Isolated Futures / short trading was introduced in 2022.4. This required major changes to configuration settings, strategy interfaces, ...
|
|
||||||
|
|
||||||
We have put a great effort into keeping compatibility with existing strategies, so if you just want to continue using freqtrade in spot markets, there are no changes necessary.
|
|
||||||
While we may drop support for the current interface sometime in the future, we will announce this separately and have an appropriate transition period.
|
|
||||||
|
|
||||||
Please follow the [Strategy migration](strategy_migration.md) guide to migrate your strategy to the new format to start using the new functionalities.
|
|
||||||
|
|
||||||
### webhooks - changes with 2022.4
|
|
||||||
|
|
||||||
#### `buy_tag` has been renamed to `enter_tag`
|
|
||||||
|
|
||||||
This should apply only to your strategy and potentially to webhooks.
|
|
||||||
We will keep a compatibility layer for 1-2 versions (so both `buy_tag` and `enter_tag` will still work), but support for this in webhooks will disappear after that.
|
|
||||||
|
|
||||||
#### Naming changes
|
|
||||||
|
|
||||||
Webhook terminology changed from "sell" to "exit", and from "buy" to "entry", removing "webhook" in the process.
|
|
||||||
|
|
||||||
* `webhookbuy`, `webhookentry` -> `entry`
|
|
||||||
* `webhookbuyfill`, `webhookentryfill` -> `entry_fill`
|
|
||||||
* `webhookbuycancel`, `webhookentrycancel` -> `entry_cancel`
|
|
||||||
* `webhooksell`, `webhookexit` -> `exit`
|
|
||||||
* `webhooksellfill`, `webhookexitfill` -> `exit_fill`
|
|
||||||
* `webhooksellcancel`, `webhookexitcancel` -> `exit_cancel`
|
|
||||||
|
|
||||||
|
|
||||||
## Removal of `populate_any_indicators`
|
|
||||||
|
|
||||||
version 2023.3 saw the removal of `populate_any_indicators` in favor of split methods for feature engineering and targets. Please read the [migration document](strategy_migration.md#freqai-strategy) for full details.
|
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
This page is intended for developers of Freqtrade, people who want to contribute to the Freqtrade codebase or documentation, or people who want to understand the source code of the application they're running.
|
This page is intended for developers of Freqtrade, people who want to contribute to the Freqtrade codebase or documentation, or people who want to understand the source code of the application they're running.
|
||||||
|
|
||||||
All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome. We [track issues](https://github.com/freqtrade/freqtrade/issues) on [GitHub](https://github.com) and also have a dev channel on [discord](https://discord.gg/p7nuUNVfP7) where you can ask questions.
|
All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome. We [track issues](https://github.com/freqtrade/freqtrade/issues) on [GitHub](https://github.com) and also have a dev channel on [discord](https://discord.gg/p7nuUNVfP7) or [slack](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw) where you can ask questions.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Documentation is available at [https://freqtrade.io](https://www.freqtrade.io/) and needs to be provided with every new feature PR.
|
Documentation is available at [https://freqtrade.io](https://www.freqtrade.io/) and needs to be provided with every new feature PR.
|
||||||
|
|
||||||
Special fields for the documentation (like Note boxes, ...) can be found [here](https://squidfunk.github.io/mkdocs-material/reference/admonitions/).
|
Special fields for the documentation (like Note boxes, ...) can be found [here](https://squidfunk.github.io/mkdocs-material/extensions/admonition/).
|
||||||
|
|
||||||
To test the documentation locally use the following commands.
|
To test the documentation locally use the following commands.
|
||||||
|
|
||||||
@ -24,12 +24,7 @@ This will spin up a local server (usually on port 8000) so you can see if everyt
|
|||||||
To configure a development environment, you can either use the provided [DevContainer](#devcontainer-setup), or use the `setup.sh` script and answer "y" when asked "Do you want to install dependencies for dev [y/N]? ".
|
To configure a development environment, you can either use the provided [DevContainer](#devcontainer-setup), or use the `setup.sh` script and answer "y" when asked "Do you want to install dependencies for dev [y/N]? ".
|
||||||
Alternatively (e.g. if your system is not supported by the setup.sh script), follow the manual installation process and run `pip3 install -e .[all]`.
|
Alternatively (e.g. if your system is not supported by the setup.sh script), follow the manual installation process and run `pip3 install -e .[all]`.
|
||||||
|
|
||||||
This will install all required tools for development, including `pytest`, `ruff`, `mypy`, and `coveralls`.
|
This will install all required tools for development, including `pytest`, `flake8`, `mypy`, and `coveralls`.
|
||||||
|
|
||||||
Then install the git hook scripts by running `pre-commit install`, so your changes will be verified locally before committing.
|
|
||||||
This avoids a lot of waiting for CI already, as some basic formatting checks are done locally on your machine.
|
|
||||||
|
|
||||||
Before opening a pull request, please familiarize yourself with our [Contributing Guidelines](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md).
|
|
||||||
|
|
||||||
### Devcontainer setup
|
### Devcontainer setup
|
||||||
|
|
||||||
@ -49,13 +44,6 @@ For more information about the [Remote container extension](https://code.visuals
|
|||||||
New code should be covered by basic unittests. Depending on the complexity of the feature, Reviewers may request more in-depth unittests.
|
New code should be covered by basic unittests. Depending on the complexity of the feature, Reviewers may request more in-depth unittests.
|
||||||
If necessary, the Freqtrade team can assist and give guidance with writing good tests (however please don't expect anyone to write the tests for you).
|
If necessary, the Freqtrade team can assist and give guidance with writing good tests (however please don't expect anyone to write the tests for you).
|
||||||
|
|
||||||
#### How to run tests
|
|
||||||
|
|
||||||
Use `pytest` in root folder to run all available testcases and confirm your local environment is setup correctly
|
|
||||||
|
|
||||||
!!! Note "feature branches"
|
|
||||||
Tests are expected to pass on the `develop` and `stable` branches. Other branches may be work in progress with tests not working yet.
|
|
||||||
|
|
||||||
#### Checking log content in tests
|
#### Checking log content in tests
|
||||||
|
|
||||||
Freqtrade uses 2 main methods to check log content in tests, `log_has()` and `log_has_re()` (to check using regex, in case of dynamic log-messages).
|
Freqtrade uses 2 main methods to check log content in tests, `log_has()` and `log_has_re()` (to check using regex, in case of dynamic log-messages).
|
||||||
@ -75,36 +63,6 @@ def test_method_to_test(caplog):
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debug configuration
|
|
||||||
|
|
||||||
To debug freqtrade, we recommend VSCode with the following launch configuration (located in `.vscode/launch.json`).
|
|
||||||
Details will obviously vary between setups - but this should work to get you started.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
{
|
|
||||||
"name": "freqtrade trade",
|
|
||||||
"type": "python",
|
|
||||||
"request": "launch",
|
|
||||||
"module": "freqtrade",
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"args": [
|
|
||||||
"trade",
|
|
||||||
// Optional:
|
|
||||||
// "--userdir", "user_data",
|
|
||||||
"--strategy",
|
|
||||||
"MyAwesomeStrategy",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
Command line arguments can be added in the `"args"` array.
|
|
||||||
This method can also be used to debug a strategy, by setting the breakpoints within the strategy.
|
|
||||||
|
|
||||||
A similar setup can also be taken for Pycharm - using `freqtrade` as module name, and setting the command line arguments as "parameters".
|
|
||||||
|
|
||||||
!!! Note "Startup directory"
|
|
||||||
This assumes that you have the repository checked out, and the editor is started at the repository root level (so setup.py is at the top level of your repository).
|
|
||||||
|
|
||||||
## ErrorHandling
|
## ErrorHandling
|
||||||
|
|
||||||
Freqtrade Exceptions all inherit from `FreqtradeException`.
|
Freqtrade Exceptions all inherit from `FreqtradeException`.
|
||||||
@ -237,12 +195,11 @@ For that reason, they must implement the following methods:
|
|||||||
* `global_stop()`
|
* `global_stop()`
|
||||||
* `stop_per_pair()`.
|
* `stop_per_pair()`.
|
||||||
|
|
||||||
`global_stop()` and `stop_per_pair()` must return a ProtectionReturn object, which consists of:
|
`global_stop()` and `stop_per_pair()` must return a ProtectionReturn tuple, which consists of:
|
||||||
|
|
||||||
* lock pair - boolean
|
* lock pair - boolean
|
||||||
* lock until - datetime - until when should the pair be locked (will be rounded up to the next new candle)
|
* lock until - datetime - until when should the pair be locked (will be rounded up to the next new candle)
|
||||||
* reason - string, used for logging and storage in the database
|
* reason - string, used for logging and storage in the database
|
||||||
* lock_side - long, short or '*'.
|
|
||||||
|
|
||||||
The `until` portion should be calculated using the provided `calculate_lock_end()` method.
|
The `until` portion should be calculated using the provided `calculate_lock_end()` method.
|
||||||
|
|
||||||
@ -261,13 +218,13 @@ Protections can have 2 different ways to stop trading for a limited :
|
|||||||
##### Protections - per pair
|
##### Protections - per pair
|
||||||
|
|
||||||
Protections that implement the per pair approach must set `has_local_stop=True`.
|
Protections that implement the per pair approach must set `has_local_stop=True`.
|
||||||
The method `stop_per_pair()` will be called whenever a trade closed (exit order completed).
|
The method `stop_per_pair()` will be called whenever a trade closed (sell order completed).
|
||||||
|
|
||||||
##### Protections - global protection
|
##### Protections - global protection
|
||||||
|
|
||||||
These Protections should do their evaluation across all pairs, and consequently will also lock all pairs from trading (called a global PairLock).
|
These Protections should do their evaluation across all pairs, and consequently will also lock all pairs from trading (called a global PairLock).
|
||||||
Global protection must set `has_global_stop=True` to be evaluated for global stops.
|
Global protection must set `has_global_stop=True` to be evaluated for global stops.
|
||||||
The method `global_stop()` will be called whenever a trade closed (exit order completed).
|
The method `global_stop()` will be called whenever a trade closed (sell order completed).
|
||||||
|
|
||||||
##### Protections - calculating lock end time
|
##### Protections - calculating lock end time
|
||||||
|
|
||||||
@ -283,34 +240,11 @@ The `IProtection` parent class provides a helper method for this in `calculate_l
|
|||||||
!!! Note
|
!!! Note
|
||||||
This section is a Work in Progress and is not a complete guide on how to test a new exchange with Freqtrade.
|
This section is a Work in Progress and is not a complete guide on how to test a new exchange with Freqtrade.
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Make sure to use an up-to-date version of CCXT before running any of the below tests.
|
|
||||||
You can get the latest version of ccxt by running `pip install -U ccxt` with activated virtual environment.
|
|
||||||
Native docker is not supported for these tests, however the available dev-container will support all required actions and eventually necessary changes.
|
|
||||||
|
|
||||||
Most exchanges supported by CCXT should work out of the box.
|
Most exchanges supported by CCXT should work out of the box.
|
||||||
|
|
||||||
To quickly test the public endpoints of an exchange, add a configuration for your exchange to `test_ccxt_compat.py` and run these tests with `pytest --longrun tests/exchange/test_ccxt_compat.py`.
|
To quickly test the public endpoints of an exchange, add a configuration for your exchange to `test_ccxt_compat.py` and run these tests with `pytest --longrun tests/exchange/test_ccxt_compat.py`.
|
||||||
Completing these tests successfully a good basis point (it's a requirement, actually), however these won't guarantee correct exchange functioning, as this only tests public endpoints, but no private endpoint (like generate order or similar).
|
Completing these tests successfully a good basis point (it's a requirement, actually), however these won't guarantee correct exchange functioning, as this only tests public endpoints, but no private endpoint (like generate order or similar).
|
||||||
|
|
||||||
Also try to use `freqtrade download-data` for an extended timerange (multiple months) and verify that the data downloaded correctly (no holes, the specified timerange was actually downloaded).
|
|
||||||
|
|
||||||
These are prerequisites to have an exchange listed as either Supported or Community tested (listed on the homepage).
|
|
||||||
The below are "extras", which will make an exchange better (feature-complete) - but are not absolutely necessary for either of the 2 categories.
|
|
||||||
|
|
||||||
Additional tests / steps to complete:
|
|
||||||
|
|
||||||
* Verify data provided by `fetch_ohlcv()` - and eventually adjust `ohlcv_candle_limit` for this exchange
|
|
||||||
* Check L2 orderbook limit range (API documentation) - and eventually set as necessary
|
|
||||||
* Check if balance shows correctly (*)
|
|
||||||
* Create market order (*)
|
|
||||||
* Create limit order (*)
|
|
||||||
* Complete trade (enter + exit) (*)
|
|
||||||
* Compare result calculation between exchange and bot
|
|
||||||
* Ensure fees are applied correctly (check the database against the exchange)
|
|
||||||
|
|
||||||
(*) Requires API keys and Balance on the exchange.
|
|
||||||
|
|
||||||
### Stoploss On Exchange
|
### Stoploss On Exchange
|
||||||
|
|
||||||
Check if the new exchange supports Stoploss on Exchange orders through their API.
|
Check if the new exchange supports Stoploss on Exchange orders through their API.
|
||||||
@ -351,32 +285,6 @@ The output will show the last entry from the Exchange as well as the current UTC
|
|||||||
If the day shows the same day, then the last candle can be assumed as incomplete and should be dropped (leave the setting `"ohlcv_partial_candle"` from the exchange-class untouched / True). Otherwise, set `"ohlcv_partial_candle"` to `False` to not drop Candles (shown in the example above).
|
If the day shows the same day, then the last candle can be assumed as incomplete and should be dropped (leave the setting `"ohlcv_partial_candle"` from the exchange-class untouched / True). Otherwise, set `"ohlcv_partial_candle"` to `False` to not drop Candles (shown in the example above).
|
||||||
Another way is to run this command multiple times in a row and observe if the volume is changing (while the date remains the same).
|
Another way is to run this command multiple times in a row and observe if the volume is changing (while the date remains the same).
|
||||||
|
|
||||||
### Update binance cached leverage tiers
|
|
||||||
|
|
||||||
Updating leveraged tiers should be done regularly - and requires an authenticated account with futures enabled.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
import ccxt
|
|
||||||
import json
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
exchange = ccxt.binance({
|
|
||||||
'apiKey': '<apikey>',
|
|
||||||
'secret': '<secret>'
|
|
||||||
'options': {'defaultType': 'swap'}
|
|
||||||
})
|
|
||||||
_ = exchange.load_markets()
|
|
||||||
|
|
||||||
lev_tiers = exchange.fetch_leverage_tiers()
|
|
||||||
|
|
||||||
# Assumes this is running in the root of the repository.
|
|
||||||
file = Path('freqtrade/exchange/binance_leverage_tiers.json')
|
|
||||||
json.dump(dict(sorted(lev_tiers.items())), file.open('w'), indent=2)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
This file should then be contributed upstream, so others can benefit from this, too.
|
|
||||||
|
|
||||||
## Updating example notebooks
|
## Updating example notebooks
|
||||||
|
|
||||||
To keep the jupyter notebooks aligned with the documentation, the following should be ran after updating a example notebook.
|
To keep the jupyter notebooks aligned with the documentation, the following should be ran after updating a example notebook.
|
||||||
@ -391,8 +299,9 @@ jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to markdown freqtrade
|
|||||||
This documents some decisions taken for the CI Pipeline.
|
This documents some decisions taken for the CI Pipeline.
|
||||||
|
|
||||||
* CI runs on all OS variants, Linux (ubuntu), macOS and Windows.
|
* CI runs on all OS variants, Linux (ubuntu), macOS and Windows.
|
||||||
* Docker images are build for the branches `stable` and `develop`, and are built as multiarch builds, supporting multiple platforms via the same tag.
|
* Docker images are build for the branches `stable` and `develop`.
|
||||||
* Docker images containing Plot dependencies are also available as `stable_plot` and `develop_plot`.
|
* Docker images containing Plot dependencies are also available as `stable_plot` and `develop_plot`.
|
||||||
|
* Raspberry PI Docker images are postfixed with `_pi` - so tags will be `:stable_pi` and `develop_pi`.
|
||||||
* Docker images contain a file, `/freqtrade/freqtrade_commit` containing the commit this image is based of.
|
* Docker images contain a file, `/freqtrade/freqtrade_commit` containing the commit this image is based of.
|
||||||
* Full docker image rebuilds are run once a week via schedule.
|
* Full docker image rebuilds are run once a week via schedule.
|
||||||
* Deployments run on ubuntu.
|
* Deployments run on ubuntu.
|
||||||
@ -416,9 +325,8 @@ Determine if crucial bugfixes have been made between this commit and the current
|
|||||||
|
|
||||||
* Merge the release branch (stable) into this branch.
|
* Merge the release branch (stable) into this branch.
|
||||||
* Edit `freqtrade/__init__.py` and add the version matching the current date (for example `2019.7` for July 2019). Minor versions can be `2019.7.1` should we need to do a second release that month. Version numbers must follow allowed versions from PEP0440 to avoid failures pushing to pypi.
|
* Edit `freqtrade/__init__.py` and add the version matching the current date (for example `2019.7` for July 2019). Minor versions can be `2019.7.1` should we need to do a second release that month. Version numbers must follow allowed versions from PEP0440 to avoid failures pushing to pypi.
|
||||||
* Commit this part.
|
* Commit this part
|
||||||
* push that branch to the remote and create a PR against the stable branch.
|
* push that branch to the remote and create a PR against the stable branch
|
||||||
* Update develop version to next version following the pattern `2019.8-dev`.
|
|
||||||
|
|
||||||
### Create changelog from git commits
|
### Create changelog from git commits
|
||||||
|
|
||||||
@ -441,11 +349,6 @@ To keep the release-log short, best wrap the full git changelog into a collapsib
|
|||||||
</details>
|
</details>
|
||||||
```
|
```
|
||||||
|
|
||||||
### FreqUI release
|
|
||||||
|
|
||||||
If FreqUI has been updated substantially, make sure to create a release before merging the release branch.
|
|
||||||
Make sure that freqUI CI on the release is finished and passed before merging the release.
|
|
||||||
|
|
||||||
### Create github release / tag
|
### Create github release / tag
|
||||||
|
|
||||||
Once the PR against stable is merged (best right after merging):
|
Once the PR against stable is merged (best right after merging):
|
||||||
|
@ -4,43 +4,102 @@ This page explains how to run the bot with Docker. It is not meant to work out o
|
|||||||
|
|
||||||
## Install Docker
|
## Install Docker
|
||||||
|
|
||||||
Start by downloading and installing Docker / Docker Desktop for your platform:
|
Start by downloading and installing Docker CE for your platform:
|
||||||
|
|
||||||
* [Mac](https://docs.docker.com/docker-for-mac/install/)
|
* [Mac](https://docs.docker.com/docker-for-mac/install/)
|
||||||
* [Windows](https://docs.docker.com/docker-for-windows/install/)
|
* [Windows](https://docs.docker.com/docker-for-windows/install/)
|
||||||
* [Linux](https://docs.docker.com/install/)
|
* [Linux](https://docs.docker.com/install/)
|
||||||
|
|
||||||
!!! Info "Docker compose install"
|
To simplify running freqtrade, [`docker-compose`](https://docs.docker.com/compose/install/) should be installed and available to follow the below [docker quick start guide](#docker-quick-start).
|
||||||
Freqtrade documentation assumes the use of Docker desktop (or the docker compose plugin).
|
|
||||||
While the docker-compose standalone installation still works, it will require changing all `docker compose` commands from `docker compose` to `docker-compose` to work (e.g. `docker compose up -d` will become `docker-compose up -d`).
|
|
||||||
|
|
||||||
## Freqtrade with docker
|
## Freqtrade with docker-compose
|
||||||
|
|
||||||
Freqtrade provides an official Docker image on [Dockerhub](https://hub.docker.com/r/freqtradeorg/freqtrade/), as well as a [docker compose file](https://github.com/freqtrade/freqtrade/blob/stable/docker-compose.yml) ready for usage.
|
Freqtrade provides an official Docker image on [Dockerhub](https://hub.docker.com/r/freqtradeorg/freqtrade/), as well as a [docker-compose file](https://github.com/freqtrade/freqtrade/blob/stable/docker-compose.yml) ready for usage.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
- The following section assumes that `docker` is installed and available to the logged in user.
|
- The following section assumes that `docker` and `docker-compose` are installed and available to the logged in user.
|
||||||
- All below commands use relative directories and will have to be executed from the directory containing the `docker-compose.yml` file.
|
- All below commands use relative directories and will have to be executed from the directory containing the `docker-compose.yml` file.
|
||||||
|
|
||||||
### Docker quick start
|
### Docker quick start
|
||||||
|
|
||||||
Create a new directory and place the [docker-compose file](https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml) in this directory.
|
Create a new directory and place the [docker-compose file](https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml) in this directory.
|
||||||
|
|
||||||
``` bash
|
=== "PC/MAC/Linux"
|
||||||
mkdir ft_userdata
|
``` bash
|
||||||
cd ft_userdata/
|
mkdir ft_userdata
|
||||||
# Download the docker-compose file from the repository
|
cd ft_userdata/
|
||||||
curl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml
|
# Download the docker-compose file from the repository
|
||||||
|
curl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml
|
||||||
|
|
||||||
# Pull the freqtrade image
|
# Pull the freqtrade image
|
||||||
docker compose pull
|
docker-compose pull
|
||||||
|
|
||||||
# Create user directory structure
|
# Create user directory structure
|
||||||
docker compose run --rm freqtrade create-userdir --userdir user_data
|
docker-compose run --rm freqtrade create-userdir --userdir user_data
|
||||||
|
|
||||||
# Create configuration - Requires answering interactive questions
|
# Create configuration - Requires answering interactive questions
|
||||||
docker compose run --rm freqtrade new-config --config user_data/config.json
|
docker-compose run --rm freqtrade new-config --config user_data/config.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
=== "RaspberryPi"
|
||||||
|
``` bash
|
||||||
|
mkdir ft_userdata
|
||||||
|
cd ft_userdata/
|
||||||
|
# Download the docker-compose file from the repository
|
||||||
|
curl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml
|
||||||
|
|
||||||
|
# Edit the compose file to use an image named `*_pi` (stable_pi or develop_pi)
|
||||||
|
|
||||||
|
# Pull the freqtrade image
|
||||||
|
docker-compose pull
|
||||||
|
|
||||||
|
# Create user directory structure
|
||||||
|
docker-compose run --rm freqtrade create-userdir --userdir user_data
|
||||||
|
|
||||||
|
# Create configuration - Requires answering interactive questions
|
||||||
|
docker-compose run --rm freqtrade new-config --config user_data/config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! Note "Change your docker Image"
|
||||||
|
You have to change the docker image in the docker-compose file for your Raspberry build to work properly.
|
||||||
|
``` yml
|
||||||
|
image: freqtradeorg/freqtrade:stable_pi
|
||||||
|
# image: freqtradeorg/freqtrade:develop_pi
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "ARM 64 Systenms (Mac M1, Raspberry Pi 4, Jetson Nano)"
|
||||||
|
In case of a Mac M1, make sure that your docker installation is running in native mode
|
||||||
|
Arm64 images are not yet provided via Docker Hub and need to be build locally first.
|
||||||
|
Depending on the device, this may take a few minutes (Apple M1) or multiple hours (Raspberry Pi)
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# Clone Freqtrade repository
|
||||||
|
git clone https://github.com/freqtrade/freqtrade.git
|
||||||
|
cd freqtrade
|
||||||
|
# Optionally switch to the stable version
|
||||||
|
git checkout stable
|
||||||
|
|
||||||
|
# Modify your docker-compose file to enable building and change the image name
|
||||||
|
# (see the Note Box below for necessary changes)
|
||||||
|
|
||||||
|
# Build image
|
||||||
|
docker-compose build
|
||||||
|
|
||||||
|
# Create user directory structure
|
||||||
|
docker-compose run --rm freqtrade create-userdir --userdir user_data
|
||||||
|
|
||||||
|
# Create configuration - Requires answering interactive questions
|
||||||
|
docker-compose run --rm freqtrade new-config --config user_data/config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! Note "Change your docker Image"
|
||||||
|
You have to change the docker image in the docker-compose file for your arm64 build to work properly.
|
||||||
|
``` yml
|
||||||
|
image: freqtradeorg/freqtrade:custom_arm64
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: "Dockerfile"
|
||||||
|
```
|
||||||
|
|
||||||
The above snippet creates a new directory called `ft_userdata`, downloads the latest compose file and pulls the freqtrade image.
|
The above snippet creates a new directory called `ft_userdata`, downloads the latest compose file and pulls the freqtrade image.
|
||||||
The last 2 steps in the snippet create the directory with `user_data`, as well as (interactively) the default configuration based on your selections.
|
The last 2 steps in the snippet create the directory with `user_data`, as well as (interactively) the default configuration based on your selections.
|
||||||
@ -58,7 +117,7 @@ The last 2 steps in the snippet create the directory with `user_data`, as well a
|
|||||||
|
|
||||||
The `SampleStrategy` is run by default.
|
The `SampleStrategy` is run by default.
|
||||||
|
|
||||||
!!! Danger "`SampleStrategy` is just a demo!"
|
!!! Warning "`SampleStrategy` is just a demo!"
|
||||||
The `SampleStrategy` is there for your reference and give you ideas for your own strategy.
|
The `SampleStrategy` is there for your reference and give you ideas for your own strategy.
|
||||||
Please always backtest your strategy and use dry-run for some time before risking real money!
|
Please always backtest your strategy and use dry-run for some time before risking real money!
|
||||||
You will find more information about Strategy development in the [Strategy documentation](strategy-customization.md).
|
You will find more information about Strategy development in the [Strategy documentation](strategy-customization.md).
|
||||||
@ -66,47 +125,35 @@ The `SampleStrategy` is run by default.
|
|||||||
Once this is done, you're ready to launch the bot in trading mode (Dry-run or Live-trading, depending on your answer to the corresponding question you made above).
|
Once this is done, you're ready to launch the bot in trading mode (Dry-run or Live-trading, depending on your answer to the corresponding question you made above).
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Warning "Default configuration"
|
!!! Warning "Default configuration"
|
||||||
While the configuration generated will be mostly functional, you will still need to verify that all options correspond to what you want (like Pricing, pairlist, ...) before starting the bot.
|
While the configuration generated will be mostly functional, you will still need to verify that all options correspond to what you want (like Pricing, pairlist, ...) before starting the bot.
|
||||||
|
|
||||||
#### Accessing the UI
|
|
||||||
|
|
||||||
If you've selected to enable FreqUI in the `new-config` step, you will have freqUI available at port `localhost:8080`.
|
|
||||||
|
|
||||||
You can now access the UI by typing localhost:8080 in your browser.
|
|
||||||
|
|
||||||
??? Note "UI Access on a remote servers"
|
|
||||||
If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot.
|
|
||||||
This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box).
|
|
||||||
Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet.
|
|
||||||
Please also read the [API configuration with docker](rest-api.md#configuration-with-docker) section to learn more about this configuration.
|
|
||||||
|
|
||||||
#### Monitoring the bot
|
#### Monitoring the bot
|
||||||
|
|
||||||
You can check for running instances with `docker compose ps`.
|
You can check for running instances with `docker-compose ps`.
|
||||||
This should list the service `freqtrade` as `running`. If that's not the case, best check the logs (see next point).
|
This should list the service `freqtrade` as `running`. If that's not the case, best check the logs (see next point).
|
||||||
|
|
||||||
#### Docker compose logs
|
#### Docker-compose logs
|
||||||
|
|
||||||
Logs will be written to: `user_data/logs/freqtrade.log`.
|
Logs will be written to: `user_data/logs/freqtrade.log`.
|
||||||
You can also check the latest log with the command `docker compose logs -f`.
|
You can also check the latest log with the command `docker-compose logs -f`.
|
||||||
|
|
||||||
#### Database
|
#### Database
|
||||||
|
|
||||||
The database will be located at: `user_data/tradesv3.sqlite`
|
The database will be located at: `user_data/tradesv3.sqlite`
|
||||||
|
|
||||||
#### Updating freqtrade with docker
|
#### Updating freqtrade with docker-compose
|
||||||
|
|
||||||
Updating freqtrade when using `docker` is as simple as running the following 2 commands:
|
Updating freqtrade when using `docker-compose` is as simple as running the following 2 commands:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
# Download the latest image
|
# Download the latest image
|
||||||
docker compose pull
|
docker-compose pull
|
||||||
# Restart the image
|
# Restart the image
|
||||||
docker compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
This will first pull the latest image, and will then restart the container with the just pulled version.
|
This will first pull the latest image, and will then restart the container with the just pulled version.
|
||||||
@ -118,43 +165,32 @@ This will first pull the latest image, and will then restart the container with
|
|||||||
|
|
||||||
Advanced users may edit the docker-compose file further to include all possible options or arguments.
|
Advanced users may edit the docker-compose file further to include all possible options or arguments.
|
||||||
|
|
||||||
All freqtrade arguments will be available by running `docker compose run --rm freqtrade <command> <optional arguments>`.
|
All freqtrade arguments will be available by running `docker-compose run --rm freqtrade <command> <optional arguments>`.
|
||||||
|
|
||||||
!!! Warning "`docker compose` for trade commands"
|
!!! Note "`docker-compose run --rm`"
|
||||||
Trade commands (`freqtrade trade <...>`) should not be ran via `docker compose run` - but should use `docker compose up -d` instead.
|
|
||||||
This makes sure that the container is properly started (including port forwardings) and will make sure that the container will restart after a system reboot.
|
|
||||||
If you intend to use freqUI, please also ensure to adjust the [configuration accordingly](rest-api.md#configuration-with-docker), otherwise the UI will not be available.
|
|
||||||
|
|
||||||
!!! Note "`docker compose run --rm`"
|
|
||||||
Including `--rm` will remove the container after completion, and is highly recommended for all modes except trading mode (running with `freqtrade trade` command).
|
Including `--rm` will remove the container after completion, and is highly recommended for all modes except trading mode (running with `freqtrade trade` command).
|
||||||
|
|
||||||
??? Note "Using docker without docker"
|
#### Example: Download data with docker-compose
|
||||||
"`docker compose run --rm`" will require a compose file to be provided.
|
|
||||||
Some freqtrade commands that don't require authentication such as `list-pairs` can be run with "`docker run --rm`" instead.
|
|
||||||
For example `docker run --rm freqtradeorg/freqtrade:stable list-pairs --exchange binance --quote BTC --print-json`.
|
|
||||||
This can be useful for fetching exchange information to add to your `config.json` without affecting your running containers.
|
|
||||||
|
|
||||||
#### Example: Download data with docker
|
|
||||||
|
|
||||||
Download backtesting data for 5 days for the pair ETH/BTC and 1h timeframe from Binance. The data will be stored in the directory `user_data/data/` on the host.
|
Download backtesting data for 5 days for the pair ETH/BTC and 1h timeframe from Binance. The data will be stored in the directory `user_data/data/` on the host.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose run --rm freqtrade download-data --pairs ETH/BTC --exchange binance --days 5 -t 1h
|
docker-compose run --rm freqtrade download-data --pairs ETH/BTC --exchange binance --days 5 -t 1h
|
||||||
```
|
```
|
||||||
|
|
||||||
Head over to the [Data Downloading Documentation](data-download.md) for more details on downloading data.
|
Head over to the [Data Downloading Documentation](data-download.md) for more details on downloading data.
|
||||||
|
|
||||||
#### Example: Backtest with docker
|
#### Example: Backtest with docker-compose
|
||||||
|
|
||||||
Run backtesting in docker-containers for SampleStrategy and specified timerange of historical data, on 5m timeframe:
|
Run backtesting in docker-containers for SampleStrategy and specified timerange of historical data, on 5m timeframe:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m
|
docker-compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m
|
||||||
```
|
```
|
||||||
|
|
||||||
Head over to the [Backtesting Documentation](backtesting.md) to learn more.
|
Head over to the [Backtesting Documentation](backtesting.md) to learn more.
|
||||||
|
|
||||||
### Additional dependencies with docker
|
### Additional dependencies with docker-compose
|
||||||
|
|
||||||
If your strategy requires dependencies not included in the default image - it will be necessary to build the image on your host.
|
If your strategy requires dependencies not included in the default image - it will be necessary to build the image on your host.
|
||||||
For this, please create a Dockerfile containing installation steps for the additional dependencies (have a look at [docker/Dockerfile.custom](https://github.com/freqtrade/freqtrade/blob/develop/docker/Dockerfile.custom) for an example).
|
For this, please create a Dockerfile containing installation steps for the additional dependencies (have a look at [docker/Dockerfile.custom](https://github.com/freqtrade/freqtrade/blob/develop/docker/Dockerfile.custom) for an example).
|
||||||
@ -168,26 +204,26 @@ You'll then also need to modify the `docker-compose.yml` file and uncomment the
|
|||||||
dockerfile: "./Dockerfile.<yourextension>"
|
dockerfile: "./Dockerfile.<yourextension>"
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then run `docker compose build --pull` to build the docker image, and run it using the commands described above.
|
You can then run `docker-compose build` to build the docker image, and run it using the commands described above.
|
||||||
|
|
||||||
### Plotting with docker
|
## Plotting with docker-compose
|
||||||
|
|
||||||
Commands `freqtrade plot-profit` and `freqtrade plot-dataframe` ([Documentation](plotting.md)) are available by changing the image to `*_plot` in your docker-compose.yml file.
|
Commands `freqtrade plot-profit` and `freqtrade plot-dataframe` ([Documentation](plotting.md)) are available by changing the image to `*_plot` in your docker-compose.yml file.
|
||||||
You can then use these commands as follows:
|
You can then use these commands as follows:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose run --rm freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805
|
docker-compose run --rm freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805
|
||||||
```
|
```
|
||||||
|
|
||||||
The output will be stored in the `user_data/plot` directory, and can be opened with any modern browser.
|
The output will be stored in the `user_data/plot` directory, and can be opened with any modern browser.
|
||||||
|
|
||||||
### Data analysis using docker compose
|
## Data analysis using docker compose
|
||||||
|
|
||||||
Freqtrade provides a docker-compose file which starts up a jupyter lab server.
|
Freqtrade provides a docker-compose file which starts up a jupyter lab server.
|
||||||
You can run this server using the following command:
|
You can run this server using the following command:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose -f docker/docker-compose-jupyter.yml up
|
docker-compose -f docker/docker-compose-jupyter.yml up
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a docker-container running jupyter lab, which will be accessible using `https://127.0.0.1:8888/lab`.
|
This will create a docker-container running jupyter lab, which will be accessible using `https://127.0.0.1:8888/lab`.
|
||||||
@ -196,24 +232,5 @@ Please use the link that's printed in the console after startup for simplified l
|
|||||||
Since part of this image is built on your machine, it is recommended to rebuild the image from time to time to keep freqtrade (and dependencies) up-to-date.
|
Since part of this image is built on your machine, it is recommended to rebuild the image from time to time to keep freqtrade (and dependencies) up-to-date.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose -f docker/docker-compose-jupyter.yml build --no-cache
|
docker-compose -f docker/docker-compose-jupyter.yml build --no-cache
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Docker on Windows
|
|
||||||
|
|
||||||
* Error: `"Timestamp for this request is outside of the recvWindow."`
|
|
||||||
* The market api requests require a synchronized clock but the time in the docker container shifts a bit over time into the past.
|
|
||||||
To fix this issue temporarily you need to run `wsl --shutdown` and restart docker again (a popup on windows 10 will ask you to do so).
|
|
||||||
A permanent solution is either to host the docker container on a linux host or restart the wsl from time to time with the scheduler.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
taskkill /IM "Docker Desktop.exe" /F
|
|
||||||
wsl --shutdown
|
|
||||||
start "" "C:\Program Files\Docker\Docker\Docker Desktop.exe"
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Due to the above, we do not recommend the usage of docker on windows for production setups, but only for experimentation, datadownload and backtesting.
|
|
||||||
Best use a linux-VPS for running freqtrade reliably.
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
The `Edge Positioning` module uses probability to calculate your win rate and risk reward ratio. It will use these statistics to control your strategy trade entry points, position size and, stoploss.
|
The `Edge Positioning` module uses probability to calculate your win rate and risk reward ratio. It will use these statistics to control your strategy trade entry points, position size and, stoploss.
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
When using `Edge positioning` with a dynamic whitelist (VolumePairList), make sure to also use `AgeFilter` and set it to at least `calculate_since_number_of_days` to avoid problems with missing data.
|
WHen using `Edge positioning` with a dynamic whitelist (VolumePairList), make sure to also use `AgeFilter` and set it to at least `calculate_since_number_of_days` to avoid problems with missing data.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
`Edge Positioning` only considers *its own* buy/sell/stoploss signals. It ignores the stoploss, trailing stoploss, and ROI settings in the strategy configuration file.
|
`Edge Positioning` only considers *its own* buy/sell/stoploss signals. It ignores the stoploss, trailing stoploss, and ROI settings in the strategy configuration file.
|
||||||
@ -222,7 +222,7 @@ usage: freqtrade edge [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
|
|||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-i TIMEFRAME, --timeframe TIMEFRAME
|
-i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
|
||||||
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
|
@ -1,72 +1,16 @@
|
|||||||
# Exchange-specific Notes
|
# Exchange-specific Notes
|
||||||
|
|
||||||
This page combines common gotchas and Information which are exchange-specific and most likely don't apply to other exchanges.
|
This page combines common gotchas and informations which are exchange-specific and most likely don't apply to other exchanges.
|
||||||
|
|
||||||
## Exchange configuration
|
|
||||||
|
|
||||||
Freqtrade is based on [CCXT library](https://github.com/ccxt/ccxt) that supports over 100 cryptocurrency
|
|
||||||
exchange markets and trading APIs. The complete up-to-date list can be found in the
|
|
||||||
[CCXT repo homepage](https://github.com/ccxt/ccxt/tree/master/python).
|
|
||||||
However, the bot was tested by the development team with only a few exchanges.
|
|
||||||
A current list of these can be found in the "Home" section of this documentation.
|
|
||||||
|
|
||||||
Feel free to test other exchanges and submit your feedback or PR to improve the bot or confirm exchanges that work flawlessly..
|
|
||||||
|
|
||||||
Some exchanges require special configuration, which can be found below.
|
|
||||||
|
|
||||||
### Sample exchange configuration
|
|
||||||
|
|
||||||
A exchange configuration for "binance" would look as follows:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"exchange": {
|
|
||||||
"name": "binance",
|
|
||||||
"key": "your_exchange_key",
|
|
||||||
"secret": "your_exchange_secret",
|
|
||||||
"ccxt_config": {},
|
|
||||||
"ccxt_async_config": {},
|
|
||||||
// ...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Setting rate limits
|
|
||||||
|
|
||||||
Usually, rate limits set by CCXT are reliable and work well.
|
|
||||||
In case of problems related to rate-limits (usually DDOS Exceptions in your logs), it's easy to change rateLimit settings to other values.
|
|
||||||
|
|
||||||
```json
|
|
||||||
"exchange": {
|
|
||||||
"name": "kraken",
|
|
||||||
"key": "your_exchange_key",
|
|
||||||
"secret": "your_exchange_secret",
|
|
||||||
"ccxt_config": {"enableRateLimit": true},
|
|
||||||
"ccxt_async_config": {
|
|
||||||
"enableRateLimit": true,
|
|
||||||
"rateLimit": 3100
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
This configuration enables kraken, as well as rate-limiting to avoid bans from the exchange.
|
|
||||||
`"rateLimit": 3100` defines a wait-event of 3.1s between each call. This can also be completely disabled by setting `"enableRateLimit"` to false.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Optimal settings for rate-limiting depend on the exchange and the size of the whitelist, so an ideal parameter will vary on many other settings.
|
|
||||||
We try to provide sensible defaults per exchange where possible, if you encounter bans please make sure that `"enableRateLimit"` is enabled and increase the `"rateLimit"` parameter step by step.
|
|
||||||
|
|
||||||
## Binance
|
## Binance
|
||||||
|
|
||||||
!!! Warning "Server location and geo-ip restrictions"
|
|
||||||
Please be aware that binance restrict api access regarding the server country. The currents and non exhaustive countries blocked are United States, Malaysia (Singapour), Ontario (Canada). Please go to [binance terms > b. Eligibility](https://www.binance.com/en/terms) to find up to date list.
|
|
||||||
|
|
||||||
Binance supports [time_in_force](configuration.md#understand-order_time_in_force).
|
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
!!! Tip "Stoploss on Exchange"
|
||||||
Binance supports `stoploss_on_exchange` and uses `stop-loss-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.
|
Binance supports `stoploss_on_exchange` and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it.
|
||||||
On futures, Binance supports both `stop-limit` as well as `stop-market` orders. You can use either `"limit"` or `"market"` in the `order_types.stoploss` configuration setting to decide which type to use.
|
|
||||||
|
|
||||||
### Binance Blacklist recommendation
|
### Binance Blacklist
|
||||||
|
|
||||||
For Binance, it is suggested to add `"BNB/<STAKE>"` to your blacklist to avoid issues, unless you are willing to maintain enough extra `BNB` on the account or unless you're willing to disable using `BNB` for fees.
|
For Binance, please add `"BNB/<STAKE>"` to your blacklist to avoid issues.
|
||||||
Binance accounts may use `BNB` for fees, and if a trade happens to be on `BNB`, further trades may consume this position and make the initial BNB trade unsellable as the expected amount is not there anymore.
|
Accounts having BNB accounts use this to pay for fees - if your first trade happens to be on `BNB`, further trades will consume this position and make the initial BNB trade unsellable as the expected amount is not there anymore.
|
||||||
|
|
||||||
### Binance sites
|
### Binance sites
|
||||||
|
|
||||||
@ -75,56 +19,6 @@ Binance has been split into 2, and users must use the correct ccxt exchange ID f
|
|||||||
* [binance.com](https://www.binance.com/) - International users. Use exchange id: `binance`.
|
* [binance.com](https://www.binance.com/) - International users. Use exchange id: `binance`.
|
||||||
* [binance.us](https://www.binance.us/) - US based users. Use exchange id: `binanceus`.
|
* [binance.us](https://www.binance.us/) - US based users. Use exchange id: `binanceus`.
|
||||||
|
|
||||||
### Binance RSA keys
|
|
||||||
|
|
||||||
Freqtrade supports binance RSA API keys.
|
|
||||||
|
|
||||||
We recommend to use them as environment variable.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
export FREQTRADE__EXCHANGE__SECRET="$(cat ./rsa_binance.private)"
|
|
||||||
```
|
|
||||||
|
|
||||||
They can however also be configured via configuration file. Since json doesn't support multi-line strings, you'll have to replace all newlines with `\n` to have a valid json file.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
// ...
|
|
||||||
"key": "<someapikey>",
|
|
||||||
"secret": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBABACAFQA<...>s8KX8=\n-----END PRIVATE KEY-----"
|
|
||||||
// ...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Binance Futures
|
|
||||||
|
|
||||||
Binance has specific (unfortunately complex) [Futures Trading Quantitative Rules](https://www.binance.com/en/support/faq/4f462ebe6ff445d4a170be7d9e897272) which need to be followed, and which prohibit a too low stake-amount (among others) for too many orders.
|
|
||||||
Violating these rules will result in a trading restriction.
|
|
||||||
|
|
||||||
When trading on Binance Futures market, orderbook must be used because there is no price ticker data for futures.
|
|
||||||
|
|
||||||
``` jsonc
|
|
||||||
"entry_pricing": {
|
|
||||||
"use_order_book": true,
|
|
||||||
"order_book_top": 1,
|
|
||||||
"check_depth_of_market": {
|
|
||||||
"enabled": false,
|
|
||||||
"bids_to_ask_delta": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exit_pricing": {
|
|
||||||
"use_order_book": true,
|
|
||||||
"order_book_top": 1
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Binance futures settings
|
|
||||||
|
|
||||||
Users will also have to have the futures-setting "Position Mode" set to "One-way Mode", and "Asset Mode" set to "Single-Asset Mode".
|
|
||||||
These settings will be checked on startup, and freqtrade will show an error if this setting is wrong.
|
|
||||||
|
|
||||||
![Binance futures settings](assets/binance_futures_settings.png)
|
|
||||||
|
|
||||||
Freqtrade will not attempt to change these settings.
|
|
||||||
|
|
||||||
## Kraken
|
## Kraken
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
!!! Tip "Stoploss on Exchange"
|
||||||
@ -162,12 +56,6 @@ Bittrex does not support market orders. If you have a message at the bot startup
|
|||||||
Bittrex also does not support `VolumePairlist` due to limited / split API constellation at the moment.
|
Bittrex also does not support `VolumePairlist` due to limited / split API constellation at the moment.
|
||||||
Please use `StaticPairlist`. Other pairlists (other than `VolumePairlist`) should not be affected.
|
Please use `StaticPairlist`. Other pairlists (other than `VolumePairlist`) should not be affected.
|
||||||
|
|
||||||
### Volume pairlist
|
|
||||||
|
|
||||||
Bittrex does not support the direct usage of VolumePairList. This can however be worked around by using the advanced mode with `lookback_days: 1` (or more), which will emulate 24h volume.
|
|
||||||
|
|
||||||
Read more in the [pairlist documentation](plugins.md#volumepairlist-advanced-mode).
|
|
||||||
|
|
||||||
### Restricted markets
|
### Restricted markets
|
||||||
|
|
||||||
Bittrex split its exchange into US and International versions.
|
Bittrex split its exchange into US and International versions.
|
||||||
@ -189,15 +77,34 @@ You can get a list of restricted markets by using the following snippet:
|
|||||||
``` python
|
``` python
|
||||||
import ccxt
|
import ccxt
|
||||||
ct = ccxt.bittrex()
|
ct = ccxt.bittrex()
|
||||||
lm = ct.load_markets()
|
_ = ct.load_markets()
|
||||||
|
res = [ f"{x['MarketCurrency']}/{x['BaseCurrency']}" for x in ct.publicGetMarkets()['result'] if x['IsRestricted']]
|
||||||
res = [p for p, x in lm.items() if 'US' in x['info']['prohibitedIn']]
|
|
||||||
print(res)
|
print(res)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## FTX
|
||||||
|
|
||||||
|
!!! Tip "Stoploss on Exchange"
|
||||||
|
FTX supports `stoploss_on_exchange` and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it.
|
||||||
|
You can use either `"limit"` or `"market"` in the `order_types.stoploss` configuration setting to decide which type of stoploss shall be used.
|
||||||
|
|
||||||
|
### Using subaccounts
|
||||||
|
|
||||||
|
To use subaccounts with FTX, you need to edit the configuration and add the following:
|
||||||
|
|
||||||
|
``` json
|
||||||
|
"exchange": {
|
||||||
|
"ccxt_config": {
|
||||||
|
"headers": {
|
||||||
|
"FTX-SUBACCOUNT": "name"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Kucoin
|
## Kucoin
|
||||||
|
|
||||||
Kucoin requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:
|
Kucoin requries a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"exchange": {
|
"exchange": {
|
||||||
@ -205,67 +112,12 @@ Kucoin requires a passphrase for each api key, you will therefore need to add th
|
|||||||
"key": "your_exchange_key",
|
"key": "your_exchange_key",
|
||||||
"secret": "your_exchange_secret",
|
"secret": "your_exchange_secret",
|
||||||
"password": "your_exchange_api_key_password",
|
"password": "your_exchange_api_key_password",
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Kucoin supports [time_in_force](configuration.md#understand-order_time_in_force).
|
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
|
||||||
Kucoin supports `stoploss_on_exchange` and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it.
|
|
||||||
You can use either `"limit"` or `"market"` in the `order_types.stoploss` configuration setting to decide which type of stoploss shall be used.
|
|
||||||
|
|
||||||
### Kucoin Blacklists
|
### Kucoin Blacklists
|
||||||
|
|
||||||
For Kucoin, it is suggested to add `"KCS/<STAKE>"` to your blacklist to avoid issues, unless you are willing to maintain enough extra `KCS` on the account or unless you're willing to disable using `KCS` for fees.
|
For Kucoin, please add `"KCS/<STAKE>"` to your blacklist to avoid issues.
|
||||||
Kucoin accounts may use `KCS` for fees, and if a trade happens to be on `KCS`, further trades may consume this position and make the initial `KCS` trade unsellable as the expected amount is not there anymore.
|
Accounts having KCS accounts use this to pay for fees - if your first trade happens to be on `KCS`, further trades will consume this position and make the initial KCS trade unsellable as the expected amount is not there anymore.
|
||||||
|
|
||||||
## Huobi
|
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
|
||||||
Huobi supports `stoploss_on_exchange` and uses `stop-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.
|
|
||||||
|
|
||||||
## OKX (former OKEX)
|
|
||||||
|
|
||||||
OKX requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"exchange": {
|
|
||||||
"name": "okx",
|
|
||||||
"key": "your_exchange_key",
|
|
||||||
"secret": "your_exchange_secret",
|
|
||||||
"password": "your_exchange_api_key_password",
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
OKX only provides 100 candles per api call. Therefore, the strategy will only have a pretty low amount of data available in backtesting mode.
|
|
||||||
|
|
||||||
!!! Warning "Futures"
|
|
||||||
OKX Futures has the concept of "position mode" - which can be "Buy/Sell" or long/short (hedge mode).
|
|
||||||
Freqtrade supports both modes (we recommend to use Buy/Sell mode) - but changing the mode mid-trading is not supported and will lead to exceptions and failures to place trades.
|
|
||||||
OKX also only provides MARK candles for the past ~3 months. Backtesting futures prior to that date will therefore lead to slight deviations, as funding-fees cannot be calculated correctly without this data.
|
|
||||||
|
|
||||||
## Gate.io
|
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
|
||||||
Gate.io supports `stoploss_on_exchange` and uses `stop-loss-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange..
|
|
||||||
|
|
||||||
Gate.io allows the use of `POINT` to pay for fees. As this is not a tradable currency (no regular market available), automatic fee calculations will fail (and default to a fee of 0).
|
|
||||||
The configuration parameter `exchange.unknown_fee_rate` can be used to specify the exchange rate between Point and the stake currency. Obviously, changing the stake-currency will also require changes to this value.
|
|
||||||
|
|
||||||
## Bybit
|
|
||||||
|
|
||||||
Futures trading on bybit is currently supported for USDT markets, and will use isolated futures mode.
|
|
||||||
Users with unified accounts (there's no way back) can create a Sub-account which will start as "non-unified", and can therefore use isolated futures.
|
|
||||||
On startup, freqtrade will set the position mode to "One-way Mode" for the whole (sub)account. This avoids making this call over and over again (slowing down bot operations), but means that changes to this setting may result in exceptions and errors.
|
|
||||||
|
|
||||||
As bybit doesn't provide funding rate history, the dry-run calculation is used for live trades as well.
|
|
||||||
|
|
||||||
!!! Tip "Stoploss on Exchange"
|
|
||||||
Bybit (futures only) supports `stoploss_on_exchange` and uses `stop-loss-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.
|
|
||||||
On futures, Bybit supports both `stop-limit` as well as `stop-market` orders. You can use either `"limit"` or `"market"` in the `order_types.stoploss` configuration setting to decide which type to use.
|
|
||||||
|
|
||||||
## All exchanges
|
## All exchanges
|
||||||
|
|
||||||
@ -302,11 +154,9 @@ For example, to test the order type `FOK` with Kraken, and modify candle limit t
|
|||||||
"exchange": {
|
"exchange": {
|
||||||
"name": "kraken",
|
"name": "kraken",
|
||||||
"_ft_has_params": {
|
"_ft_has_params": {
|
||||||
"order_time_in_force": ["GTC", "FOK"],
|
"order_time_in_force": ["gtc", "fok"],
|
||||||
"ohlcv_candle_limit": 200
|
"ohlcv_candle_limit": 200
|
||||||
}
|
}
|
||||||
//...
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
|
116
docs/faq.md
@ -2,19 +2,17 @@
|
|||||||
|
|
||||||
## Supported Markets
|
## Supported Markets
|
||||||
|
|
||||||
Freqtrade supports spot trading, as well as (isolated) futures trading for some selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an uptodate list of supported exchanges.
|
Freqtrade supports spot trading only.
|
||||||
|
|
||||||
### Can my bot open short positions?
|
### Can I open short positions?
|
||||||
|
|
||||||
Freqtrade can open short positions in futures markets.
|
No, Freqtrade does not support trading with margin / leverage, and cannot open short positions.
|
||||||
This requires the strategy to be made for this - and `"trading_mode": "futures"` in the configuration.
|
|
||||||
Please make sure to read the [relevant documentation page](leverage.md) first.
|
|
||||||
|
|
||||||
In spot markets, you can in some cases use leveraged spot tokens, which reflect an inverted pair (eg. BTCUP/USD, BTCDOWN/USD, ETHBULL/USD, ETHBEAR/USD,...) which can be traded with Freqtrade.
|
In some cases, your exchange may provide leveraged spot tokens which can be traded with Freqtrade eg. BTCUP/USD, BTCDOWN/USD, ETHBULL/USD, ETHBEAR/USD, etc...
|
||||||
|
|
||||||
### Can my bot trade options or futures?
|
### Can I trade options or futures?
|
||||||
|
|
||||||
Futures trading is supported for selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an uptodate list of supported exchanges.
|
No, options and futures trading are not supported.
|
||||||
|
|
||||||
## Beginner Tips & Tricks
|
## Beginner Tips & Tricks
|
||||||
|
|
||||||
@ -22,13 +20,6 @@ Futures trading is supported for selected exchanges. Please refer to the [docume
|
|||||||
|
|
||||||
## Freqtrade common issues
|
## Freqtrade common issues
|
||||||
|
|
||||||
### Can freqtrade open multiple positions on the same pair in parallel?
|
|
||||||
|
|
||||||
No. Freqtrade will only open one position per pair at a time.
|
|
||||||
You can however use the [`adjust_trade_position()` callback](strategy-callbacks.md#adjust-trade-position) to adjust an open position.
|
|
||||||
|
|
||||||
Backtesting provides an option for this in `--eps` - however this is only there to highlight "hidden" signals, and will not work in live.
|
|
||||||
|
|
||||||
### The bot does not start
|
### The bot does not start
|
||||||
|
|
||||||
Running the bot with `freqtrade trade --config config.json` shows the output `freqtrade: command not found`.
|
Running the bot with `freqtrade trade --config config.json` shows the output `freqtrade: command not found`.
|
||||||
@ -37,7 +28,7 @@ This could be caused by the following reasons:
|
|||||||
|
|
||||||
* The virtual environment is not active.
|
* The virtual environment is not active.
|
||||||
* Run `source .env/bin/activate` to activate the virtual environment.
|
* Run `source .env/bin/activate` to activate the virtual environment.
|
||||||
* The installation did not complete successfully.
|
* The installation did not work correctly.
|
||||||
* Please check the [Installation documentation](installation.md).
|
* Please check the [Installation documentation](installation.md).
|
||||||
|
|
||||||
### I have waited 5 minutes, why hasn't the bot made any trades yet?
|
### I have waited 5 minutes, why hasn't the bot made any trades yet?
|
||||||
@ -51,7 +42,7 @@ position for a trade. Be patient!
|
|||||||
### I have made 12 trades already, why is my total profit negative?
|
### I have made 12 trades already, why is my total profit negative?
|
||||||
|
|
||||||
I understand your disappointment but unfortunately 12 trades is just
|
I understand your disappointment but unfortunately 12 trades is just
|
||||||
not enough to say anything. If you run backtesting, you can see that the
|
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
|
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
|
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
|
specific coins that you have traded tens if not hundreds of times. We
|
||||||
@ -63,30 +54,13 @@ you can't say much from few trades.
|
|||||||
|
|
||||||
Yes. You can edit your config and use the `/reload_config` command to reload the configuration. The bot will stop, reload the configuration and strategy and will restart with the new configuration and strategy.
|
Yes. You can edit your config and use the `/reload_config` command to reload the configuration. The bot will stop, reload the configuration and strategy and will restart with the new configuration and strategy.
|
||||||
|
|
||||||
### Why does my bot not sell everything it bought?
|
### I want to improve the bot with a new strategy
|
||||||
|
|
||||||
This is called "coin dust" and can happen on all exchanges.
|
That's great. We have a nice backtesting and hyperoptimization setup. See the tutorial [here|Testing-new-strategies-with-Hyperopt](bot-usage.md#hyperopt-commands).
|
||||||
It happens because many exchanges subtract fees from the "receiving currency" - so you buy 100 COIN - but you only get 99.9 COIN.
|
|
||||||
As COIN is trading in full lot sizes (1COIN steps), you cannot sell 0.9 COIN (or 99.9 COIN) - but you need to round down to 99 COIN.
|
|
||||||
|
|
||||||
This is not a bot-problem, but will also happen while manual trading.
|
### Is there a setting to only SELL the coins being held and not perform anymore BUYS?
|
||||||
|
|
||||||
While freqtrade can handle this (it'll sell 99 COIN), fees are often below the minimum tradable lot-size (you can only trade full COIN, not 0.9 COIN).
|
You can use the `/stopbuy` command in Telegram to prevent future buys, followed by `/forcesell all` (sell all open trades).
|
||||||
Leaving the dust (0.9 COIN) on the exchange makes usually sense, as the next time freqtrade buys COIN, it'll eat into the remaining small balance, this time selling everything it bought, and therefore slowly declining the dust balance (although it most likely will never reach exactly 0).
|
|
||||||
|
|
||||||
Where possible (e.g. on binance), the use of the exchange's dedicated fee currency will fix this.
|
|
||||||
On binance, it's sufficient to have BNB in your account, and have "Pay fees in BNB" enabled in your profile. Your BNB balance will slowly decline (as it's used to pay fees) - but you'll no longer encounter dust (Freqtrade will include the fees in the profit calculations).
|
|
||||||
Other exchanges don't offer such possibilities, where it's simply something you'll have to accept or move to a different exchange.
|
|
||||||
|
|
||||||
### I want to use incomplete candles
|
|
||||||
|
|
||||||
Freqtrade will not provide incomplete candles to strategies. Using incomplete candles will lead to repainting and consequently to strategies with "ghost" buys, which are impossible to both backtest, and verify after they happened.
|
|
||||||
|
|
||||||
You can use "current" market data by using the [dataprovider](strategy-customization.md#orderbookpair-maximum)'s orderbook or ticker methods - which however cannot be used during backtesting.
|
|
||||||
|
|
||||||
### Is there a setting to only Exit the trades being held and not perform any new Entries?
|
|
||||||
|
|
||||||
You can use the `/stopentry` command in Telegram to prevent future trade entry, followed by `/forceexit all` (sell all open trades).
|
|
||||||
|
|
||||||
### I want to run multiple bots on the same machine
|
### I want to run multiple bots on the same machine
|
||||||
|
|
||||||
@ -102,40 +76,22 @@ If this happens for all pairs in the pairlist, this might indicate a recent exch
|
|||||||
|
|
||||||
Irrespectively of the reason, Freqtrade will fill up these candles with "empty" candles, where open, high, low and close are set to the previous candle close - and volume is empty. In a chart, this will look like a `_` - and is aligned with how exchanges usually represent 0 volume candles.
|
Irrespectively of the reason, Freqtrade will fill up these candles with "empty" candles, where open, high, low and close are set to the previous candle close - and volume is empty. In a chart, this will look like a `_` - and is aligned with how exchanges usually represent 0 volume candles.
|
||||||
|
|
||||||
### I'm getting "Price jump between 2 candles detected"
|
|
||||||
|
|
||||||
This message is a warning that the candles had a price jump of > 30%.
|
|
||||||
This might be a sign that the pair stopped trading, and some token exchange took place (e.g. COCOS in 2021 - where price jumped from 0.0000154 to 0.01621).
|
|
||||||
This message is often accompanied by ["Missing data fillup"](#im-getting-missing-data-fillup-messages-in-the-log) - as trading on such pairs is often stopped for some time.
|
|
||||||
|
|
||||||
### I'm getting "Outdated history for pair xxx" in the log
|
|
||||||
|
|
||||||
The bot is trying to tell you that it got an outdated last candle (not the last complete candle).
|
|
||||||
As a consequence, Freqtrade will not enter a trade for this pair - as trading on old information is usually not what is desired.
|
|
||||||
|
|
||||||
This warning can point to one of the below problems:
|
|
||||||
|
|
||||||
* Exchange downtime -> Check your exchange status page / blog / twitter feed for details.
|
|
||||||
* Wrong system time -> Ensure your system-time is correct.
|
|
||||||
* Barely traded pair -> Check the pair on the exchange webpage, look at the timeframe your strategy uses. If the pair does not have any volume in some candles (usually visualized with a "volume 0" bar, and a "_" as candle), this pair did not have any trades in this timeframe. These pairs should ideally be avoided, as they can cause problems with order-filling.
|
|
||||||
* API problem -> API returns wrong data (this only here for completeness, and should not happen with supported exchanges).
|
|
||||||
|
|
||||||
### I'm getting the "RESTRICTED_MARKET" message in the log
|
### I'm getting the "RESTRICTED_MARKET" message in the log
|
||||||
|
|
||||||
Currently known to happen for US Bittrex users.
|
Currently known to happen for US Bittrex users.
|
||||||
|
|
||||||
Read [the Bittrex section about restricted markets](exchanges.md#restricted-markets) for more information.
|
Read [the Bittrex section about restricted markets](exchanges.md#restricted-markets) for more information.
|
||||||
|
|
||||||
### I'm getting the "Exchange XXX does not support market orders." message and cannot run my strategy
|
### I'm getting the "Exchange Bittrex does not support market orders." message and cannot run my strategy
|
||||||
|
|
||||||
As the message says, your exchange does not support market orders and you have one of the [order types](configuration.md/#understand-order_types) set to "market". Your strategy was probably written with other exchanges in mind and sets "market" orders for "stoploss" orders, which is correct and preferable for most of the exchanges supporting market orders (but not for Bittrex and Gate.io).
|
As the message says, Bittrex does not support market orders and you have one of the [order types](configuration.md/#understand-order_types) set to "market". Your strategy was probably written with other exchanges in mind and sets "market" orders for "stoploss" orders, which is correct and preferable for most of the exchanges supporting market orders (but not for Bittrex).
|
||||||
|
|
||||||
To fix this, redefine order types in the strategy to use "limit" instead of "market":
|
To fix it for Bittrex, redefine order types in the strategy to use "limit" instead of "market":
|
||||||
|
|
||||||
``` python
|
```
|
||||||
order_types = {
|
order_types = {
|
||||||
...
|
...
|
||||||
"stoploss": "limit",
|
'stoploss': 'limit',
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -180,8 +136,6 @@ On Windows, the `--logfile` option is also supported by Freqtrade and you can us
|
|||||||
> type \path\to\mylogfile.log | findstr "something"
|
> type \path\to\mylogfile.log | findstr "something"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Hyperopt module
|
|
||||||
|
|
||||||
### Why does freqtrade not have GPU support?
|
### Why does freqtrade not have GPU support?
|
||||||
|
|
||||||
First of all, most indicator libraries don't have GPU support - as such, there would be little benefit for indicator calculations.
|
First of all, most indicator libraries don't have GPU support - as such, there would be little benefit for indicator calculations.
|
||||||
@ -198,25 +152,27 @@ The benefit of using GPU would therefore be pretty slim - and will not justify t
|
|||||||
|
|
||||||
There is however nothing preventing you from using GPU-enabled indicators within your strategy if you think you must have this - you will however probably be disappointed by the slim gain that will give you (compared to the complexity).
|
There is however nothing preventing you from using GPU-enabled indicators within your strategy if you think you must have this - you will however probably be disappointed by the slim gain that will give you (compared to the complexity).
|
||||||
|
|
||||||
|
## Hyperopt module
|
||||||
|
|
||||||
### How many epochs do I need to get a good Hyperopt result?
|
### How many epochs do I need to get a good Hyperopt result?
|
||||||
|
|
||||||
Per default Hyperopt called without the `-e`/`--epochs` command line option will only
|
Per default Hyperopt called without the `-e`/`--epochs` command line option will only
|
||||||
run 100 epochs, means 100 evaluations of your triggers, guards, ... Too few
|
run 100 epochs, means 100 evaluations of your triggers, guards, ... Too few
|
||||||
to find a great result (unless if you are very lucky), so you probably
|
to find a great result (unless if you are very lucky), so you probably
|
||||||
have to run it for 10000 or more. But it will take an eternity to
|
have to run it for 10.000 or more. But it will take an eternity to
|
||||||
compute.
|
compute.
|
||||||
|
|
||||||
Since hyperopt uses Bayesian search, running for too many epochs may not produce greater results.
|
Since hyperopt uses Bayesian search, running for too many epochs may not produce greater results.
|
||||||
|
|
||||||
It's therefore recommended to run between 500-1000 epochs over and over until you hit at least 10000 epochs in total (or are satisfied with the result). You can best judge by looking at the results - if the bot keeps discovering better strategies, it's best to keep on going.
|
It's therefore recommended to run between 500-1000 epochs over and over until you hit at least 10.000 epochs in total (or are satisfied with the result). You can best judge by looking at the results - if the bot keeps discovering better strategies, it's best to keep on going.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy SampleStrategy -e 1000
|
freqtrade hyperopt --hyperopt SampleHyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy SampleStrategy -e 1000
|
||||||
```
|
```
|
||||||
|
|
||||||
### Why does it take a long time to run hyperopt?
|
### Why does it take a long time to run hyperopt?
|
||||||
|
|
||||||
* Discovering a great strategy with Hyperopt takes time. Study www.freqtrade.io, the Freqtrade Documentation page, join the Freqtrade [discord community](https://discord.gg/p7nuUNVfP7). While you patiently wait for the most advanced, free crypto bot in the world, to hand you a possible golden strategy specially designed just for you.
|
* Discovering a great strategy with Hyperopt takes time. Study www.freqtrade.io, the Freqtrade Documentation page, join the Freqtrade [Slack community](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw) - or the Freqtrade [discord community](https://discord.gg/p7nuUNVfP7). While you patiently wait for the most advanced, free crypto bot in the world, to hand you a possible golden strategy specially designed just for you.
|
||||||
|
|
||||||
* If you wonder why it can take from 20 minutes to days to do 1000 epochs here are some answers:
|
* If you wonder why it can take from 20 minutes to days to do 1000 epochs here are some answers:
|
||||||
|
|
||||||
@ -232,9 +188,9 @@ already 8\*10^9\*10 evaluations. A roughly total of 80 billion evaluations.
|
|||||||
Did you run 100 000 evaluations? Congrats, you've done roughly 1 / 100 000 th
|
Did you run 100 000 evaluations? Congrats, you've done roughly 1 / 100 000 th
|
||||||
of the search space, assuming that the bot never tests the same parameters more than once.
|
of the search space, assuming that the bot never tests the same parameters more than once.
|
||||||
|
|
||||||
* The time it takes to run 1000 hyperopt epochs depends on things like: The available cpu, hard-disk, ram, timeframe, timerange, indicator settings, indicator count, amount of coins that hyperopt test strategies on and the resulting trade count - which can be 650 trades in a year or 100000 trades depending if the strategy aims for big profits by trading rarely or for many low profit trades.
|
* The time it takes to run 1000 hyperopt epochs depends on things like: The available cpu, hard-disk, ram, timeframe, timerange, indicator settings, indicator count, amount of coins that hyperopt test strategies on and the resulting trade count - which can be 650 trades in a year or 10.0000 trades depending if the strategy aims for big profits by trading rarely or for many low profit trades.
|
||||||
|
|
||||||
Example: 4% profit 650 times vs 0,3% profit a trade 10000 times in a year. If we assume you set the --timerange to 365 days.
|
Example: 4% profit 650 times vs 0,3% profit a trade 10.000 times in a year. If we assume you set the --timerange to 365 days.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
`freqtrade --config config.json --strategy SampleStrategy --hyperopt SampleHyperopt -e 1000 --timerange 20190601-20200601`
|
`freqtrade --config config.json --strategy SampleStrategy --hyperopt SampleHyperopt -e 1000 --timerange 20190601-20200601`
|
||||||
@ -248,26 +204,8 @@ The Edge module is mostly a result of brainstorming of [@mishaker](https://githu
|
|||||||
You can find further info on expectancy, win rate, risk management and position size in the following sources:
|
You can find further info on expectancy, win rate, risk management and position size in the following sources:
|
||||||
|
|
||||||
- https://www.tradeciety.com/ultimate-math-guide-for-traders/
|
- https://www.tradeciety.com/ultimate-math-guide-for-traders/
|
||||||
|
- http://www.vantharp.com/tharp-concepts/expectancy.asp
|
||||||
- https://samuraitradingacademy.com/trading-expectancy/
|
- https://samuraitradingacademy.com/trading-expectancy/
|
||||||
- https://www.learningmarkets.com/determining-expectancy-in-your-trading/
|
- https://www.learningmarkets.com/determining-expectancy-in-your-trading/
|
||||||
- https://www.lonestocktrader.com/make-money-trading-positive-expectancy/
|
- http://www.lonestocktrader.com/make-money-trading-positive-expectancy/
|
||||||
- https://www.babypips.com/trading/trade-expectancy-matter
|
- https://www.babypips.com/trading/trade-expectancy-matter
|
||||||
|
|
||||||
## Official channels
|
|
||||||
|
|
||||||
Freqtrade is using exclusively the following official channels:
|
|
||||||
|
|
||||||
* [Freqtrade discord server](https://discord.gg/p7nuUNVfP7)
|
|
||||||
* [Freqtrade documentation (https://freqtrade.io)](https://freqtrade.io)
|
|
||||||
* [Freqtrade github organization](https://github.com/freqtrade)
|
|
||||||
|
|
||||||
Nobody affiliated with the freqtrade project will ask you about your exchange keys or anything else exposing your funds to exploitation.
|
|
||||||
Should you be asked to expose your exchange keys or send funds to some random wallet, then please don't follow these instructions.
|
|
||||||
|
|
||||||
Failing to follow these guidelines will not be responsibility of freqtrade.
|
|
||||||
|
|
||||||
## "Freqtrade token"
|
|
||||||
|
|
||||||
Freqtrade does not have a Crypto token offering.
|
|
||||||
|
|
||||||
Token offerings you find on the internet referring Freqtrade, FreqAI or freqUI must be considered to be a scam, trying to exploit freqtrade's popularity for their own, nefarious gains.
|
|
||||||
|
@ -1,396 +0,0 @@
|
|||||||
# Configuration
|
|
||||||
|
|
||||||
FreqAI is configured through the typical [Freqtrade config file](configuration.md) and the standard [Freqtrade strategy](strategy-customization.md). Examples of FreqAI config and strategy files can be found in `config_examples/config_freqai.example.json` and `freqtrade/templates/FreqaiExampleStrategy.py`, respectively.
|
|
||||||
|
|
||||||
## Setting up the configuration file
|
|
||||||
|
|
||||||
Although there are plenty of additional parameters to choose from, as highlighted in the [parameter table](freqai-parameter-table.md#parameter-table), a FreqAI config must at minimum include the following parameters (the parameter values are only examples):
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"enabled": true,
|
|
||||||
"purge_old_models": 2,
|
|
||||||
"train_period_days": 30,
|
|
||||||
"backtest_period_days": 7,
|
|
||||||
"identifier" : "unique-id",
|
|
||||||
"feature_parameters" : {
|
|
||||||
"include_timeframes": ["5m","15m","4h"],
|
|
||||||
"include_corr_pairlist": [
|
|
||||||
"ETH/USD",
|
|
||||||
"LINK/USD",
|
|
||||||
"BNB/USD"
|
|
||||||
],
|
|
||||||
"label_period_candles": 24,
|
|
||||||
"include_shifted_candles": 2,
|
|
||||||
"indicator_periods_candles": [10, 20]
|
|
||||||
},
|
|
||||||
"data_split_parameters" : {
|
|
||||||
"test_size": 0.25
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A full example config is available in `config_examples/config_freqai.example.json`.
|
|
||||||
|
|
||||||
## Building a FreqAI strategy
|
|
||||||
|
|
||||||
The FreqAI strategy requires including the following lines of code in the standard [Freqtrade strategy](strategy-customization.md):
|
|
||||||
|
|
||||||
```python
|
|
||||||
# user should define the maximum startup candle count (the largest number of candles
|
|
||||||
# passed to any single indicator)
|
|
||||||
startup_candle_count: int = 20
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
|
|
||||||
# the model will return all labels created by user in `set_freqai_labels()`
|
|
||||||
# (& appended targets), an indication of whether or not the prediction should be accepted,
|
|
||||||
# the target mean/std values for each of the labels created by user in
|
|
||||||
# `feature_engineering_*` for each training period.
|
|
||||||
|
|
||||||
dataframe = self.freqai.start(dataframe, metadata, self)
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def feature_engineering_expand_all(self, dataframe, period, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This function will automatically expand the defined features on the config defined
|
|
||||||
`indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and
|
|
||||||
`include_corr_pairs`. In other words, a single feature defined in this function
|
|
||||||
will automatically expand to a total of
|
|
||||||
`indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *
|
|
||||||
`include_corr_pairs` numbers of features added to the model.
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
:param period: period of the indicator - usage example:
|
|
||||||
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
|
||||||
"""
|
|
||||||
|
|
||||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-adx-period"] = ta.ADX(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-sma-period"] = ta.SMA(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def feature_engineering_expand_basic(self, dataframe, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This function will automatically expand the defined features on the config defined
|
|
||||||
`include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.
|
|
||||||
In other words, a single feature defined in this function
|
|
||||||
will automatically expand to a total of
|
|
||||||
`include_timeframes` * `include_shifted_candles` * `include_corr_pairs`
|
|
||||||
numbers of features added to the model.
|
|
||||||
|
|
||||||
Features defined here will *not* be automatically duplicated on user defined
|
|
||||||
`indicator_periods_candles`
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
|
||||||
dataframe["%-ema-200"] = ta.EMA(dataframe, timeperiod=200)
|
|
||||||
"""
|
|
||||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
|
||||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
|
||||||
dataframe["%-raw_price"] = dataframe["close"]
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def feature_engineering_standard(self, dataframe, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This optional function will be called once with the dataframe of the base timeframe.
|
|
||||||
This is the final function to be called, which means that the dataframe entering this
|
|
||||||
function will contain all the features and columns created by all other
|
|
||||||
freqai_feature_engineering_* functions.
|
|
||||||
|
|
||||||
This function is a good place to do custom exotic feature extractions (e.g. tsfresh).
|
|
||||||
This function is a good place for any feature that should not be auto-expanded upon
|
|
||||||
(e.g. day of the week).
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
|
|
||||||
"""
|
|
||||||
dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
|
|
||||||
dataframe["%-hour_of_day"] = (dataframe["date"].dt.hour + 1) / 25
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
Required function to set the targets for the model.
|
|
||||||
All targets must be prepended with `&` to be recognized by the FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the targets
|
|
||||||
usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"]
|
|
||||||
"""
|
|
||||||
dataframe["&-s_close"] = (
|
|
||||||
dataframe["close"]
|
|
||||||
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
|
|
||||||
.rolling(self.freqai_info["feature_parameters"]["label_period_candles"])
|
|
||||||
.mean()
|
|
||||||
/ dataframe["close"]
|
|
||||||
- 1
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Notice how the `feature_engineering_*()` is where [features](freqai-feature-engineering.md#feature-engineering) are added. Meanwhile `set_freqai_targets()` adds the labels/targets. A full example strategy is available in `templates/FreqaiExampleStrategy.py`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
The `self.freqai.start()` function cannot be called outside the `populate_indicators()`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Features **must** be defined in `feature_engineering_*()`. Defining FreqAI features in `populate_indicators()`
|
|
||||||
will cause the algorithm to fail in live/dry mode. In order to add generalized features that are not associated with a specific pair or timeframe, you should use `feature_engineering_standard()`
|
|
||||||
(as exemplified in `freqtrade/templates/FreqaiExampleStrategy.py`).
|
|
||||||
|
|
||||||
## Important dataframe key patterns
|
|
||||||
|
|
||||||
Below are the values you can expect to include/use inside a typical strategy dataframe (`df[]`):
|
|
||||||
|
|
||||||
| DataFrame Key | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| `df['&*']` | Any dataframe column prepended with `&` in `set_freqai_targets()` is treated as a training target (label) inside FreqAI (typically following the naming convention `&-s*`). For example, to predict the close price 40 candles into the future, you would set `df['&-s_close'] = df['close'].shift(-self.freqai_info["feature_parameters"]["label_period_candles"])` with `"label_period_candles": 40` in the config. FreqAI makes the predictions and gives them back under the same key (`df['&-s_close']`) to be used in `populate_entry/exit_trend()`. <br> **Datatype:** Depends on the output of the model.
|
|
||||||
| `df['&*_std/mean']` | Standard deviation and mean values of the defined labels during training (or live tracking with `fit_live_predictions_candles`). Commonly used to understand the rarity of a prediction (use the z-score as shown in `templates/FreqaiExampleStrategy.py` and explained [here](#creating-a-dynamic-target-threshold) to evaluate how often a particular prediction was observed during training or historically with `fit_live_predictions_candles`). <br> **Datatype:** Float.
|
|
||||||
| `df['do_predict']` | Indication of an outlier data point. The return value is integer between -2 and 2, which lets you know if the prediction is trustworthy or not. `do_predict==1` means that the prediction is trustworthy. If the Dissimilarity Index (DI, see details [here](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di)) of the input data point is above the threshold defined in the config, FreqAI will subtract 1 from `do_predict`, resulting in `do_predict==0`. If `use_SVM_to_remove_outliers()` is active, the Support Vector Machine (SVM, see details [here](freqai-feature-engineering.md#identifying-outliers-using-a-support-vector-machine-svm)) may also detect outliers in training and prediction data. In this case, the SVM will also subtract 1 from `do_predict`. If the input data point was considered an outlier by the SVM but not by the DI, or vice versa, the result will be `do_predict==0`. If both the DI and the SVM considers the input data point to be an outlier, the result will be `do_predict==-1`. As with the SVM, if `use_DBSCAN_to_remove_outliers` is active, DBSCAN (see details [here](freqai-feature-engineering.md#identifying-outliers-with-dbscan)) may also detect outliers and subtract 1 from `do_predict`. Hence, if both the SVM and DBSCAN are active and identify a datapoint that was above the DI threshold as an outlier, the result will be `do_predict==-2`. A particular case is when `do_predict == 2`, which means that the model has expired due to exceeding `expired_hours`. <br> **Datatype:** Integer between -2 and 2.
|
|
||||||
| `df['DI_values']` | Dissimilarity Index (DI) values are proxies for the level of confidence FreqAI has in the prediction. A lower DI means the prediction is close to the training data, i.e., higher prediction confidence. See details about the DI [here](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di). <br> **Datatype:** Float.
|
|
||||||
| `df['%*']` | Any dataframe column prepended with `%` in `feature_engineering_*()` is treated as a training feature. For example, you can include the RSI in the training feature set (similar to in `templates/FreqaiExampleStrategy.py`) by setting `df['%-rsi']`. See more details on how this is done [here](freqai-feature-engineering.md). <br> **Note:** Since the number of features prepended with `%` can multiply very quickly (10s of thousands of features are easily engineered using the multiplictative functionality of, e.g., `include_shifted_candles` and `include_timeframes` as described in the [parameter table](freqai-parameter-table.md)), these features are removed from the dataframe that is returned from FreqAI to the strategy. To keep a particular type of feature for plotting purposes, you would prepend it with `%%`. <br> **Datatype:** Depends on the output of the model.
|
|
||||||
|
|
||||||
## Setting the `startup_candle_count`
|
|
||||||
|
|
||||||
The `startup_candle_count` in the FreqAI strategy needs to be set up in the same way as in the standard Freqtrade strategy (see details [here](strategy-customization.md#strategy-startup-period)). This value is used by Freqtrade to ensure that a sufficient amount of data is provided when calling the `dataprovider`, to avoid any NaNs at the beginning of the first training. You can easily set this value by identifying the longest period (in candle units) which is passed to the indicator creation functions (e.g., TA-Lib functions). In the presented example, `startup_candle_count` is 20 since this is the maximum value in `indicators_periods_candles`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
There are instances where the TA-Lib functions actually require more data than just the passed `period` or else the feature dataset gets populated with NaNs. Anecdotally, multiplying the `startup_candle_count` by 2 always leads to a fully NaN free training dataset. Hence, it is typically safest to multiply the expected `startup_candle_count` by 2. Look out for this log message to confirm that the data is clean:
|
|
||||||
|
|
||||||
```
|
|
||||||
2022-08-31 15:14:04 - freqtrade.freqai.data_kitchen - INFO - dropped 0 training points due to NaNs in populated dataset 4319.
|
|
||||||
```
|
|
||||||
|
|
||||||
## Creating a dynamic target threshold
|
|
||||||
|
|
||||||
Deciding when to enter or exit a trade can be done in a dynamic way to reflect current market conditions. FreqAI allows you to return additional information from the training of a model (more info [here](freqai-feature-engineering.md#returning-additional-info-from-training)). For example, the `&*_std/mean` return values describe the statistical distribution of the target/label *during the most recent training*. Comparing a given prediction to these values allows you to know the rarity of the prediction. In `templates/FreqaiExampleStrategy.py`, the `target_roi` and `sell_roi` are defined to be 1.25 z-scores away from the mean which causes predictions that are closer to the mean to be filtered out.
|
|
||||||
|
|
||||||
```python
|
|
||||||
dataframe["target_roi"] = dataframe["&-s_close_mean"] + dataframe["&-s_close_std"] * 1.25
|
|
||||||
dataframe["sell_roi"] = dataframe["&-s_close_mean"] - dataframe["&-s_close_std"] * 1.25
|
|
||||||
```
|
|
||||||
|
|
||||||
To consider the population of *historical predictions* for creating the dynamic target instead of information from the training as discussed above, you would set `fit_live_predictions_candles` in the config to the number of historical prediction candles you wish to use to generate target statistics.
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"fit_live_predictions_candles": 300,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If this value is set, FreqAI will initially use the predictions from the training data and subsequently begin introducing real prediction data as it is generated. FreqAI will save this historical data to be reloaded if you stop and restart a model with the same `identifier`.
|
|
||||||
|
|
||||||
## Using different prediction models
|
|
||||||
|
|
||||||
FreqAI has multiple example prediction model libraries that are ready to be used as is via the flag `--freqaimodel`. These libraries include `CatBoost`, `LightGBM`, and `XGBoost` regression, classification, and multi-target models, and can be found in `freqai/prediction_models/`.
|
|
||||||
|
|
||||||
Regression and classification models differ in what targets they predict - a regression model will predict a target of continuous values, for example what price BTC will be at tomorrow, whilst a classifier will predict a target of discrete values, for example if the price of BTC will go up tomorrow or not. This means that you have to specify your targets differently depending on which model type you are using (see details [below](#setting-model-targets)).
|
|
||||||
|
|
||||||
All of the aforementioned model libraries implement gradient boosted decision tree algorithms. They all work on the principle of ensemble learning, where predictions from multiple simple learners are combined to get a final prediction that is more stable and generalized. The simple learners in this case are decision trees. Gradient boosting refers to the method of learning, where each simple learner is built in sequence - the subsequent learner is used to improve on the error from the previous learner. If you want to learn more about the different model libraries you can find the information in their respective docs:
|
|
||||||
|
|
||||||
* CatBoost: https://catboost.ai/en/docs/
|
|
||||||
* LightGBM: https://lightgbm.readthedocs.io/en/v3.3.2/#
|
|
||||||
* XGBoost: https://xgboost.readthedocs.io/en/stable/#
|
|
||||||
|
|
||||||
There are also numerous online articles describing and comparing the algorithms. Some relatively lightweight examples would be [CatBoost vs. LightGBM vs. XGBoost — Which is the best algorithm?](https://towardsdatascience.com/catboost-vs-lightgbm-vs-xgboost-c80f40662924#:~:text=In%20CatBoost%2C%20symmetric%20trees%2C%20or,the%20same%20depth%20can%20differ.) and [XGBoost, LightGBM or CatBoost — which boosting algorithm should I use?](https://medium.com/riskified-technology/xgboost-lightgbm-or-catboost-which-boosting-algorithm-should-i-use-e7fda7bb36bc). Keep in mind that the performance of each model is highly dependent on the application and so any reported metrics might not be true for your particular use of the model.
|
|
||||||
|
|
||||||
Apart from the models already available in FreqAI, it is also possible to customize and create your own prediction models using the `IFreqaiModel` class. You are encouraged to inherit `fit()`, `train()`, and `predict()` to customize various aspects of the training procedures. You can place custom FreqAI models in `user_data/freqaimodels` - and freqtrade will pick them up from there based on the provided `--freqaimodel` name - which has to correspond to the class name of your custom model.
|
|
||||||
Make sure to use unique names to avoid overriding built-in models.
|
|
||||||
|
|
||||||
### Setting model targets
|
|
||||||
|
|
||||||
#### Regressors
|
|
||||||
|
|
||||||
If you are using a regressor, you need to specify a target that has continuous values. FreqAI includes a variety of regressors, such as the `CatboostRegressor`via the flag `--freqaimodel CatboostRegressor`. An example of how you could set a regression target for predicting the price 100 candles into the future would be
|
|
||||||
|
|
||||||
```python
|
|
||||||
df['&s-close_price'] = df['close'].shift(-100)
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want to predict multiple targets, you need to define multiple labels using the same syntax as shown above.
|
|
||||||
|
|
||||||
#### Classifiers
|
|
||||||
|
|
||||||
If you are using a classifier, you need to specify a target that has discrete values. FreqAI includes a variety of classifiers, such as the `CatboostClassifier` via the flag `--freqaimodel CatboostClassifier`. If you elects to use a classifier, the classes need to be set using strings. For example, if you want to predict if the price 100 candles into the future goes up or down you would set
|
|
||||||
|
|
||||||
```python
|
|
||||||
df['&s-up_or_down'] = np.where( df["close"].shift(-100) > df["close"], 'up', 'down')
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want to predict multiple targets you must specify all labels in the same label column. You could, for example, add the label `same` to define where the price was unchanged by setting
|
|
||||||
|
|
||||||
```python
|
|
||||||
df['&s-up_or_down'] = np.where( df["close"].shift(-100) > df["close"], 'up', 'down')
|
|
||||||
df['&s-up_or_down'] = np.where( df["close"].shift(-100) == df["close"], 'same', df['&s-up_or_down'])
|
|
||||||
```
|
|
||||||
|
|
||||||
## PyTorch Module
|
|
||||||
|
|
||||||
### Quick start
|
|
||||||
|
|
||||||
The easiest way to quickly run a pytorch model is with the following command (for regression task):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel PyTorchMLPRegressor --strategy-path freqtrade/templates
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! note "Installation/docker"
|
|
||||||
The PyTorch module requires large packages such as `torch`, which should be explicitly requested during `./setup.sh -i` by answering "y" to the question "Do you also want dependencies for freqai-rl or PyTorch (~700mb additional space required) [y/N]?".
|
|
||||||
Users who prefer docker should ensure they use the docker image appended with `_freqaitorch`.
|
|
||||||
|
|
||||||
### Structure
|
|
||||||
|
|
||||||
#### Model
|
|
||||||
|
|
||||||
You can construct your own Neural Network architecture in PyTorch by simply defining your `nn.Module` class inside your custom [`IFreqaiModel` file](#using-different-prediction-models) and then using that class in your `def train()` function. Here is an example of logistic regression model implementation using PyTorch (should be used with nn.BCELoss criterion) for classification tasks.
|
|
||||||
|
|
||||||
```python
|
|
||||||
|
|
||||||
class LogisticRegression(nn.Module):
|
|
||||||
def __init__(self, input_size: int):
|
|
||||||
super().__init__()
|
|
||||||
# Define your layers
|
|
||||||
self.linear = nn.Linear(input_size, 1)
|
|
||||||
self.activation = nn.Sigmoid()
|
|
||||||
|
|
||||||
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
||||||
# Define the forward pass
|
|
||||||
out = self.linear(x)
|
|
||||||
out = self.activation(out)
|
|
||||||
return out
|
|
||||||
|
|
||||||
class MyCoolPyTorchClassifier(BasePyTorchClassifier):
|
|
||||||
"""
|
|
||||||
This is a custom IFreqaiModel showing how a user might setup their own
|
|
||||||
custom Neural Network architecture for their training.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def data_convertor(self) -> PyTorchDataConvertor:
|
|
||||||
return DefaultPyTorchDataConvertor(target_tensor_type=torch.float)
|
|
||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
config = self.freqai_info.get("model_training_parameters", {})
|
|
||||||
self.learning_rate: float = config.get("learning_rate", 3e-4)
|
|
||||||
self.model_kwargs: Dict[str, Any] = config.get("model_kwargs", {})
|
|
||||||
self.trainer_kwargs: Dict[str, Any] = config.get("trainer_kwargs", {})
|
|
||||||
|
|
||||||
def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:
|
|
||||||
"""
|
|
||||||
User sets up the training and test data to fit their desired model here
|
|
||||||
:param data_dictionary: the dictionary holding all data for train, test,
|
|
||||||
labels, weights
|
|
||||||
:param dk: The datakitchen object for the current coin/model
|
|
||||||
"""
|
|
||||||
|
|
||||||
class_names = self.get_class_names()
|
|
||||||
self.convert_label_column_to_int(data_dictionary, dk, class_names)
|
|
||||||
n_features = data_dictionary["train_features"].shape[-1]
|
|
||||||
model = LogisticRegression(
|
|
||||||
input_dim=n_features
|
|
||||||
)
|
|
||||||
model.to(self.device)
|
|
||||||
optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)
|
|
||||||
criterion = torch.nn.CrossEntropyLoss()
|
|
||||||
init_model = self.get_init_model(dk.pair)
|
|
||||||
trainer = PyTorchModelTrainer(
|
|
||||||
model=model,
|
|
||||||
optimizer=optimizer,
|
|
||||||
criterion=criterion,
|
|
||||||
model_meta_data={"class_names": class_names},
|
|
||||||
device=self.device,
|
|
||||||
init_model=init_model,
|
|
||||||
data_convertor=self.data_convertor,
|
|
||||||
**self.trainer_kwargs,
|
|
||||||
)
|
|
||||||
trainer.fit(data_dictionary, self.splits)
|
|
||||||
return trainer
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Trainer
|
|
||||||
|
|
||||||
The `PyTorchModelTrainer` performs the idiomatic PyTorch train loop:
|
|
||||||
Define our model, loss function, and optimizer, and then move them to the appropriate device (GPU or CPU). Inside the loop, we iterate through the batches in the dataloader, move the data to the device, compute the prediction and loss, backpropagate, and update the model parameters using the optimizer.
|
|
||||||
|
|
||||||
In addition, the trainer is responsible for the following:
|
|
||||||
- saving and loading the model
|
|
||||||
- converting the data from `pandas.DataFrame` to `torch.Tensor`.
|
|
||||||
|
|
||||||
#### Integration with Freqai module
|
|
||||||
|
|
||||||
Like all freqai models, PyTorch models inherit `IFreqaiModel`. `IFreqaiModel` declares three abstract methods: `train`, `fit`, and `predict`. we implement these methods in three levels of hierarchy.
|
|
||||||
From top to bottom:
|
|
||||||
|
|
||||||
1. `BasePyTorchModel` - Implements the `train` method. all `BasePyTorch*` inherit it. responsible for general data preparation (e.g., data normalization) and calling the `fit` method. Sets `device` attribute used by children classes. Sets `model_type` attribute used by the parent class.
|
|
||||||
2. `BasePyTorch*` - Implements the `predict` method. Here, the `*` represents a group of algorithms, such as classifiers or regressors. responsible for data preprocessing, predicting, and postprocessing if needed.
|
|
||||||
3. `PyTorch*Classifier` / `PyTorch*Regressor` - implements the `fit` method. responsible for the main train flaw, where we initialize the trainer and model objects.
|
|
||||||
|
|
||||||
![image](assets/freqai_pytorch-diagram.png)
|
|
||||||
|
|
||||||
#### Full example
|
|
||||||
|
|
||||||
Building a PyTorch regressor using MLP (multilayer perceptron) model, MSELoss criterion, and AdamW optimizer.
|
|
||||||
|
|
||||||
```python
|
|
||||||
class PyTorchMLPRegressor(BasePyTorchRegressor):
|
|
||||||
def __init__(self, **kwargs) -> None:
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
config = self.freqai_info.get("model_training_parameters", {})
|
|
||||||
self.learning_rate: float = config.get("learning_rate", 3e-4)
|
|
||||||
self.model_kwargs: Dict[str, Any] = config.get("model_kwargs", {})
|
|
||||||
self.trainer_kwargs: Dict[str, Any] = config.get("trainer_kwargs", {})
|
|
||||||
|
|
||||||
def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:
|
|
||||||
n_features = data_dictionary["train_features"].shape[-1]
|
|
||||||
model = PyTorchMLPModel(
|
|
||||||
input_dim=n_features,
|
|
||||||
output_dim=1,
|
|
||||||
**self.model_kwargs
|
|
||||||
)
|
|
||||||
model.to(self.device)
|
|
||||||
optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)
|
|
||||||
criterion = torch.nn.MSELoss()
|
|
||||||
init_model = self.get_init_model(dk.pair)
|
|
||||||
trainer = PyTorchModelTrainer(
|
|
||||||
model=model,
|
|
||||||
optimizer=optimizer,
|
|
||||||
criterion=criterion,
|
|
||||||
device=self.device,
|
|
||||||
init_model=init_model,
|
|
||||||
target_tensor_type=torch.float,
|
|
||||||
**self.trainer_kwargs,
|
|
||||||
)
|
|
||||||
trainer.fit(data_dictionary)
|
|
||||||
return trainer
|
|
||||||
```
|
|
||||||
|
|
||||||
Here we create a `PyTorchMLPRegressor` class that implements the `fit` method. The `fit` method specifies the training building blocks: model, optimizer, criterion, and trainer. We inherit both `BasePyTorchRegressor` and `BasePyTorchModel`, where the former implements the `predict` method that is suitable for our regression task, and the latter implements the train method.
|
|
||||||
|
|
||||||
??? Note "Setting Class Names for Classifiers"
|
|
||||||
When using classifiers, the user must declare the class names (or targets) by overriding the `IFreqaiModel.class_names` attribute. This is achieved by setting `self.freqai.class_names` in the FreqAI strategy inside the `set_freqai_targets` method.
|
|
||||||
|
|
||||||
For example, if you are using a binary classifier to predict price movements as up or down, you can set the class names as follows:
|
|
||||||
```python
|
|
||||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
|
||||||
self.freqai.class_names = ["down", "up"]
|
|
||||||
dataframe['&s-up_or_down'] = np.where(dataframe["close"].shift(-100) >
|
|
||||||
dataframe["close"], 'up', 'down')
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
To see a full example, you can refer to the [classifier test strategy class](https://github.com/freqtrade/freqtrade/blob/develop/tests/strategy/strats/freqai_test_classifier.py).
|
|
@ -1,78 +0,0 @@
|
|||||||
# Development
|
|
||||||
|
|
||||||
## Project architecture
|
|
||||||
|
|
||||||
The architecture and functions of FreqAI are generalized to encourages development of unique features, functions, models, etc.
|
|
||||||
|
|
||||||
The class structure and a detailed algorithmic overview is depicted in the following diagram:
|
|
||||||
|
|
||||||
![image](assets/freqai_algorithm-diagram.jpg)
|
|
||||||
|
|
||||||
As shown, there are three distinct objects comprising FreqAI:
|
|
||||||
|
|
||||||
* **IFreqaiModel** - A singular persistent object containing all the necessary logic to collect, store, and process data, engineer features, run training, and inference models.
|
|
||||||
* **FreqaiDataKitchen** - A non-persistent object which is created uniquely for each unique asset/model. Beyond metadata, it also contains a variety of data processing tools.
|
|
||||||
* **FreqaiDataDrawer** - A singular persistent object containing all the historical predictions, models, and save/load methods.
|
|
||||||
|
|
||||||
There are a variety of built-in [prediction models](freqai-configuration.md#using-different-prediction-models) which inherit directly from `IFreqaiModel`. Each of these models have full access to all methods in `IFreqaiModel` and can therefore override any of those functions at will. However, advanced users will likely stick to overriding `fit()`, `train()`, `predict()`, and `data_cleaning_train/predict()`.
|
|
||||||
|
|
||||||
## Data handling
|
|
||||||
|
|
||||||
FreqAI aims to organize model files, prediction data, and meta data in a way that simplifies post-processing and enhances crash resilience by automatic data reloading. The data is saved in a file structure,`user_data_dir/models/`, which contains all the data associated with the trainings and backtests. The `FreqaiDataKitchen()` relies heavily on the file structure for proper training and inferencing and should therefore not be manually modified.
|
|
||||||
|
|
||||||
### File structure
|
|
||||||
|
|
||||||
The file structure is automatically generated based on the model `identifier` set in the [config](freqai-configuration.md#setting-up-the-configuration-file). The following structure shows where the data is stored for post processing:
|
|
||||||
|
|
||||||
| Structure | Description |
|
|
||||||
|-----------|-------------|
|
|
||||||
| `config_*.json` | A copy of the model specific configuration file. |
|
|
||||||
| `historic_predictions.pkl` | A file containing all historic predictions generated during the lifetime of the `identifier` model during live deployment. `historic_predictions.pkl` is used to reload the model after a crash or a config change. A backup file is always held in case of corruption on the main file. FreqAI **automatically** detects corruption and replaces the corrupted file with the backup. |
|
|
||||||
| `pair_dictionary.json` | A file containing the training queue as well as the on disk location of the most recently trained model. |
|
|
||||||
| `sub-train-*_TIMESTAMP` | A folder containing all the files associated with a single model, such as: <br>
|
|
||||||
|| `*_metadata.json` - Metadata for the model, such as normalization max/min, expected training feature list, etc. <br>
|
|
||||||
|| `*_model.*` - The model file saved to disk for reloading from a crash. Can be `joblib` (typical boosting libs), `zip` (stable_baselines), `hd5` (keras type), etc. <br>
|
|
||||||
|| `*_pca_object.pkl` - The [Principal component analysis (PCA)](freqai-feature-engineering.md#data-dimensionality-reduction-with-principal-component-analysis) transform (if `principal_component_analysis: True` is set in the config) which will be used to transform unseen prediction features. <br>
|
|
||||||
|| `*_svm_model.pkl` - The [Support Vector Machine (SVM)](freqai-feature-engineering.md#identifying-outliers-using-a-support-vector-machine-svm) model (if `use_SVM_to_remove_outliers: True` is set in the config) which is used to detect outliers in unseen prediction features. <br>
|
|
||||||
|| `*_trained_df.pkl` - The dataframe containing all the training features used to train the `identifier` model. This is used for computing the [Dissimilarity Index (DI)](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di) and can also be used for post-processing. <br>
|
|
||||||
|| `*_trained_dates.df.pkl` - The dates associated with the `trained_df.pkl`, which is useful for post-processing. |
|
|
||||||
|
|
||||||
The example file structure would look like this:
|
|
||||||
|
|
||||||
```
|
|
||||||
├── models
|
|
||||||
│ └── unique-id
|
|
||||||
│ ├── config_freqai.example.json
|
|
||||||
│ ├── historic_predictions.backup.pkl
|
|
||||||
│ ├── historic_predictions.pkl
|
|
||||||
│ ├── pair_dictionary.json
|
|
||||||
│ ├── sub-train-1INCH_1662821319
|
|
||||||
│ │ ├── cb_1inch_1662821319_metadata.json
|
|
||||||
│ │ ├── cb_1inch_1662821319_model.joblib
|
|
||||||
│ │ ├── cb_1inch_1662821319_pca_object.pkl
|
|
||||||
│ │ ├── cb_1inch_1662821319_svm_model.joblib
|
|
||||||
│ │ ├── cb_1inch_1662821319_trained_dates_df.pkl
|
|
||||||
│ │ └── cb_1inch_1662821319_trained_df.pkl
|
|
||||||
│ ├── sub-train-1INCH_1662821371
|
|
||||||
│ │ ├── cb_1inch_1662821371_metadata.json
|
|
||||||
│ │ ├── cb_1inch_1662821371_model.joblib
|
|
||||||
│ │ ├── cb_1inch_1662821371_pca_object.pkl
|
|
||||||
│ │ ├── cb_1inch_1662821371_svm_model.joblib
|
|
||||||
│ │ ├── cb_1inch_1662821371_trained_dates_df.pkl
|
|
||||||
│ │ └── cb_1inch_1662821371_trained_df.pkl
|
|
||||||
│ ├── sub-train-ADA_1662821344
|
|
||||||
│ │ ├── cb_ada_1662821344_metadata.json
|
|
||||||
│ │ ├── cb_ada_1662821344_model.joblib
|
|
||||||
│ │ ├── cb_ada_1662821344_pca_object.pkl
|
|
||||||
│ │ ├── cb_ada_1662821344_svm_model.joblib
|
|
||||||
│ │ ├── cb_ada_1662821344_trained_dates_df.pkl
|
|
||||||
│ │ └── cb_ada_1662821344_trained_df.pkl
|
|
||||||
│ └── sub-train-ADA_1662821399
|
|
||||||
│ ├── cb_ada_1662821399_metadata.json
|
|
||||||
│ ├── cb_ada_1662821399_model.joblib
|
|
||||||
│ ├── cb_ada_1662821399_pca_object.pkl
|
|
||||||
│ ├── cb_ada_1662821399_svm_model.joblib
|
|
||||||
│ ├── cb_ada_1662821399_trained_dates_df.pkl
|
|
||||||
│ └── cb_ada_1662821399_trained_df.pkl
|
|
||||||
|
|
||||||
```
|
|
@ -1,335 +0,0 @@
|
|||||||
# Feature engineering
|
|
||||||
|
|
||||||
## Defining the features
|
|
||||||
|
|
||||||
Low level feature engineering is performed in the user strategy within a set of functions called `feature_engineering_*`. These function set the `base features` such as, `RSI`, `MFI`, `EMA`, `SMA`, time of day, volume, etc. The `base features` can be custom indicators or they can be imported from any technical-analysis library that you can find. FreqAI is equipped with a set of functions to simplify rapid large-scale feature engineering:
|
|
||||||
|
|
||||||
| Function | Description |
|
|
||||||
|---------------|-------------|
|
|
||||||
| `feature_engineering_expand_all()` | This optional function will automatically expand the defined features on the config defined `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.
|
|
||||||
| `feature_engineering_expand_basic()` | This optional function will automatically expand the defined features on the config defined `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`. Note: this function does *not* expand across `include_periods_candles`.
|
|
||||||
| `feature_engineering_standard()` | This optional function will be called once with the dataframe of the base timeframe. This is the final function to be called, which means that the dataframe entering this function will contain all the features and columns from the base asset created by the other `feature_engineering_expand` functions. This function is a good place to do custom exotic feature extractions (e.g. tsfresh). This function is also a good place for any feature that should not be auto-expanded upon (e.g., day of the week).
|
|
||||||
| `set_freqai_targets()` | Required function to set the targets for the model. All targets must be prepended with `&` to be recognized by the FreqAI internals.
|
|
||||||
|
|
||||||
Meanwhile, high level feature engineering is handled within `"feature_parameters":{}` in the FreqAI config. Within this file, it is possible to decide large scale feature expansions on top of the `base_features` such as "including correlated pairs" or "including informative timeframes" or even "including recent candles."
|
|
||||||
|
|
||||||
It is advisable to start from the template `feature_engineering_*` functions in the source provided example strategy (found in `templates/FreqaiExampleStrategy.py`) to ensure that the feature definitions are following the correct conventions. Here is an example of how to set the indicators and labels in the strategy:
|
|
||||||
|
|
||||||
```python
|
|
||||||
def feature_engineering_expand_all(self, dataframe, period, metadata, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This function will automatically expand the defined features on the config defined
|
|
||||||
`indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and
|
|
||||||
`include_corr_pairs`. In other words, a single feature defined in this function
|
|
||||||
will automatically expand to a total of
|
|
||||||
`indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *
|
|
||||||
`include_corr_pairs` numbers of features added to the model.
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
Access metadata such as the current pair/timeframe/period with:
|
|
||||||
|
|
||||||
`metadata["pair"]` `metadata["tf"]` `metadata["period"]`
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
:param period: period of the indicator - usage example:
|
|
||||||
:param metadata: metadata of current pair
|
|
||||||
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
|
||||||
"""
|
|
||||||
|
|
||||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-adx-period"] = ta.ADX(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-sma-period"] = ta.SMA(dataframe, timeperiod=period)
|
|
||||||
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
|
||||||
|
|
||||||
bollinger = qtpylib.bollinger_bands(
|
|
||||||
qtpylib.typical_price(dataframe), window=period, stds=2.2
|
|
||||||
)
|
|
||||||
dataframe["bb_lowerband-period"] = bollinger["lower"]
|
|
||||||
dataframe["bb_middleband-period"] = bollinger["mid"]
|
|
||||||
dataframe["bb_upperband-period"] = bollinger["upper"]
|
|
||||||
|
|
||||||
dataframe["%-bb_width-period"] = (
|
|
||||||
dataframe["bb_upperband-period"]
|
|
||||||
- dataframe["bb_lowerband-period"]
|
|
||||||
) / dataframe["bb_middleband-period"]
|
|
||||||
dataframe["%-close-bb_lower-period"] = (
|
|
||||||
dataframe["close"] / dataframe["bb_lowerband-period"]
|
|
||||||
)
|
|
||||||
|
|
||||||
dataframe["%-roc-period"] = ta.ROC(dataframe, timeperiod=period)
|
|
||||||
|
|
||||||
dataframe["%-relative_volume-period"] = (
|
|
||||||
dataframe["volume"] / dataframe["volume"].rolling(period).mean()
|
|
||||||
)
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def feature_engineering_expand_basic(self, dataframe, metadata, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This function will automatically expand the defined features on the config defined
|
|
||||||
`include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.
|
|
||||||
In other words, a single feature defined in this function
|
|
||||||
will automatically expand to a total of
|
|
||||||
`include_timeframes` * `include_shifted_candles` * `include_corr_pairs`
|
|
||||||
numbers of features added to the model.
|
|
||||||
|
|
||||||
Features defined here will *not* be automatically duplicated on user defined
|
|
||||||
`indicator_periods_candles`
|
|
||||||
|
|
||||||
Access metadata such as the current pair/timeframe with:
|
|
||||||
|
|
||||||
`metadata["pair"]` `metadata["tf"]`
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
:param metadata: metadata of current pair
|
|
||||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
|
||||||
dataframe["%-ema-200"] = ta.EMA(dataframe, timeperiod=200)
|
|
||||||
"""
|
|
||||||
dataframe["%-pct-change"] = dataframe["close"].pct_change()
|
|
||||||
dataframe["%-raw_volume"] = dataframe["volume"]
|
|
||||||
dataframe["%-raw_price"] = dataframe["close"]
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def feature_engineering_standard(self, dataframe, metadata, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
This optional function will be called once with the dataframe of the base timeframe.
|
|
||||||
This is the final function to be called, which means that the dataframe entering this
|
|
||||||
function will contain all the features and columns created by all other
|
|
||||||
freqai_feature_engineering_* functions.
|
|
||||||
|
|
||||||
This function is a good place to do custom exotic feature extractions (e.g. tsfresh).
|
|
||||||
This function is a good place for any feature that should not be auto-expanded upon
|
|
||||||
(e.g. day of the week).
|
|
||||||
|
|
||||||
Access metadata such as the current pair with:
|
|
||||||
|
|
||||||
`metadata["pair"]`
|
|
||||||
|
|
||||||
All features must be prepended with `%` to be recognized by FreqAI internals.
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the features
|
|
||||||
:param metadata: metadata of current pair
|
|
||||||
usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
|
|
||||||
"""
|
|
||||||
dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
|
|
||||||
dataframe["%-hour_of_day"] = (dataframe["date"].dt.hour + 1) / 25
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe, metadata, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
Required function to set the targets for the model.
|
|
||||||
All targets must be prepended with `&` to be recognized by the FreqAI internals.
|
|
||||||
|
|
||||||
Access metadata such as the current pair with:
|
|
||||||
|
|
||||||
`metadata["pair"]`
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the targets
|
|
||||||
:param metadata: metadata of current pair
|
|
||||||
usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"]
|
|
||||||
"""
|
|
||||||
dataframe["&-s_close"] = (
|
|
||||||
dataframe["close"]
|
|
||||||
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
|
|
||||||
.rolling(self.freqai_info["feature_parameters"]["label_period_candles"])
|
|
||||||
.mean()
|
|
||||||
/ dataframe["close"]
|
|
||||||
- 1
|
|
||||||
)
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
In the presented example, the user does not wish to pass the `bb_lowerband` as a feature to the model,
|
|
||||||
and has therefore not prepended it with `%`. The user does, however, wish to pass `bb_width` to the
|
|
||||||
model for training/prediction and has therefore prepended it with `%`.
|
|
||||||
|
|
||||||
After having defined the `base features`, the next step is to expand upon them using the powerful `feature_parameters` in the configuration file:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
//...
|
|
||||||
"feature_parameters" : {
|
|
||||||
"include_timeframes": ["5m","15m","4h"],
|
|
||||||
"include_corr_pairlist": [
|
|
||||||
"ETH/USD",
|
|
||||||
"LINK/USD",
|
|
||||||
"BNB/USD"
|
|
||||||
],
|
|
||||||
"label_period_candles": 24,
|
|
||||||
"include_shifted_candles": 2,
|
|
||||||
"indicator_periods_candles": [10, 20]
|
|
||||||
},
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `include_timeframes` in the config above are the timeframes (`tf`) of each call to `feature_engineering_expand_*()` in the strategy. In the presented case, the user is asking for the `5m`, `15m`, and `4h` timeframes of the `rsi`, `mfi`, `roc`, and `bb_width` to be included in the feature set.
|
|
||||||
|
|
||||||
You can ask for each of the defined features to be included also for informative pairs using the `include_corr_pairlist`. This means that the feature set will include all the features from `feature_engineering_expand_*()` on all the `include_timeframes` for each of the correlated pairs defined in the config (`ETH/USD`, `LINK/USD`, and `BNB/USD` in the presented example).
|
|
||||||
|
|
||||||
`include_shifted_candles` indicates the number of previous candles to include in the feature set. For example, `include_shifted_candles: 2` tells FreqAI to include the past 2 candles for each of the features in the feature set.
|
|
||||||
|
|
||||||
In total, the number of features the user of the presented example strat has created is: length of `include_timeframes` * no. features in `feature_engineering_expand_*()` * length of `include_corr_pairlist` * no. `include_shifted_candles` * length of `indicator_periods_candles`
|
|
||||||
$= 3 * 3 * 3 * 2 * 2 = 108$.
|
|
||||||
|
|
||||||
|
|
||||||
### Gain finer control over `feature_engineering_*` functions with `metadata`
|
|
||||||
|
|
||||||
All `feature_engineering_*` and `set_freqai_targets()` functions are passed a `metadata` dictionary which contains information about the `pair`, `tf` (timeframe), and `period` that FreqAI is automating for feature building. As such, a user can use `metadata` inside `feature_engineering_*` functions as criteria for blocking/reserving features for certain timeframes, periods, pairs etc.
|
|
||||||
|
|
||||||
```python
|
|
||||||
def feature_engineering_expand_all(self, dataframe, period, metadata, **kwargs):
|
|
||||||
if metadata["tf"] == "1h":
|
|
||||||
dataframe["%-roc-period"] = ta.ROC(dataframe, timeperiod=period)
|
|
||||||
```
|
|
||||||
|
|
||||||
This will block `ta.ROC()` from being added to any timeframes other than `"1h"`.
|
|
||||||
|
|
||||||
### Returning additional info from training
|
|
||||||
|
|
||||||
Important metrics can be returned to the strategy at the end of each model training by assigning them to `dk.data['extra_returns_per_train']['my_new_value'] = XYZ` inside the custom prediction model class.
|
|
||||||
|
|
||||||
FreqAI takes the `my_new_value` assigned in this dictionary and expands it to fit the dataframe that is returned to the strategy. You can then use the returned metrics in your strategy through `dataframe['my_new_value']`. An example of how return values can be used in FreqAI are the `&*_mean` and `&*_std` values that are used to [created a dynamic target threshold](freqai-configuration.md#creating-a-dynamic-target-threshold).
|
|
||||||
|
|
||||||
Another example, where the user wants to use live metrics from the trade database, is shown below:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"extra_returns_per_train": {"total_profit": 4}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You need to set the standard dictionary in the config so that FreqAI can return proper dataframe shapes. These values will likely be overridden by the prediction model, but in the case where the model has yet to set them, or needs a default initial value, the pre-set values are what will be returned.
|
|
||||||
|
|
||||||
## Feature normalization
|
|
||||||
|
|
||||||
FreqAI is strict when it comes to data normalization. The train features, $X^{train}$, are always normalized to [-1, 1] using a shifted min-max normalization:
|
|
||||||
|
|
||||||
$$X^{train}_{norm} = 2 * \frac{X^{train} - X^{train}.min()}{X^{train}.max() - X^{train}.min()} - 1$$
|
|
||||||
|
|
||||||
All other data (test data and unseen prediction data in dry/live/backtest) is always automatically normalized to the training feature space according to industry standards. FreqAI stores all the metadata required to ensure that test and prediction features will be properly normalized and that predictions are properly denormalized. For this reason, it is not recommended to eschew industry standards and modify FreqAI internals - however - advanced users can do so by inheriting `train()` in their custom `IFreqaiModel` and using their own normalization functions.
|
|
||||||
|
|
||||||
## Data dimensionality reduction with Principal Component Analysis
|
|
||||||
|
|
||||||
You can reduce the dimensionality of your features by activating the `principal_component_analysis` in the config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"feature_parameters" : {
|
|
||||||
"principal_component_analysis": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This will perform PCA on the features and reduce their dimensionality so that the explained variance of the data set is >= 0.999. Reducing data dimensionality makes training the model faster and hence allows for more up-to-date models.
|
|
||||||
|
|
||||||
## Inlier metric
|
|
||||||
|
|
||||||
The `inlier_metric` is a metric aimed at quantifying how similar the features of a data point are to the most recent historical data points.
|
|
||||||
|
|
||||||
You define the lookback window by setting `inlier_metric_window` and FreqAI computes the distance between the present time point and each of the previous `inlier_metric_window` lookback points. A Weibull function is fit to each of the lookback distributions and its cumulative distribution function (CDF) is used to produce a quantile for each lookback point. The `inlier_metric` is then computed for each time point as the average of the corresponding lookback quantiles. The figure below explains the concept for an `inlier_metric_window` of 5.
|
|
||||||
|
|
||||||
![inlier-metric](assets/freqai_inlier-metric.jpg)
|
|
||||||
|
|
||||||
FreqAI adds the `inlier_metric` to the training features and hence gives the model access to a novel type of temporal information.
|
|
||||||
|
|
||||||
This function does **not** remove outliers from the data set.
|
|
||||||
|
|
||||||
## Weighting features for temporal importance
|
|
||||||
|
|
||||||
FreqAI allows you to set a `weight_factor` to weight recent data more strongly than past data via an exponential function:
|
|
||||||
|
|
||||||
$$ W_i = \exp(\frac{-i}{\alpha*n}) $$
|
|
||||||
|
|
||||||
where $W_i$ is the weight of data point $i$ in a total set of $n$ data points. Below is a figure showing the effect of different weight factors on the data points in a feature set.
|
|
||||||
|
|
||||||
![weight-factor](assets/freqai_weight-factor.jpg)
|
|
||||||
|
|
||||||
## Outlier detection
|
|
||||||
|
|
||||||
Equity and crypto markets suffer from a high level of non-patterned noise in the form of outlier data points. FreqAI implements a variety of methods to identify such outliers and hence mitigate risk.
|
|
||||||
|
|
||||||
### Identifying outliers with the Dissimilarity Index (DI)
|
|
||||||
|
|
||||||
The Dissimilarity Index (DI) aims to quantify the uncertainty associated with each prediction made by the model.
|
|
||||||
|
|
||||||
You can tell FreqAI to remove outlier data points from the training/test data sets using the DI by including the following statement in the config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"feature_parameters" : {
|
|
||||||
"DI_threshold": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The DI allows predictions which are outliers (not existent in the model feature space) to be thrown out due to low levels of certainty. To do so, FreqAI measures the distance between each training data point (feature vector), $X_{a}$, and all other training data points:
|
|
||||||
|
|
||||||
$$ d_{ab} = \sqrt{\sum_{j=1}^p(X_{a,j}-X_{b,j})^2} $$
|
|
||||||
|
|
||||||
where $d_{ab}$ is the distance between the normalized points $a$ and $b$, and $p$ is the number of features, i.e., the length of the vector $X$. The characteristic distance, $\overline{d}$, for a set of training data points is simply the mean of the average distances:
|
|
||||||
|
|
||||||
$$ \overline{d} = \sum_{a=1}^n(\sum_{b=1}^n(d_{ab}/n)/n) $$
|
|
||||||
|
|
||||||
$\overline{d}$ quantifies the spread of the training data, which is compared to the distance between a new prediction feature vectors, $X_k$ and all the training data:
|
|
||||||
|
|
||||||
$$ d_k = \arg \min d_{k,i} $$
|
|
||||||
|
|
||||||
This enables the estimation of the Dissimilarity Index as:
|
|
||||||
|
|
||||||
$$ DI_k = d_k/\overline{d} $$
|
|
||||||
|
|
||||||
You can tweak the DI through the `DI_threshold` to increase or decrease the extrapolation of the trained model. A higher `DI_threshold` means that the DI is more lenient and allows predictions further away from the training data to be used whilst a lower `DI_threshold` has the opposite effect and hence discards more predictions.
|
|
||||||
|
|
||||||
Below is a figure that describes the DI for a 3D data set.
|
|
||||||
|
|
||||||
![DI](assets/freqai_DI.jpg)
|
|
||||||
|
|
||||||
### Identifying outliers using a Support Vector Machine (SVM)
|
|
||||||
|
|
||||||
You can tell FreqAI to remove outlier data points from the training/test data sets using a Support Vector Machine (SVM) by including the following statement in the config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"feature_parameters" : {
|
|
||||||
"use_SVM_to_remove_outliers": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The SVM will be trained on the training data and any data point that the SVM deems to be beyond the feature space will be removed.
|
|
||||||
|
|
||||||
FreqAI uses `sklearn.linear_model.SGDOneClassSVM` (details are available on scikit-learn's webpage [here](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDOneClassSVM.html) (external website)) and you can elect to provide additional parameters for the SVM, such as `shuffle`, and `nu`.
|
|
||||||
|
|
||||||
The parameter `shuffle` is by default set to `False` to ensure consistent results. If it is set to `True`, running the SVM multiple times on the same data set might result in different outcomes due to `max_iter` being to low for the algorithm to reach the demanded `tol`. Increasing `max_iter` solves this issue but causes the procedure to take longer time.
|
|
||||||
|
|
||||||
The parameter `nu`, *very* broadly, is the amount of data points that should be considered outliers and should be between 0 and 1.
|
|
||||||
|
|
||||||
### Identifying outliers with DBSCAN
|
|
||||||
|
|
||||||
You can configure FreqAI to use DBSCAN to cluster and remove outliers from the training/test data set or incoming outliers from predictions, by activating `use_DBSCAN_to_remove_outliers` in the config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"feature_parameters" : {
|
|
||||||
"use_DBSCAN_to_remove_outliers": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
DBSCAN is an unsupervised machine learning algorithm that clusters data without needing to know how many clusters there should be.
|
|
||||||
|
|
||||||
Given a number of data points $N$, and a distance $\varepsilon$, DBSCAN clusters the data set by setting all data points that have $N-1$ other data points within a distance of $\varepsilon$ as *core points*. A data point that is within a distance of $\varepsilon$ from a *core point* but that does not have $N-1$ other data points within a distance of $\varepsilon$ from itself is considered an *edge point*. A cluster is then the collection of *core points* and *edge points*. Data points that have no other data points at a distance $<\varepsilon$ are considered outliers. The figure below shows a cluster with $N = 3$.
|
|
||||||
|
|
||||||
![dbscan](assets/freqai_dbscan.jpg)
|
|
||||||
|
|
||||||
FreqAI uses `sklearn.cluster.DBSCAN` (details are available on scikit-learn's webpage [here](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html) (external website)) with `min_samples` ($N$) taken as 1/4 of the no. of time points (candles) in the feature set. `eps` ($\varepsilon$) is computed automatically as the elbow point in the *k-distance graph* computed from the nearest neighbors in the pairwise distances of all data points in the feature set.
|
|
@ -1,117 +0,0 @@
|
|||||||
# Parameter table
|
|
||||||
|
|
||||||
The table below will list all configuration parameters available for FreqAI. Some of the parameters are exemplified in `config_examples/config_freqai.example.json`.
|
|
||||||
|
|
||||||
Mandatory parameters are marked as **Required** and have to be set in one of the suggested ways.
|
|
||||||
|
|
||||||
### General configuration parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **General configuration parameters within the `config.freqai` tree**
|
|
||||||
| `freqai` | **Required.** <br> The parent dictionary containing all the parameters for controlling FreqAI. <br> **Datatype:** Dictionary.
|
|
||||||
| `train_period_days` | **Required.** <br> Number of days to use for the training data (width of the sliding window). <br> **Datatype:** Positive integer.
|
|
||||||
| `backtest_period_days` | **Required.** <br> Number of days to inference from the trained model before sliding the `train_period_days` window defined above, and retraining the model during backtesting (more info [here](freqai-running.md#backtesting)). This can be fractional days, but beware that the provided `timerange` will be divided by this number to yield the number of trainings necessary to complete the backtest. <br> **Datatype:** Float.
|
|
||||||
| `identifier` | **Required.** <br> A unique ID for the current model. If models are saved to disk, the `identifier` allows for reloading specific pre-trained models/data. <br> **Datatype:** String.
|
|
||||||
| `live_retrain_hours` | Frequency of retraining during dry/live runs. <br> **Datatype:** Float > 0. <br> Default: `0` (models retrain as often as possible).
|
|
||||||
| `expiration_hours` | Avoid making predictions if a model is more than `expiration_hours` old. <br> **Datatype:** Positive integer. <br> Default: `0` (models never expire).
|
|
||||||
| `purge_old_models` | Number of models to keep on disk (not relevant to backtesting). Default is 2, which means that dry/live runs will keep the latest 2 models on disk. Setting to 0 keeps all models. This parameter also accepts a boolean to maintain backwards compatibility. <br> **Datatype:** Integer. <br> Default: `2`.
|
|
||||||
| `save_backtest_models` | Save models to disk when running backtesting. Backtesting operates most efficiently by saving the prediction data and reusing them directly for subsequent runs (when you wish to tune entry/exit parameters). Saving backtesting models to disk also allows to use the same model files for starting a dry/live instance with the same model `identifier`. <br> **Datatype:** Boolean. <br> Default: `False` (no models are saved).
|
|
||||||
| `fit_live_predictions_candles` | Number of historical candles to use for computing target (label) statistics from prediction data, instead of from the training dataset (more information can be found [here](freqai-configuration.md#creating-a-dynamic-target-threshold)). <br> **Datatype:** Positive integer.
|
|
||||||
| `continual_learning` | Use the final state of the most recently trained model as starting point for the new model, allowing for incremental learning (more information can be found [here](freqai-running.md#continual-learning)). <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
||||||
| `write_metrics_to_disk` | Collect train timings, inference timings and cpu usage in json file. <br> **Datatype:** Boolean. <br> Default: `False`
|
|
||||||
| `data_kitchen_thread_count` | <br> Designate the number of threads you want to use for data processing (outlier methods, normalization, etc.). This has no impact on the number of threads used for training. If user does not set it (default), FreqAI will use max number of threads - 2 (leaving 1 physical core available for Freqtrade bot and FreqUI) <br> **Datatype:** Positive integer.
|
|
||||||
|
|
||||||
### Feature parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Feature parameters within the `freqai.feature_parameters` sub dictionary**
|
|
||||||
| `feature_parameters` | A dictionary containing the parameters used to engineer the feature set. Details and examples are shown [here](freqai-feature-engineering.md). <br> **Datatype:** Dictionary.
|
|
||||||
| `include_timeframes` | A list of timeframes that all indicators in `feature_engineering_expand_*()` will be created for. The list is added as features to the base indicators dataset. <br> **Datatype:** List of timeframes (strings).
|
|
||||||
| `include_corr_pairlist` | A list of correlated coins that FreqAI will add as additional features to all `pair_whitelist` coins. All indicators set in `feature_engineering_expand_*()` during feature engineering (see details [here](freqai-feature-engineering.md)) will be created for each correlated coin. The correlated coins features are added to the base indicators dataset. <br> **Datatype:** List of assets (strings).
|
|
||||||
| `label_period_candles` | Number of candles into the future that the labels are created for. This is used in `feature_engineering_expand_all()` (see `templates/FreqaiExampleStrategy.py` for detailed usage). You can create custom labels and choose whether to make use of this parameter or not. <br> **Datatype:** Positive integer.
|
|
||||||
| `include_shifted_candles` | Add features from previous candles to subsequent candles with the intent of adding historical information. If used, FreqAI will duplicate and shift all features from the `include_shifted_candles` previous candles so that the information is available for the subsequent candle. <br> **Datatype:** Positive integer.
|
|
||||||
| `weight_factor` | Weight training data points according to their recency (see details [here](freqai-feature-engineering.md#weighting-features-for-temporal-importance)). <br> **Datatype:** Positive float (typically < 1).
|
|
||||||
| `indicator_max_period_candles` | **No longer used (#7325)**. Replaced by `startup_candle_count` which is set in the [strategy](freqai-configuration.md#building-a-freqai-strategy). `startup_candle_count` is timeframe independent and defines the maximum *period* used in `feature_engineering_*()` for indicator creation. FreqAI uses this parameter together with the maximum timeframe in `include_time_frames` to calculate how many data points to download such that the first data point does not include a NaN. <br> **Datatype:** Positive integer.
|
|
||||||
| `indicator_periods_candles` | Time periods to calculate indicators for. The indicators are added to the base indicator dataset. <br> **Datatype:** List of positive integers.
|
|
||||||
| `principal_component_analysis` | Automatically reduce the dimensionality of the data set using Principal Component Analysis. See details about how it works [here](#reducing-data-dimensionality-with-principal-component-analysis) <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
||||||
| `plot_feature_importances` | Create a feature importance plot for each model for the top/bottom `plot_feature_importances` number of features. Plot is stored in `user_data/models/<identifier>/sub-train-<COIN>_<timestamp>.html`. <br> **Datatype:** Integer. <br> Default: `0`.
|
|
||||||
| `DI_threshold` | Activates the use of the Dissimilarity Index for outlier detection when set to > 0. See details about how it works [here](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di). <br> **Datatype:** Positive float (typically < 1).
|
|
||||||
| `use_SVM_to_remove_outliers` | Train a support vector machine to detect and remove outliers from the training dataset, as well as from incoming data points. See details about how it works [here](freqai-feature-engineering.md#identifying-outliers-using-a-support-vector-machine-svm). <br> **Datatype:** Boolean.
|
|
||||||
| `svm_params` | All parameters available in Sklearn's `SGDOneClassSVM()`. See details about some select parameters [here](freqai-feature-engineering.md#identifying-outliers-using-a-support-vector-machine-svm). <br> **Datatype:** Dictionary.
|
|
||||||
| `use_DBSCAN_to_remove_outliers` | Cluster data using the DBSCAN algorithm to identify and remove outliers from training and prediction data. See details about how it works [here](freqai-feature-engineering.md#identifying-outliers-with-dbscan). <br> **Datatype:** Boolean.
|
|
||||||
| `inlier_metric_window` | If set, FreqAI adds an `inlier_metric` to the training feature set and set the lookback to be the `inlier_metric_window`, i.e., the number of previous time points to compare the current candle to. Details of how the `inlier_metric` is computed can be found [here](freqai-feature-engineering.md#inlier-metric). <br> **Datatype:** Integer. <br> Default: `0`.
|
|
||||||
| `noise_standard_deviation` | If set, FreqAI adds noise to the training features with the aim of preventing overfitting. FreqAI generates random deviates from a gaussian distribution with a standard deviation of `noise_standard_deviation` and adds them to all data points. `noise_standard_deviation` should be kept relative to the normalized space, i.e., between -1 and 1. In other words, since data in FreqAI is always normalized to be between -1 and 1, `noise_standard_deviation: 0.05` would result in 32% of the data being randomly increased/decreased by more than 2.5% (i.e., the percent of data falling within the first standard deviation). <br> **Datatype:** Integer. <br> Default: `0`.
|
|
||||||
| `outlier_protection_percentage` | Enable to prevent outlier detection methods from discarding too much data. If more than `outlier_protection_percentage` % of points are detected as outliers by the SVM or DBSCAN, FreqAI will log a warning message and ignore outlier detection, i.e., the original dataset will be kept intact. If the outlier protection is triggered, no predictions will be made based on the training dataset. <br> **Datatype:** Float. <br> Default: `30`.
|
|
||||||
| `reverse_train_test_order` | Split the feature dataset (see below) and use the latest data split for training and test on historical split of the data. This allows the model to be trained up to the most recent data point, while avoiding overfitting. However, you should be careful to understand the unorthodox nature of this parameter before employing it. <br> **Datatype:** Boolean. <br> Default: `False` (no reversal).
|
|
||||||
| `shuffle_after_split` | Split the data into train and test sets, and then shuffle both sets individually. <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
||||||
| `buffer_train_data_candles` | Cut `buffer_train_data_candles` off the beginning and end of the training data *after* the indicators were populated. The main example use is when predicting maxima and minima, the argrelextrema function cannot know the maxima/minima at the edges of the timerange. To improve model accuracy, it is best to compute argrelextrema on the full timerange and then use this function to cut off the edges (buffer) by the kernel. In another case, if the targets are set to a shifted price movement, this buffer is unnecessary because the shifted candles at the end of the timerange will be NaN and FreqAI will automatically cut those off of the training dataset.<br> **Datatype:** Integer. <br> Default: `0`.
|
|
||||||
|
|
||||||
### Data split parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Data split parameters within the `freqai.data_split_parameters` sub dictionary**
|
|
||||||
| `data_split_parameters` | Include any additional parameters available from scikit-learn `test_train_split()`, which are shown [here](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html) (external website). <br> **Datatype:** Dictionary.
|
|
||||||
| `test_size` | The fraction of data that should be used for testing instead of training. <br> **Datatype:** Positive float < 1.
|
|
||||||
| `shuffle` | Shuffle the training data points during training. Typically, to not remove the chronological order of data in time-series forecasting, this is set to `False`. <br> **Datatype:** Boolean. <br> Defaut: `False`.
|
|
||||||
|
|
||||||
### Model training parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Model training parameters within the `freqai.model_training_parameters` sub dictionary**
|
|
||||||
| `model_training_parameters` | A flexible dictionary that includes all parameters available by the selected model library. For example, if you use `LightGBMRegressor`, this dictionary can contain any parameter available by the `LightGBMRegressor` [here](https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMRegressor.html) (external website). If you select a different model, this dictionary can contain any parameter from that model. A list of the currently available models can be found [here](freqai-configuration.md#using-different-prediction-models). <br> **Datatype:** Dictionary.
|
|
||||||
| `n_estimators` | The number of boosted trees to fit in the training of the model. <br> **Datatype:** Integer.
|
|
||||||
| `learning_rate` | Boosting learning rate during training of the model. <br> **Datatype:** Float.
|
|
||||||
| `n_jobs`, `thread_count`, `task_type` | Set the number of threads for parallel processing and the `task_type` (`gpu` or `cpu`). Different model libraries use different parameter names. <br> **Datatype:** Float.
|
|
||||||
|
|
||||||
### Reinforcement Learning parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Reinforcement Learning Parameters within the `freqai.rl_config` sub dictionary**
|
|
||||||
| `rl_config` | A dictionary containing the control parameters for a Reinforcement Learning model. <br> **Datatype:** Dictionary.
|
|
||||||
| `train_cycles` | Training time steps will be set based on the `train_cycles * number of training data points. <br> **Datatype:** Integer.
|
|
||||||
| `cpu_count` | Number of processors to dedicate to the Reinforcement Learning training process. <br> **Datatype:** int.
|
|
||||||
| `max_trade_duration_candles`| Guides the agent training to keep trades below desired length. Example usage shown in `prediction_models/ReinforcementLearner.py` within the customizable `calculate_reward()` function. <br> **Datatype:** int.
|
|
||||||
| `model_type` | Model string from stable_baselines3 or SBcontrib. Available strings include: `'TRPO', 'ARS', 'RecurrentPPO', 'MaskablePPO', 'PPO', 'A2C', 'DQN'`. User should ensure that `model_training_parameters` match those available to the corresponding stable_baselines3 model by visiting their documentaiton. [PPO doc](https://stable-baselines3.readthedocs.io/en/master/modules/ppo.html) (external website) <br> **Datatype:** string.
|
|
||||||
| `policy_type` | One of the available policy types from stable_baselines3 <br> **Datatype:** string.
|
|
||||||
| `max_training_drawdown_pct` | The maximum drawdown that the agent is allowed to experience during training. <br> **Datatype:** float. <br> Default: 0.8
|
|
||||||
| `cpu_count` | Number of threads/cpus to dedicate to the Reinforcement Learning training process (depending on if `ReinforcementLearning_multiproc` is selected or not). Recommended to leave this untouched, by default, this value is set to the total number of physical cores minus 1. <br> **Datatype:** int.
|
|
||||||
| `model_reward_parameters` | Parameters used inside the customizable `calculate_reward()` function in `ReinforcementLearner.py` <br> **Datatype:** int.
|
|
||||||
| `add_state_info` | Tell FreqAI to include state information in the feature set for training and inferencing. The current state variables include trade duration, current profit, trade position. This is only available in dry/live runs, and is automatically switched to false for backtesting. <br> **Datatype:** bool. <br> Default: `False`.
|
|
||||||
| `net_arch` | Network architecture which is well described in [`stable_baselines3` doc](https://stable-baselines3.readthedocs.io/en/master/guide/custom_policy.html#examples). In summary: `[<shared layers>, dict(vf=[<non-shared value network layers>], pi=[<non-shared policy network layers>])]`. By default this is set to `[128, 128]`, which defines 2 shared hidden layers with 128 units each.
|
|
||||||
| `randomize_starting_position` | Randomize the starting point of each episode to avoid overfitting. <br> **Datatype:** bool. <br> Default: `False`.
|
|
||||||
| `drop_ohlc_from_features` | Do not include the normalized ohlc data in the feature set passed to the agent during training (ohlc will still be used for driving the environment in all cases) <br> **Datatype:** Boolean. <br> **Default:** `False`
|
|
||||||
|
|
||||||
### PyTorch parameters
|
|
||||||
|
|
||||||
#### general
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Model training parameters within the `freqai.model_training_parameters` sub dictionary**
|
|
||||||
| `learning_rate` | Learning rate to be passed to the optimizer. <br> **Datatype:** float. <br> Default: `3e-4`.
|
|
||||||
| `model_kwargs` | Parameters to be passed to the model class. <br> **Datatype:** dict. <br> Default: `{}`.
|
|
||||||
| `trainer_kwargs` | Parameters to be passed to the trainer class. <br> **Datatype:** dict. <br> Default: `{}`.
|
|
||||||
|
|
||||||
#### trainer_kwargs
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Model training parameters within the `freqai.model_training_parameters.model_kwargs` sub dictionary**
|
|
||||||
| `max_iters` | The number of training iterations to run. iteration here refers to the number of times we call self.optimizer.step(). used to calculate n_epochs. <br> **Datatype:** int. <br> Default: `100`.
|
|
||||||
| `batch_size` | The size of the batches to use during training.. <br> **Datatype:** int. <br> Default: `64`.
|
|
||||||
| `max_n_eval_batches` | The maximum number batches to use for evaluation.. <br> **Datatype:** int, optional. <br> Default: `None`.
|
|
||||||
|
|
||||||
|
|
||||||
### Additional parameters
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| | **Extraneous parameters**
|
|
||||||
| `freqai.keras` | If the selected model makes use of Keras (typical for TensorFlow-based prediction models), this flag needs to be activated so that the model save/loading follows Keras standards. <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
||||||
| `freqai.conv_width` | The width of a convolutional neural network input tensor. This replaces the need for shifting candles (`include_shifted_candles`) by feeding in historical data points as the second dimension of the tensor. Technically, this parameter can also be used for regressors, but it only adds computational overhead and does not change the model training/prediction. <br> **Datatype:** Integer. <br> Default: `2`.
|
|
||||||
| `freqai.reduce_df_footprint` | Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage and decreasing train/inference timing. This parameter is set in the main level of the Freqtrade configuration file (not inside FreqAI). <br> **Datatype:** Boolean. <br> Default: `False`.
|
|
@ -1,269 +0,0 @@
|
|||||||
# Reinforcement Learning
|
|
||||||
|
|
||||||
!!! Note "Installation size"
|
|
||||||
Reinforcement learning dependencies include large packages such as `torch`, which should be explicitly requested during `./setup.sh -i` by answering "y" to the question "Do you also want dependencies for freqai-rl (~700mb additional space required) [y/N]?".
|
|
||||||
Users who prefer docker should ensure they use the docker image appended with `_freqairl`.
|
|
||||||
|
|
||||||
## Background and terminology
|
|
||||||
|
|
||||||
### What is RL and why does FreqAI need it?
|
|
||||||
|
|
||||||
Reinforcement learning involves two important components, the *agent* and the training *environment*. During agent training, the agent moves through historical data candle by candle, always making 1 of a set of actions: Long entry, long exit, short entry, short exit, neutral). During this training process, the environment tracks the performance of these actions and rewards the agent according to a custom user made `calculate_reward()` (here we offer a default reward for users to build on if they wish [details here](#creating-a-custom-reward-function)). The reward is used to train weights in a neural network.
|
|
||||||
|
|
||||||
A second important component of the FreqAI RL implementation is the use of *state* information. State information is fed into the network at each step, including current profit, current position, and current trade duration. These are used to train the agent in the training environment, and to reinforce the agent in dry/live (this functionality is not available in backtesting). *FreqAI + Freqtrade is a perfect match for this reinforcing mechanism since this information is readily available in live deployments.*
|
|
||||||
|
|
||||||
Reinforcement learning is a natural progression for FreqAI, since it adds a new layer of adaptivity and market reactivity that Classifiers and Regressors cannot match. However, Classifiers and Regressors have strengths that RL does not have such as robust predictions. Improperly trained RL agents may find "cheats" and "tricks" to maximize reward without actually winning any trades. For this reason, RL is more complex and demands a higher level of understanding than typical Classifiers and Regressors.
|
|
||||||
|
|
||||||
### The RL interface
|
|
||||||
|
|
||||||
With the current framework, we aim to expose the training environment via the common "prediction model" file, which is a user inherited `BaseReinforcementLearner` object (e.g. `freqai/prediction_models/ReinforcementLearner`). Inside this user class, the RL environment is available and customized via `MyRLEnv` as [shown below](#creating-a-custom-reward-function).
|
|
||||||
|
|
||||||
We envision the majority of users focusing their effort on creative design of the `calculate_reward()` function [details here](#creating-a-custom-reward-function), while leaving the rest of the environment untouched. Other users may not touch the environment at all, and they will only play with the configuration settings and the powerful feature engineering that already exists in FreqAI. Meanwhile, we enable advanced users to create their own model classes entirely.
|
|
||||||
|
|
||||||
The framework is built on stable_baselines3 (torch) and OpenAI gym for the base environment class. But generally speaking, the model class is well isolated. Thus, the addition of competing libraries can be easily integrated into the existing framework. For the environment, it is inheriting from `gym.env` which means that it is necessary to write an entirely new environment in order to switch to a different library.
|
|
||||||
|
|
||||||
### Important considerations
|
|
||||||
|
|
||||||
As explained above, the agent is "trained" in an artificial trading "environment". In our case, that environment may seem quite similar to a real Freqtrade backtesting environment, but it is *NOT*. In fact, the RL training environment is much more simplified. It does not incorporate any of the complicated strategy logic, such as callbacks like `custom_exit`, `custom_stoploss`, leverage controls, etc. The RL environment is instead a very "raw" representation of the true market, where the agent has free will to learn the policy (read: stoploss, take profit, etc.) which is enforced by the `calculate_reward()`. Thus, it is important to consider that the agent training environment is not identical to the real world.
|
|
||||||
|
|
||||||
## Running Reinforcement Learning
|
|
||||||
|
|
||||||
Setting up and running a Reinforcement Learning model is the same as running a Regressor or Classifier. The same two flags, `--freqaimodel` and `--strategy`, must be defined on the command line:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade trade --freqaimodel ReinforcementLearner --strategy MyRLStrategy --config config.json
|
|
||||||
```
|
|
||||||
|
|
||||||
where `ReinforcementLearner` will use the templated `ReinforcementLearner` from `freqai/prediction_models/ReinforcementLearner` (or a custom user defined one located in `user_data/freqaimodels`). The strategy, on the other hand, follows the same base [feature engineering](freqai-feature-engineering.md) with `feature_engineering_*` as a typical Regressor. The difference lies in the creation of the targets, Reinforcement Learning doesn't require them. However, FreqAI requires a default (neutral) value to be set in the action column:
|
|
||||||
|
|
||||||
```python
|
|
||||||
def set_freqai_targets(self, dataframe, **kwargs):
|
|
||||||
"""
|
|
||||||
*Only functional with FreqAI enabled strategies*
|
|
||||||
Required function to set the targets for the model.
|
|
||||||
All targets must be prepended with `&` to be recognized by the FreqAI internals.
|
|
||||||
|
|
||||||
More details about feature engineering available:
|
|
||||||
|
|
||||||
https://www.freqtrade.io/en/latest/freqai-feature-engineering
|
|
||||||
|
|
||||||
:param df: strategy dataframe which will receive the targets
|
|
||||||
usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"]
|
|
||||||
"""
|
|
||||||
# For RL, there are no direct targets to set. This is filler (neutral)
|
|
||||||
# until the agent sends an action.
|
|
||||||
dataframe["&-action"] = 0
|
|
||||||
```
|
|
||||||
|
|
||||||
Most of the function remains the same as for typical Regressors, however, the function below shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment:
|
|
||||||
|
|
||||||
```python
|
|
||||||
def feature_engineering_standard(self, dataframe, **kwargs):
|
|
||||||
# The following features are necessary for RL models
|
|
||||||
dataframe[f"%-raw_close"] = dataframe["close"]
|
|
||||||
dataframe[f"%-raw_open"] = dataframe["open"]
|
|
||||||
dataframe[f"%-raw_high"] = dataframe["high"]
|
|
||||||
dataframe[f"%-raw_low"] = dataframe["low"]
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, there is no explicit "label" to make - instead it is necessary to assign the `&-action` column which will contain the agent's actions when accessed in `populate_entry/exit_trends()`. In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action.
|
|
||||||
|
|
||||||
After users realize there are no labels to set, they will soon understand that the agent is making its "own" entry and exit decisions. This makes strategy construction rather simple. The entry and exit signals come from the agent in the form of an integer - which are used directly to decide entries and exits in the strategy:
|
|
||||||
|
|
||||||
```python
|
|
||||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
|
|
||||||
enter_long_conditions = [df["do_predict"] == 1, df["&-action"] == 1]
|
|
||||||
|
|
||||||
if enter_long_conditions:
|
|
||||||
df.loc[
|
|
||||||
reduce(lambda x, y: x & y, enter_long_conditions), ["enter_long", "enter_tag"]
|
|
||||||
] = (1, "long")
|
|
||||||
|
|
||||||
enter_short_conditions = [df["do_predict"] == 1, df["&-action"] == 3]
|
|
||||||
|
|
||||||
if enter_short_conditions:
|
|
||||||
df.loc[
|
|
||||||
reduce(lambda x, y: x & y, enter_short_conditions), ["enter_short", "enter_tag"]
|
|
||||||
] = (1, "short")
|
|
||||||
|
|
||||||
return df
|
|
||||||
|
|
||||||
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
exit_long_conditions = [df["do_predict"] == 1, df["&-action"] == 2]
|
|
||||||
if exit_long_conditions:
|
|
||||||
df.loc[reduce(lambda x, y: x & y, exit_long_conditions), "exit_long"] = 1
|
|
||||||
|
|
||||||
exit_short_conditions = [df["do_predict"] == 1, df["&-action"] == 4]
|
|
||||||
if exit_short_conditions:
|
|
||||||
df.loc[reduce(lambda x, y: x & y, exit_short_conditions), "exit_short"] = 1
|
|
||||||
|
|
||||||
return df
|
|
||||||
```
|
|
||||||
|
|
||||||
It is important to consider that `&-action` depends on which environment they choose to use. The example above shows 5 actions, where 0 is neutral, 1 is enter long, 2 is exit long, 3 is enter short and 4 is exit short.
|
|
||||||
|
|
||||||
## Configuring the Reinforcement Learner
|
|
||||||
|
|
||||||
In order to configure the `Reinforcement Learner` the following dictionary must exist in the `freqai` config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"rl_config": {
|
|
||||||
"train_cycles": 25,
|
|
||||||
"add_state_info": true,
|
|
||||||
"max_trade_duration_candles": 300,
|
|
||||||
"max_training_drawdown_pct": 0.02,
|
|
||||||
"cpu_count": 8,
|
|
||||||
"model_type": "PPO",
|
|
||||||
"policy_type": "MlpPolicy",
|
|
||||||
"model_reward_parameters": {
|
|
||||||
"rr": 1,
|
|
||||||
"profit_aim": 0.025
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Parameter details can be found [here](freqai-parameter-table.md), but in general the `train_cycles` decides how many times the agent should cycle through the candle data in its artificial environment to train weights in the model. `model_type` is a string which selects one of the available models in [stable_baselines](https://stable-baselines3.readthedocs.io/en/master/)(external link).
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
If you would like to experiment with `continual_learning`, then you should set that value to `true` in the main `freqai` configuration dictionary. This will tell the Reinforcement Learning library to continue training new models from the final state of previous models, instead of retraining new models from scratch each time a retrain is initiated.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Remember that the general `model_training_parameters` dictionary should contain all the model hyperparameter customizations for the particular `model_type`. For example, `PPO` parameters can be found [here](https://stable-baselines3.readthedocs.io/en/master/modules/ppo.html).
|
|
||||||
|
|
||||||
## Creating a custom reward function
|
|
||||||
|
|
||||||
As you begin to modify the strategy and the prediction model, you will quickly realize some important differences between the Reinforcement Learner and the Regressors/Classifiers. Firstly, the strategy does not set a target value (no labels!). Instead, you set the `calculate_reward()` function inside the `MyRLEnv` class (see below). A default `calculate_reward()` is provided inside `prediction_models/ReinforcementLearner.py` to demonstrate the necessary building blocks for creating rewards, but users are encouraged to create their own custom reinforcement learning model class (see below) and save it to `user_data/freqaimodels`. It is inside the `calculate_reward()` where creative theories about the market can be expressed. For example, you can reward your agent when it makes a winning trade, and penalize the agent when it makes a losing trade. Or perhaps, you wish to reward the agent for entering trades, and penalize the agent for sitting in trades too long. Below we show examples of how these rewards are all calculated:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from freqtrade.freqai.prediction_models.ReinforcementLearner import ReinforcementLearner
|
|
||||||
from freqtrade.freqai.RL.Base5ActionRLEnv import Actions, Base5ActionRLEnv, Positions
|
|
||||||
|
|
||||||
|
|
||||||
class MyCoolRLModel(ReinforcementLearner):
|
|
||||||
"""
|
|
||||||
User created RL prediction model.
|
|
||||||
|
|
||||||
Save this file to `freqtrade/user_data/freqaimodels`
|
|
||||||
|
|
||||||
then use it with:
|
|
||||||
|
|
||||||
freqtrade trade --freqaimodel MyCoolRLModel --config config.json --strategy SomeCoolStrat
|
|
||||||
|
|
||||||
Here the users can override any of the functions
|
|
||||||
available in the `IFreqaiModel` inheritance tree. Most importantly for RL, this
|
|
||||||
is where the user overrides `MyRLEnv` (see below), to define custom
|
|
||||||
`calculate_reward()` function, or to override any other parts of the environment.
|
|
||||||
|
|
||||||
This class also allows users to override any other part of the IFreqaiModel tree.
|
|
||||||
For example, the user can override `def fit()` or `def train()` or `def predict()`
|
|
||||||
to take fine-tuned control over these processes.
|
|
||||||
|
|
||||||
Another common override may be `def data_cleaning_predict()` where the user can
|
|
||||||
take fine-tuned control over the data handling pipeline.
|
|
||||||
"""
|
|
||||||
class MyRLEnv(Base5ActionRLEnv):
|
|
||||||
"""
|
|
||||||
User made custom environment. This class inherits from BaseEnvironment and gym.env.
|
|
||||||
Users can override any functions from those parent classes. Here is an example
|
|
||||||
of a user customized `calculate_reward()` function.
|
|
||||||
"""
|
|
||||||
def calculate_reward(self, action: int) -> float:
|
|
||||||
# first, penalize if the action is not valid
|
|
||||||
if not self._is_valid(action):
|
|
||||||
return -2
|
|
||||||
pnl = self.get_unrealized_profit()
|
|
||||||
|
|
||||||
factor = 100
|
|
||||||
|
|
||||||
pair = self.pair.replace(':', '')
|
|
||||||
|
|
||||||
# you can use feature values from dataframe
|
|
||||||
# Assumes the shifted RSI indicator has been generated in the strategy.
|
|
||||||
rsi_now = self.raw_features[f"%-rsi-period_10_shift-1_{pair}_"
|
|
||||||
f"{self.config['timeframe']}"].iloc[self._current_tick]
|
|
||||||
|
|
||||||
# reward agent for entering trades
|
|
||||||
if (action in (Actions.Long_enter.value, Actions.Short_enter.value)
|
|
||||||
and self._position == Positions.Neutral):
|
|
||||||
if rsi_now < 40:
|
|
||||||
factor = 40 / rsi_now
|
|
||||||
else:
|
|
||||||
factor = 1
|
|
||||||
return 25 * factor
|
|
||||||
|
|
||||||
# discourage agent from not entering trades
|
|
||||||
if action == Actions.Neutral.value and self._position == Positions.Neutral:
|
|
||||||
return -1
|
|
||||||
max_trade_duration = self.rl_config.get('max_trade_duration_candles', 300)
|
|
||||||
trade_duration = self._current_tick - self._last_trade_tick
|
|
||||||
if trade_duration <= max_trade_duration:
|
|
||||||
factor *= 1.5
|
|
||||||
elif trade_duration > max_trade_duration:
|
|
||||||
factor *= 0.5
|
|
||||||
# discourage sitting in position
|
|
||||||
if self._position in (Positions.Short, Positions.Long) and \
|
|
||||||
action == Actions.Neutral.value:
|
|
||||||
return -1 * trade_duration / max_trade_duration
|
|
||||||
# close long
|
|
||||||
if action == Actions.Long_exit.value and self._position == Positions.Long:
|
|
||||||
if pnl > self.profit_aim * self.rr:
|
|
||||||
factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)
|
|
||||||
return float(pnl * factor)
|
|
||||||
# close short
|
|
||||||
if action == Actions.Short_exit.value and self._position == Positions.Short:
|
|
||||||
if pnl > self.profit_aim * self.rr:
|
|
||||||
factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)
|
|
||||||
return float(pnl * factor)
|
|
||||||
return 0.
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Tensorboard
|
|
||||||
|
|
||||||
Reinforcement Learning models benefit from tracking training metrics. FreqAI has integrated Tensorboard to allow users to track training and evaluation performance across all coins and across all retrainings. Tensorboard is activated via the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd freqtrade
|
|
||||||
tensorboard --logdir user_data/models/unique-id
|
|
||||||
```
|
|
||||||
|
|
||||||
where `unique-id` is the `identifier` set in the `freqai` configuration file. This command must be run in a separate shell to view the output in their browser at 127.0.0.1:6006 (6006 is the default port used by Tensorboard).
|
|
||||||
|
|
||||||
![tensorboard](assets/tensorboard.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
### Custom logging
|
|
||||||
|
|
||||||
FreqAI also provides a built in episodic summary logger called `self.tensorboard_log` for adding custom information to the Tensorboard log. By default, this function is already called once per step inside the environment to record the agent actions. All values accumulated for all steps in a single episode are reported at the conclusion of each episode, followed by a full reset of all metrics to 0 in preparation for the subsequent episode.
|
|
||||||
|
|
||||||
|
|
||||||
`self.tensorboard_log` can also be used anywhere inside the environment, for example, it can be added to the `calculate_reward` function to collect more detailed information about how often various parts of the reward were called:
|
|
||||||
|
|
||||||
```py
|
|
||||||
class MyRLEnv(Base5ActionRLEnv):
|
|
||||||
"""
|
|
||||||
User made custom environment. This class inherits from BaseEnvironment and gym.env.
|
|
||||||
Users can override any functions from those parent classes. Here is an example
|
|
||||||
of a user customized `calculate_reward()` function.
|
|
||||||
"""
|
|
||||||
def calculate_reward(self, action: int) -> float:
|
|
||||||
if not self._is_valid(action):
|
|
||||||
self.tensorboard_log("invalid")
|
|
||||||
return -2
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
The `self.tensorboard_log()` function is designed for tracking incremented objects only i.e. events, actions inside the training environment. If the event of interest is a float, the float can be passed as the second argument e.g. `self.tensorboard_log("float_metric1", 0.23)`. In this case the metric values are not incremented.
|
|
||||||
|
|
||||||
### Choosing a base environment
|
|
||||||
|
|
||||||
FreqAI provides three base environments, `Base3ActionRLEnvironment`, `Base4ActionEnvironment` and `Base5ActionEnvironment`. As the names imply, the environments are customized for agents that can select from 3, 4 or 5 actions. The `Base3ActionEnvironment` is the simplest, the agent can select from hold, long, or short. This environment can also be used for long-only bots (it automatically follows the `can_short` flag from the strategy), where long is the enter condition and short is the exit condition. Meanwhile, in the `Base4ActionEnvironment`, the agent can enter long, enter short, hold neutral, or exit position. Finally, in the `Base5ActionEnvironment`, the agent has the same actions as Base4, but instead of a single exit action, it separates exit long and exit short. The main changes stemming from the environment selection include:
|
|
||||||
|
|
||||||
* the actions available in the `calculate_reward`
|
|
||||||
* the actions consumed by the user strategy
|
|
||||||
|
|
||||||
All of the FreqAI provided environments inherit from an action/position agnostic environment object called the `BaseEnvironment`, which contains all shared logic. The architecture is designed to be easily customized. The simplest customization is the `calculate_reward()` (see details [here](#creating-a-custom-reward-function)). However, the customizations can be further extended into any of the functions inside the environment. You can do this by simply overriding those functions inside your `MyRLEnv` in the prediction model file. Or for more advanced customizations, it is encouraged to create an entirely new environment inherited from `BaseEnvironment`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Only the `Base3ActionRLEnv` can do long-only training/trading (set the user strategy attribute `can_short = False`).
|
|
@ -1,170 +0,0 @@
|
|||||||
# Running FreqAI
|
|
||||||
|
|
||||||
There are two ways to train and deploy an adaptive machine learning model - live deployment and historical backtesting. In both cases, FreqAI runs/simulates periodic retraining of models as shown in the following figure:
|
|
||||||
|
|
||||||
![freqai-window](assets/freqai_moving-window.jpg)
|
|
||||||
|
|
||||||
## Live deployments
|
|
||||||
|
|
||||||
FreqAI can be run dry/live using the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade trade --strategy FreqaiExampleStrategy --config config_freqai.example.json --freqaimodel LightGBMRegressor
|
|
||||||
```
|
|
||||||
|
|
||||||
When launched, FreqAI will start training a new model, with a new `identifier`, based on the config settings. Following training, the model will be used to make predictions on incoming candles until a new model is available. New models are typically generated as often as possible, with FreqAI managing an internal queue of the coin pairs to try to keep all models equally up to date. FreqAI will always use the most recently trained model to make predictions on incoming live data. If you do not want FreqAI to retrain new models as often as possible, you can set `live_retrain_hours` to tell FreqAI to wait at least that number of hours before training a new model. Additionally, you can set `expired_hours` to tell FreqAI to avoid making predictions on models that are older than that number of hours.
|
|
||||||
|
|
||||||
Trained models are by default saved to disk to allow for reuse during backtesting or after a crash. You can opt to [purge old models](#purging-old-model-data) to save disk space by setting `"purge_old_models": true` in the config.
|
|
||||||
|
|
||||||
To start a dry/live run from a saved backtest model (or from a previously crashed dry/live session), you only need to specify the `identifier` of the specific model:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"identifier": "example",
|
|
||||||
"live_retrain_hours": 0.5
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In this case, although FreqAI will initiate with a pre-trained model, it will still check to see how much time has elapsed since the model was trained. If a full `live_retrain_hours` has elapsed since the end of the loaded model, FreqAI will start training a new model.
|
|
||||||
|
|
||||||
### Automatic data download
|
|
||||||
|
|
||||||
FreqAI automatically downloads the proper amount of data needed to ensure training of a model through the defined `train_period_days` and `startup_candle_count` (see the [parameter table](freqai-parameter-table.md) for detailed descriptions of these parameters).
|
|
||||||
|
|
||||||
### Saving prediction data
|
|
||||||
|
|
||||||
All predictions made during the lifetime of a specific `identifier` model are stored in `historic_predictions.pkl` to allow for reloading after a crash or changes made to the config.
|
|
||||||
|
|
||||||
### Purging old model data
|
|
||||||
|
|
||||||
FreqAI stores new model files after each successful training. These files become obsolete as new models are generated to adapt to new market conditions. If you are planning to leave FreqAI running for extended periods of time with high frequency retraining, you should enable `purge_old_models` in the config:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"purge_old_models": true,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This will automatically purge all models older than the two most recently trained ones to save disk space.
|
|
||||||
|
|
||||||
## Backtesting
|
|
||||||
|
|
||||||
The FreqAI backtesting module can be executed with the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701
|
|
||||||
```
|
|
||||||
|
|
||||||
If this command has never been executed with the existing config file, FreqAI will train a new model
|
|
||||||
for each pair, for each backtesting window within the expanded `--timerange`.
|
|
||||||
|
|
||||||
Backtesting mode requires [downloading the necessary data](#downloading-data-to-cover-the-full-backtest-period) before deployment (unlike in dry/live mode where FreqAI handles the data downloading automatically). You should be careful to consider that the time range of the downloaded data is more than the backtesting time range. This is because FreqAI needs data prior to the desired backtesting time range in order to train a model to be ready to make predictions on the first candle of the set backtesting time range. More details on how to calculate the data to download can be found [here](#deciding-the-size-of-the-sliding-training-window-and-backtesting-duration).
|
|
||||||
|
|
||||||
!!! Note "Model reuse"
|
|
||||||
Once the training is completed, you can execute the backtesting again with the same config file and
|
|
||||||
FreqAI will find the trained models and load them instead of spending time training. This is useful
|
|
||||||
if you want to tweak (or even hyperopt) buy and sell criteria inside the strategy. If you
|
|
||||||
*want* to retrain a new model with the same config file, you should simply change the `identifier`.
|
|
||||||
This way, you can return to using any model you wish by simply specifying the `identifier`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Backtesting calls `set_freqai_targets()` one time for each backtest window (where the number of windows is the full backtest timerange divided by the `backtest_period_days` parameter). Doing this means that the targets simulate dry/live behavior without look ahead bias. However, the definition of the features in `feature_engineering_*()` is performed once on the entire backtest timerange. This means that you should be sure that features do look-ahead into the future.
|
|
||||||
More details about look-ahead bias can be found in [Common Mistakes](strategy-customization.md#common-mistakes-when-developing-strategies).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Saving prediction data
|
|
||||||
|
|
||||||
To allow for tweaking your strategy (**not** the features!), FreqAI will automatically save the predictions during backtesting so that they can be reused for future backtests and live runs using the same `identifier` model. This provides a performance enhancement geared towards enabling **high-level hyperopting** of entry/exit criteria.
|
|
||||||
|
|
||||||
An additional directory called `backtesting_predictions`, which contains all the predictions stored in `hdf` format, will be created in the `unique-id` folder.
|
|
||||||
|
|
||||||
To change your **features**, you **must** set a new `identifier` in the config to signal to FreqAI to train new models.
|
|
||||||
|
|
||||||
To save the models generated during a particular backtest so that you can start a live deployment from one of them instead of training a new model, you must set `save_backtest_models` to `True` in the config.
|
|
||||||
|
|
||||||
### Backtest live collected predictions
|
|
||||||
|
|
||||||
FreqAI allow you to reuse live historic predictions through the backtest parameter `--freqai-backtest-live-models`. This can be useful when you want to reuse predictions generated in dry/run for comparison or other study.
|
|
||||||
|
|
||||||
The `--timerange` parameter must not be informed, as it will be automatically calculated through the data in the historic predictions file.
|
|
||||||
|
|
||||||
|
|
||||||
### Downloading data to cover the full backtest period
|
|
||||||
|
|
||||||
For live/dry deployments, FreqAI will download the necessary data automatically. However, to use backtesting functionality, you need to download the necessary data using `download-data` (details [here](data-download.md#data-downloading)). You need to pay careful attention to understanding how much *additional* data needs to be downloaded to ensure that there is a sufficient amount of training data *before* the start of the backtesting time range. The amount of additional data can be roughly estimated by moving the start date of the time range backwards by `train_period_days` and the `startup_candle_count` (see the [parameter table](freqai-parameter-table.md) for detailed descriptions of these parameters) from the beginning of the desired backtesting time range.
|
|
||||||
|
|
||||||
As an example, to backtest the `--timerange 20210501-20210701` using the [example config](freqai-configuration.md#setting-up-the-configuration-file) which sets `train_period_days` to 30, together with `startup_candle_count: 40` on a maximum `include_timeframes` of 1h, the start date for the downloaded data needs to be `20210501` - 30 days - 40 * 1h / 24 hours = 20210330 (31.7 days earlier than the start of the desired training time range).
|
|
||||||
|
|
||||||
### Deciding the size of the sliding training window and backtesting duration
|
|
||||||
|
|
||||||
The backtesting time range is defined with the typical `--timerange` parameter in the configuration file. The duration of the sliding training window is set by `train_period_days`, whilst `backtest_period_days` is the sliding backtesting window, both in number of days (`backtest_period_days` can be
|
|
||||||
a float to indicate sub-daily retraining in live/dry mode). In the presented [example config](freqai-configuration.md#setting-up-the-configuration-file) (found in `config_examples/config_freqai.example.json`), the user is asking FreqAI to use a training period of 30 days and backtest on the subsequent 7 days. After the training of the model, FreqAI will backtest the subsequent 7 days. The "sliding window" then moves one week forward (emulating FreqAI retraining once per week in live mode) and the new model uses the previous 30 days (including the 7 days used for backtesting by the previous model) to train. This is repeated until the end of `--timerange`. This means that if you set `--timerange 20210501-20210701`, FreqAI will have trained 8 separate models at the end of `--timerange` (because the full range comprises 8 weeks).
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Although fractional `backtest_period_days` is allowed, you should be aware that the `--timerange` is divided by this value to determine the number of models that FreqAI will need to train in order to backtest the full range. For example, by setting a `--timerange` of 10 days, and a `backtest_period_days` of 0.1, FreqAI will need to train 100 models per pair to complete the full backtest. Because of this, a true backtest of FreqAI adaptive training would take a *very* long time. The best way to fully test a model is to run it dry and let it train constantly. In this case, backtesting would take the exact same amount of time as a dry run.
|
|
||||||
|
|
||||||
## Defining model expirations
|
|
||||||
|
|
||||||
During dry/live mode, FreqAI trains each coin pair sequentially (on separate threads/GPU from the main Freqtrade bot). This means that there is always an age discrepancy between models. If you are training on 50 pairs, and each pair requires 5 minutes to train, the oldest model will be over 4 hours old. This may be undesirable if the characteristic time scale (the trade duration target) for a strategy is less than 4 hours. You can decide to only make trade entries if the model is less than a certain number of hours old by setting the `expiration_hours` in the config file:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"freqai": {
|
|
||||||
"expiration_hours": 0.5,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In the presented example config, the user will only allow predictions on models that are less than 1/2 hours old.
|
|
||||||
|
|
||||||
## Controlling the model learning process
|
|
||||||
|
|
||||||
Model training parameters are unique to the selected machine learning library. FreqAI allows you to set any parameter for any library using the `model_training_parameters` dictionary in the config. The example config (found in `config_examples/config_freqai.example.json`) shows some of the example parameters associated with `Catboost` and `LightGBM`, but you can add any parameters available in those libraries or any other machine learning library you choose to implement.
|
|
||||||
|
|
||||||
Data split parameters are defined in `data_split_parameters` which can be any parameters associated with scikit-learn's `train_test_split()` function. `train_test_split()` has a parameters called `shuffle` which allows to shuffle the data or keep it unshuffled. This is particularly useful to avoid biasing training with temporally auto-correlated data. More details about these parameters can be found the [scikit-learn website](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html) (external website).
|
|
||||||
|
|
||||||
The FreqAI specific parameter `label_period_candles` defines the offset (number of candles into the future) used for the `labels`. In the presented [example config](freqai-configuration.md#setting-up-the-configuration-file), the user is asking for `labels` that are 24 candles in the future.
|
|
||||||
|
|
||||||
## Continual learning
|
|
||||||
|
|
||||||
You can choose to adopt a continual learning scheme by setting `"continual_learning": true` in the config. By enabling `continual_learning`, after training an initial model from scratch, subsequent trainings will start from the final model state of the preceding training. This gives the new model a "memory" of the previous state. By default, this is set to `False` which means that all new models are trained from scratch, without input from previous models.
|
|
||||||
|
|
||||||
???+ danger "Continual learning enforces a constant parameter space"
|
|
||||||
Since `continual_learning` means that the model parameter space *cannot* change between trainings, `principal_component_analysis` is automatically disabled when `continual_learning` is enabled. Hint: PCA changes the parameter space and the number of features, learn more about PCA [here](freqai-feature-engineering.md#data-dimensionality-reduction-with-principal-component-analysis).
|
|
||||||
|
|
||||||
## Hyperopt
|
|
||||||
|
|
||||||
You can hyperopt using the same command as for [typical Freqtrade hyperopt](hyperopt.md):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --timerange 20220428-20220507
|
|
||||||
```
|
|
||||||
|
|
||||||
`hyperopt` requires you to have the data pre-downloaded in the same fashion as if you were doing [backtesting](#backtesting). In addition, you must consider some restrictions when trying to hyperopt FreqAI strategies:
|
|
||||||
|
|
||||||
- The `--analyze-per-epoch` hyperopt parameter is not compatible with FreqAI.
|
|
||||||
- It's not possible to hyperopt indicators in the `feature_engineering_*()` and `set_freqai_targets()` functions. This means that you cannot optimize model parameters using hyperopt. Apart from this exception, it is possible to optimize all other [spaces](hyperopt.md#running-hyperopt-with-smaller-search-space).
|
|
||||||
- The backtesting instructions also apply to hyperopt.
|
|
||||||
|
|
||||||
The best method for combining hyperopt and FreqAI is to focus on hyperopting entry/exit thresholds/criteria. You need to focus on hyperopting parameters that are not used in your features. For example, you should not try to hyperopt rolling window lengths in the feature creation, or any part of the FreqAI config which changes predictions. In order to efficiently hyperopt the FreqAI strategy, FreqAI stores predictions as dataframes and reuses them. Hence the requirement to hyperopt entry/exit thresholds/criteria only.
|
|
||||||
|
|
||||||
A good example of a hyperoptable parameter in FreqAI is a threshold for the [Dissimilarity Index (DI)](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di) `DI_values` beyond which we consider data points as outliers:
|
|
||||||
|
|
||||||
```python
|
|
||||||
di_max = IntParameter(low=1, high=20, default=10, space='buy', optimize=True, load=True)
|
|
||||||
dataframe['outlier'] = np.where(dataframe['DI_values'] > self.di_max.value/10, 1, 0)
|
|
||||||
```
|
|
||||||
|
|
||||||
This specific hyperopt would help you understand the appropriate `DI_values` for your particular parameter space.
|
|
||||||
|
|
||||||
## Using Tensorboard
|
|
||||||
|
|
||||||
CatBoost models benefit from tracking training metrics via Tensorboard. You can take advantage of the FreqAI integration to track training and evaluation performance across all coins and across all retrainings. Tensorboard is activated via the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd freqtrade
|
|
||||||
tensorboard --logdir user_data/models/unique-id
|
|
||||||
```
|
|
||||||
|
|
||||||
where `unique-id` is the `identifier` set in the `freqai` configuration file. This command must be run in a separate shell if you wish to view the output in your browser at 127.0.0.1:6060 (6060 is the default port used by Tensorboard).
|
|
||||||
|
|
||||||
![tensorboard](assets/tensorboard.jpg)
|
|
127
docs/freqai.md
@ -1,127 +0,0 @@
|
|||||||
![freqai-logo](assets/freqai_doc_logo.svg)
|
|
||||||
|
|
||||||
# FreqAI
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
|
|
||||||
FreqAI is a software designed to automate a variety of tasks associated with training a predictive machine learning model to generate market forecasts given a set of input signals. In general, FreqAI aims to be a sandbox for easily deploying robust machine learning libraries on real-time data ([details](#freqai-position-in-open-source-machine-learning-landscape)).
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
FreqAI is, and always will be, a not-for-profit, open-source project. FreqAI does *not* have a crypto token, FreqAI does *not* sell signals, and FreqAI does not have a domain besides the present [freqtrade documentation](https://www.freqtrade.io/en/latest/freqai/).
|
|
||||||
|
|
||||||
Features include:
|
|
||||||
|
|
||||||
* **Self-adaptive retraining** - Retrain models during [live deployments](freqai-running.md#live-deployments) to self-adapt to the market in a supervised manner
|
|
||||||
* **Rapid feature engineering** - Create large rich [feature sets](freqai-feature-engineering.md#feature-engineering) (10k+ features) based on simple user-created strategies
|
|
||||||
* **High performance** - Threading allows for adaptive model retraining on a separate thread (or on GPU if available) from model inferencing (prediction) and bot trade operations. Newest models and data are kept in RAM for rapid inferencing
|
|
||||||
* **Realistic backtesting** - Emulate self-adaptive training on historic data with a [backtesting module](freqai-running.md#backtesting) that automates retraining
|
|
||||||
* **Extensibility** - The generalized and robust architecture allows for incorporating any [machine learning library/method](freqai-configuration.md#using-different-prediction-models) available in Python. Eight examples are currently available, including classifiers, regressors, and a convolutional neural network
|
|
||||||
* **Smart outlier removal** - Remove outliers from training and prediction data sets using a variety of [outlier detection techniques](freqai-feature-engineering.md#outlier-detection)
|
|
||||||
* **Crash resilience** - Store trained models to disk to make reloading from a crash fast and easy, and [purge obsolete files](freqai-running.md#purging-old-model-data) for sustained dry/live runs
|
|
||||||
* **Automatic data normalization** - [Normalize the data](freqai-feature-engineering.md#feature-normalization) in a smart and statistically safe way
|
|
||||||
* **Automatic data download** - Compute timeranges for data downloads and update historic data (in live deployments)
|
|
||||||
* **Cleaning of incoming data** - Handle NaNs safely before training and model inferencing
|
|
||||||
* **Dimensionality reduction** - Reduce the size of the training data via [Principal Component Analysis](freqai-feature-engineering.md#data-dimensionality-reduction-with-principal-component-analysis)
|
|
||||||
* **Deploying bot fleets** - Set one bot to train models while a fleet of [consumers](producer-consumer.md) use signals.
|
|
||||||
|
|
||||||
## Quick start
|
|
||||||
|
|
||||||
The easiest way to quickly test FreqAI is to run it in dry mode with the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates
|
|
||||||
```
|
|
||||||
|
|
||||||
You will see the boot-up process of automatic data downloading, followed by simultaneous training and trading.
|
|
||||||
|
|
||||||
An example strategy, prediction model, and config to use as a starting points can be found in
|
|
||||||
`freqtrade/templates/FreqaiExampleStrategy.py`, `freqtrade/freqai/prediction_models/LightGBMRegressor.py`, and
|
|
||||||
`config_examples/config_freqai.example.json`, respectively.
|
|
||||||
|
|
||||||
## General approach
|
|
||||||
|
|
||||||
You provide FreqAI with a set of custom *base indicators* (the same way as in a [typical Freqtrade strategy](strategy-customization.md)) as well as target values (*labels*). For each pair in the whitelist, FreqAI trains a model to predict the target values based on the input of custom indicators. The models are then consistently retrained, with a predetermined frequency, to adapt to market conditions. FreqAI offers the ability to both backtest strategies (emulating reality with periodic retraining on historic data) and deploy dry/live runs. In dry/live conditions, FreqAI can be set to constant retraining in a background thread to keep models as up to date as possible.
|
|
||||||
|
|
||||||
An overview of the algorithm, explaining the data processing pipeline and model usage, is shown below.
|
|
||||||
|
|
||||||
![freqai-algo](assets/freqai_algo.jpg)
|
|
||||||
|
|
||||||
### Important machine learning vocabulary
|
|
||||||
|
|
||||||
**Features** - the parameters, based on historic data, on which a model is trained. All features for a single candle are stored as a vector. In FreqAI, you build a feature data set from anything you can construct in the strategy.
|
|
||||||
|
|
||||||
**Labels** - the target values that the model is trained toward. Each feature vector is associated with a single label that is defined by you within the strategy. These labels intentionally look into the future and are what you are training the model to be able to predict.
|
|
||||||
|
|
||||||
**Training** - the process of "teaching" the model to match the feature sets to the associated labels. Different types of models "learn" in different ways which means that one might be better than another for a specific application. More information about the different models that are already implemented in FreqAI can be found [here](freqai-configuration.md#using-different-prediction-models).
|
|
||||||
|
|
||||||
**Train data** - a subset of the feature data set that is fed to the model during training to "teach" the model how to predict the targets. This data directly influences weight connections in the model.
|
|
||||||
|
|
||||||
**Test data** - a subset of the feature data set that is used to evaluate the performance of the model after training. This data does not influence nodal weights within the model.
|
|
||||||
|
|
||||||
**Inferencing** - the process of feeding a trained model new unseen data on which it will make a prediction.
|
|
||||||
|
|
||||||
## Install prerequisites
|
|
||||||
|
|
||||||
The normal Freqtrade install process will ask if you wish to install FreqAI dependencies. You should reply "yes" to this question if you wish to use FreqAI. If you did not reply yes, you can manually install these dependencies after the install with:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
pip install -r requirements-freqai.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Catboost will not be installed on arm devices (raspberry, Mac M1, ARM based VPS, ...), since it does not provide wheels for this platform.
|
|
||||||
|
|
||||||
!!! Note "python 3.11"
|
|
||||||
Some dependencies (Catboost, Torch) currently don't support python 3.11. Freqtrade therefore only supports python 3.10 for these models/dependencies.
|
|
||||||
Tests involving these dependencies are skipped on 3.11.
|
|
||||||
|
|
||||||
### Usage with docker
|
|
||||||
|
|
||||||
If you are using docker, a dedicated tag with FreqAI dependencies is available as `:freqai`. As such - you can replace the image line in your docker compose file with `image: freqtradeorg/freqtrade:develop_freqai`. This image contains the regular FreqAI dependencies. Similar to native installs, Catboost will not be available on ARM based devices.
|
|
||||||
|
|
||||||
### FreqAI position in open-source machine learning landscape
|
|
||||||
|
|
||||||
Forecasting chaotic time-series based systems, such as equity/cryptocurrency markets, requires a broad set of tools geared toward testing a wide range of hypotheses. Fortunately, a recent maturation of robust machine learning libraries (e.g. `scikit-learn`) has opened up a wide range of research possibilities. Scientists from a diverse range of fields can now easily prototype their studies on an abundance of established machine learning algorithms. Similarly, these user-friendly libraries enable "citzen scientists" to use their basic Python skills for data exploration. However, leveraging these machine learning libraries on historical and live chaotic data sources can be logistically difficult and expensive. Additionally, robust data collection, storage, and handling presents a disparate challenge. [`FreqAI`](#freqai) aims to provide a generalized and extensible open-sourced framework geared toward live deployments of adaptive modeling for market forecasting. The `FreqAI` framework is effectively a sandbox for the rich world of open-source machine learning libraries. Inside the `FreqAI` sandbox, users find they can combine a wide variety of third-party libraries to test creative hypotheses on a free live 24/7 chaotic data source - cryptocurrency exchange data.
|
|
||||||
|
|
||||||
### Citing FreqAI
|
|
||||||
|
|
||||||
FreqAI is [published in the Journal of Open Source Software](https://joss.theoj.org/papers/10.21105/joss.04864). If you find FreqAI useful in your research, please use the following citation:
|
|
||||||
|
|
||||||
```bibtex
|
|
||||||
@article{Caulk2022,
|
|
||||||
doi = {10.21105/joss.04864},
|
|
||||||
url = {https://doi.org/10.21105/joss.04864},
|
|
||||||
year = {2022}, publisher = {The Open Journal},
|
|
||||||
volume = {7}, number = {80}, pages = {4864},
|
|
||||||
author = {Robert A. Caulk and Elin Törnquist and Matthias Voppichler and Andrew R. Lawless and Ryan McMullan and Wagner Costa Santos and Timothy C. Pogue and Johan van der Vlugt and Stefan P. Gehring and Pascal Schmidt},
|
|
||||||
title = {FreqAI: generalizing adaptive modeling for chaotic time-series market forecasts},
|
|
||||||
journal = {Journal of Open Source Software} }
|
|
||||||
```
|
|
||||||
|
|
||||||
## Common pitfalls
|
|
||||||
|
|
||||||
FreqAI cannot be combined with dynamic `VolumePairlists` (or any pairlist filter that adds and removes pairs dynamically).
|
|
||||||
This is for performance reasons - FreqAI relies on making quick predictions/retrains. To do this effectively,
|
|
||||||
it needs to download all the training data at the beginning of a dry/live instance. FreqAI stores and appends
|
|
||||||
new candles automatically for future retrains. This means that if new pairs arrive later in the dry run due to a volume pairlist, it will not have the data ready. However, FreqAI does work with the `ShufflePairlist` or a `VolumePairlist` which keeps the total pairlist constant (but reorders the pairs according to volume).
|
|
||||||
|
|
||||||
## Credits
|
|
||||||
|
|
||||||
FreqAI is developed by a group of individuals who all contribute specific skillsets to the project.
|
|
||||||
|
|
||||||
Conception and software development:
|
|
||||||
Robert Caulk @robcaulk
|
|
||||||
|
|
||||||
Theoretical brainstorming and data analysis:
|
|
||||||
Elin Törnquist @th0rntwig
|
|
||||||
|
|
||||||
Code review and software architecture brainstorming:
|
|
||||||
@xmatthias
|
|
||||||
|
|
||||||
Software development:
|
|
||||||
Wagner Costa @wagnercosta
|
|
||||||
Emre Suzen @aemr3
|
|
||||||
Timothy Pogue @wizrds
|
|
||||||
|
|
||||||
Beta testing and bug reporting:
|
|
||||||
Stefan Gehring @bloodhunter4rc, @longyu, Andrew Lawless @paranoidandy, Pascal Schmidt @smidelis, Ryan McMullan @smarmau, Juha Nykänen @suikula, Johan van der Vlugt @jooopiert, Richárd Józsa @richardjosza
|
|
323
docs/hyperopt.md
@ -40,31 +40,28 @@ pip install -r requirements-hyperopt.txt
|
|||||||
```
|
```
|
||||||
usage: freqtrade hyperopt [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
|
usage: freqtrade hyperopt [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
|
||||||
[--userdir PATH] [-s NAME] [--strategy-path PATH]
|
[--userdir PATH] [-s NAME] [--strategy-path PATH]
|
||||||
[--recursive-strategy-search] [--freqaimodel NAME]
|
[-i TIMEFRAME] [--timerange TIMERANGE]
|
||||||
[--freqaimodel-path PATH] [-i TIMEFRAME]
|
|
||||||
[--timerange TIMERANGE]
|
|
||||||
[--data-format-ohlcv {json,jsongz,hdf5}]
|
[--data-format-ohlcv {json,jsongz,hdf5}]
|
||||||
[--max-open-trades INT]
|
[--max-open-trades INT]
|
||||||
[--stake-amount STAKE_AMOUNT] [--fee FLOAT]
|
[--stake-amount STAKE_AMOUNT] [--fee FLOAT]
|
||||||
[-p PAIRS [PAIRS ...]] [--hyperopt-path PATH]
|
[-p PAIRS [PAIRS ...]] [--hyperopt NAME]
|
||||||
[--eps] [--dmmp] [--enable-protections]
|
[--hyperopt-path PATH] [--eps] [--dmmp]
|
||||||
[--dry-run-wallet DRY_RUN_WALLET]
|
[--enable-protections]
|
||||||
[--timeframe-detail TIMEFRAME_DETAIL] [-e INT]
|
[--dry-run-wallet DRY_RUN_WALLET] [-e INT]
|
||||||
[--spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]]
|
[--spaces {all,buy,sell,roi,stoploss,trailing,default} [{all,buy,sell,roi,stoploss,trailing,default} ...]]
|
||||||
[--print-all] [--no-color] [--print-json] [-j JOBS]
|
[--print-all] [--no-color] [--print-json] [-j JOBS]
|
||||||
[--random-state INT] [--min-trades INT]
|
[--random-state INT] [--min-trades INT]
|
||||||
[--hyperopt-loss NAME] [--disable-param-export]
|
[--hyperopt-loss NAME]
|
||||||
[--ignore-missing-spaces] [--analyze-per-epoch]
|
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-i TIMEFRAME, --timeframe TIMEFRAME
|
-i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
|
||||||
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
--data-format-ohlcv {json,jsongz,hdf5}
|
--data-format-ohlcv {json,jsongz,hdf5}
|
||||||
Storage format for downloaded candle (OHLCV) data.
|
Storage format for downloaded candle (OHLCV) data.
|
||||||
(default: `json`).
|
(default: `None`).
|
||||||
--max-open-trades INT
|
--max-open-trades INT
|
||||||
Override the value of the `max_open_trades`
|
Override the value of the `max_open_trades`
|
||||||
configuration setting.
|
configuration setting.
|
||||||
@ -76,8 +73,10 @@ optional arguments:
|
|||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Limit command to these pairs. Pairs are space-
|
Limit command to these pairs. Pairs are space-
|
||||||
separated.
|
separated.
|
||||||
--hyperopt-path PATH Specify additional lookup path for Hyperopt Loss
|
--hyperopt NAME Specify hyperopt class name which will be used by the
|
||||||
functions.
|
bot.
|
||||||
|
--hyperopt-path PATH Specify additional lookup path for Hyperopt and
|
||||||
|
Hyperopt Loss functions.
|
||||||
--eps, --enable-position-stacking
|
--eps, --enable-position-stacking
|
||||||
Allow buying the same pair multiple times (position
|
Allow buying the same pair multiple times (position
|
||||||
stacking).
|
stacking).
|
||||||
@ -92,11 +91,8 @@ optional arguments:
|
|||||||
--dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
|
--dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
|
||||||
Starting balance, used for backtesting / hyperopt and
|
Starting balance, used for backtesting / hyperopt and
|
||||||
dry-runs.
|
dry-runs.
|
||||||
--timeframe-detail TIMEFRAME_DETAIL
|
|
||||||
Specify detail timeframe for backtesting (`1m`, `5m`,
|
|
||||||
`30m`, `1h`, `1d`).
|
|
||||||
-e INT, --epochs INT Specify number of epochs (default: 100).
|
-e INT, --epochs INT Specify number of epochs (default: 100).
|
||||||
--spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]
|
--spaces {all,buy,sell,roi,stoploss,trailing,default} [{all,buy,sell,roi,stoploss,trailing,default} ...]
|
||||||
Specify which parameters to hyperopt. Space-separated
|
Specify which parameters to hyperopt. Space-separated
|
||||||
list.
|
list.
|
||||||
--print-all Print all results, not only the best ones.
|
--print-all Print all results, not only the best ones.
|
||||||
@ -121,16 +117,7 @@ optional arguments:
|
|||||||
Hyperopt-loss-functions are:
|
Hyperopt-loss-functions are:
|
||||||
ShortTradeDurHyperOptLoss, OnlyProfitHyperOptLoss,
|
ShortTradeDurHyperOptLoss, OnlyProfitHyperOptLoss,
|
||||||
SharpeHyperOptLoss, SharpeHyperOptLossDaily,
|
SharpeHyperOptLoss, SharpeHyperOptLossDaily,
|
||||||
SortinoHyperOptLoss, SortinoHyperOptLossDaily,
|
SortinoHyperOptLoss, SortinoHyperOptLossDaily
|
||||||
CalmarHyperOptLoss, MaxDrawDownHyperOptLoss,
|
|
||||||
MaxDrawDownRelativeHyperOptLoss,
|
|
||||||
ProfitDrawDownHyperOptLoss
|
|
||||||
--disable-param-export
|
|
||||||
Disable automatic hyperopt parameter export.
|
|
||||||
--ignore-missing-spaces, --ignore-unparameterized-spaces
|
|
||||||
Suppress errors for any requested Hyperopt spaces that
|
|
||||||
do not contain any parameters.
|
|
||||||
--analyze-per-epoch Run populate_indicators once per epoch.
|
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
@ -153,12 +140,6 @@ Strategy arguments:
|
|||||||
Specify strategy class name which will be used by the
|
Specify strategy class name which will be used by the
|
||||||
bot.
|
bot.
|
||||||
--strategy-path PATH Specify additional strategy lookup path.
|
--strategy-path PATH Specify additional strategy lookup path.
|
||||||
--recursive-strategy-search
|
|
||||||
Recursively search for a strategy in the strategies
|
|
||||||
folder.
|
|
||||||
--freqaimodel NAME Specify a custom freqaimodels.
|
|
||||||
--freqaimodel-path PATH
|
|
||||||
Specify additional lookup path for freqaimodels.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -168,8 +149,8 @@ Checklist on all tasks / possibilities in hyperopt
|
|||||||
|
|
||||||
Depending on the space you want to optimize, only some of the below are required:
|
Depending on the space you want to optimize, only some of the below are required:
|
||||||
|
|
||||||
* define parameters with `space='buy'` - for entry signal optimization
|
* define parameters with `space='buy'` - for buy signal optimization
|
||||||
* define parameters with `space='sell'` - for exit signal optimization
|
* define parameters with `space='sell'` - for sell signal optimization
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
`populate_indicators` needs to create all indicators any of the spaces may use, otherwise hyperopt will not work.
|
`populate_indicators` needs to create all indicators any of the spaces may use, otherwise hyperopt will not work.
|
||||||
@ -180,7 +161,6 @@ Rarely you may also need to create a [nested class](advanced-hyperopt.md#overrid
|
|||||||
* `generate_roi_table` - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
|
* `generate_roi_table` - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
|
||||||
* `stoploss_space` - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
|
* `stoploss_space` - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
|
||||||
* `trailing_space` - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
|
* `trailing_space` - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
|
||||||
* `max_open_trades_space` - for custom max_open_trades optimization (if you need the ranges for the max_open_trades parameter in the optimization hyperspace that differ from default)
|
|
||||||
|
|
||||||
!!! Tip "Quickly optimize ROI, stoploss and trailing stoploss"
|
!!! Tip "Quickly optimize ROI, stoploss and trailing stoploss"
|
||||||
You can quickly optimize the spaces `roi`, `stoploss` and `trailing` without changing anything in your strategy.
|
You can quickly optimize the spaces `roi`, `stoploss` and `trailing` without changing anything in your strategy.
|
||||||
@ -192,11 +172,11 @@ Rarely you may also need to create a [nested class](advanced-hyperopt.md#overrid
|
|||||||
|
|
||||||
### Hyperopt execution logic
|
### Hyperopt execution logic
|
||||||
|
|
||||||
Hyperopt will first load your data into memory and will then run `populate_indicators()` once per Pair to generate all indicators, unless `--analyze-per-epoch` is specified.
|
Hyperopt will first load your data into memory and will then run `populate_indicators()` once per Pair to generate all indicators.
|
||||||
|
|
||||||
Hyperopt will then spawn into different processes (number of processors, or `-j <n>`), and run backtesting over and over again, changing the parameters that are part of the `--spaces` defined.
|
Hyperopt will then spawn into different processes (number of processors, or `-j <n>`), and run backtesting over and over again, changing the parameters that are part of the `--spaces` defined.
|
||||||
|
|
||||||
For every new set of parameters, freqtrade will run first `populate_entry_trend()` followed by `populate_exit_trend()`, and then run the regular backtesting process to simulate trades.
|
For every new set of parameters, freqtrade will run first `populate_buy_trend()` followed by `populate_sell_trend()`, and then run the regular backtesting process to simulate trades.
|
||||||
|
|
||||||
After backtesting, the results are passed into the [loss function](#loss-functions), which will evaluate if this result was better or worse than previous results.
|
After backtesting, the results are passed into the [loss function](#loss-functions), which will evaluate if this result was better or worse than previous results.
|
||||||
Based on the loss function result, hyperopt will determine the next set of parameters to try in the next round of backtesting.
|
Based on the loss function result, hyperopt will determine the next set of parameters to try in the next round of backtesting.
|
||||||
@ -206,7 +186,7 @@ Based on the loss function result, hyperopt will determine the next set of param
|
|||||||
There are two places you need to change in your strategy file to add a new buy hyperopt for testing:
|
There are two places you need to change in your strategy file to add a new buy hyperopt for testing:
|
||||||
|
|
||||||
* Define the parameters at the class level hyperopt shall be optimizing.
|
* Define the parameters at the class level hyperopt shall be optimizing.
|
||||||
* Within `populate_entry_trend()` - use defined parameter values instead of raw constants.
|
* Within `populate_buy_trend()` - use defined parameter values instead of raw constants.
|
||||||
|
|
||||||
There you have two different types of indicators: 1. `guards` and 2. `triggers`.
|
There you have two different types of indicators: 1. `guards` and 2. `triggers`.
|
||||||
|
|
||||||
@ -216,24 +196,24 @@ There you have two different types of indicators: 1. `guards` and 2. `triggers`.
|
|||||||
!!! Hint "Guards and Triggers"
|
!!! Hint "Guards and Triggers"
|
||||||
Technically, there is no difference between Guards and Triggers.
|
Technically, there is no difference between Guards and Triggers.
|
||||||
However, this guide will make this distinction to make it clear that signals should not be "sticking".
|
However, this guide will make this distinction to make it clear that signals should not be "sticking".
|
||||||
Sticking signals are signals that are active for multiple candles. This can lead into entering a signal late (right before the signal disappears - which means that the chance of success is a lot lower than right at the beginning).
|
Sticking signals are signals that are active for multiple candles. This can lead into buying a signal late (right before the signal disappears - which means that the chance of success is a lot lower than right at the beginning).
|
||||||
|
|
||||||
Hyper-optimization will, for each epoch round, pick one trigger and possibly multiple guards.
|
Hyper-optimization will, for each epoch round, pick one trigger and possibly multiple guards.
|
||||||
|
|
||||||
#### Exit signal optimization
|
#### Sell optimization
|
||||||
|
|
||||||
Similar to the entry-signal above, exit-signals can also be optimized.
|
Similar to the buy-signal above, sell-signals can also be optimized.
|
||||||
Place the corresponding settings into the following methods
|
Place the corresponding settings into the following methods
|
||||||
|
|
||||||
* Define the parameters at the class level hyperopt shall be optimizing, either naming them `sell_*`, or by explicitly defining `space='sell'`.
|
* Define the parameters at the class level hyperopt shall be optimizing, either naming them `sell_*`, or by explicitly defining `space='sell'`.
|
||||||
* Within `populate_exit_trend()` - use defined parameter values instead of raw constants.
|
* Within `populate_sell_trend()` - use defined parameter values instead of raw constants.
|
||||||
|
|
||||||
The configuration and rules are the same than for buy signals.
|
The configuration and rules are the same than for buy signals.
|
||||||
|
|
||||||
## Solving a Mystery
|
## Solving a Mystery
|
||||||
|
|
||||||
Let's say you are curious: should you use MACD crossings or lower Bollinger Bands to trigger your long entries.
|
Let's say you are curious: should you use MACD crossings or lower Bollinger Bands to trigger your buys.
|
||||||
And you also wonder should you use RSI or ADX to help with those decisions.
|
And you also wonder should you use RSI or ADX to help with those buy decisions.
|
||||||
If you decide to use RSI or ADX, which values should I use for them?
|
If you decide to use RSI or ADX, which values should I use for them?
|
||||||
|
|
||||||
So let's use hyperparameter optimization to solve this mystery.
|
So let's use hyperparameter optimization to solve this mystery.
|
||||||
@ -271,7 +251,7 @@ We continue to define hyperoptable parameters:
|
|||||||
class MyAwesomeStrategy(IStrategy):
|
class MyAwesomeStrategy(IStrategy):
|
||||||
buy_adx = DecimalParameter(20, 40, decimals=1, default=30.1, space="buy")
|
buy_adx = DecimalParameter(20, 40, decimals=1, default=30.1, space="buy")
|
||||||
buy_rsi = IntParameter(20, 40, default=30, space="buy")
|
buy_rsi = IntParameter(20, 40, default=30, space="buy")
|
||||||
buy_adx_enabled = BooleanParameter(default=True, space="buy")
|
buy_adx_enabled = CategoricalParameter([True, False], default=True, space="buy")
|
||||||
buy_rsi_enabled = CategoricalParameter([True, False], default=False, space="buy")
|
buy_rsi_enabled = CategoricalParameter([True, False], default=False, space="buy")
|
||||||
buy_trigger = CategoricalParameter(["bb_lower", "macd_cross_signal"], default="bb_lower", space="buy")
|
buy_trigger = CategoricalParameter(["bb_lower", "macd_cross_signal"], default="bb_lower", space="buy")
|
||||||
```
|
```
|
||||||
@ -286,12 +266,11 @@ The last one we call `trigger` and use it to decide which buy trigger we want to
|
|||||||
!!! Note "Parameter space assignment"
|
!!! Note "Parameter space assignment"
|
||||||
Parameters must either be assigned to a variable named `buy_*` or `sell_*` - or contain `space='buy'` | `space='sell'` to be assigned to a space correctly.
|
Parameters must either be assigned to a variable named `buy_*` or `sell_*` - or contain `space='buy'` | `space='sell'` to be assigned to a space correctly.
|
||||||
If no parameter is available for a space, you'll receive the error that no space was found when running hyperopt.
|
If no parameter is available for a space, you'll receive the error that no space was found when running hyperopt.
|
||||||
Parameters with unclear space (e.g. `adx_period = IntParameter(4, 24, default=14)` - no explicit nor implicit space) will not be detected and will therefore be ignored.
|
|
||||||
|
|
||||||
So let's write the buy strategy using these values:
|
So let's write the buy strategy using these values:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
conditions = []
|
conditions = []
|
||||||
# GUARDS AND TRENDS
|
# GUARDS AND TRENDS
|
||||||
if self.buy_adx_enabled.value:
|
if self.buy_adx_enabled.value:
|
||||||
@ -313,12 +292,12 @@ So let's write the buy strategy using these values:
|
|||||||
if conditions:
|
if conditions:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
reduce(lambda x, y: x & y, conditions),
|
reduce(lambda x, y: x & y, conditions),
|
||||||
'enter_long'] = 1
|
'buy'] = 1
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
Hyperopt will now call `populate_entry_trend()` many times (`epochs`) with different value combinations.
|
Hyperopt will now call `populate_buy_trend()` many times (`epochs`) with different value combinations.
|
||||||
It will use the given historical data and simulate buys based on the buy signals generated with the above function.
|
It will use the given historical data and simulate buys based on the buy signals generated with the above function.
|
||||||
Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured [loss function](#loss-functions)).
|
Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured [loss function](#loss-functions)).
|
||||||
|
|
||||||
@ -335,7 +314,6 @@ There are four parameter types each suited for different purposes.
|
|||||||
* `DecimalParameter` - defines a floating point parameter with a limited number of decimals (default 3). Should be preferred instead of `RealParameter` in most cases.
|
* `DecimalParameter` - defines a floating point parameter with a limited number of decimals (default 3). Should be preferred instead of `RealParameter` in most cases.
|
||||||
* `RealParameter` - defines a floating point parameter with upper and lower boundaries and no precision limit. Rarely used as it creates a space with a near infinite number of possibilities.
|
* `RealParameter` - defines a floating point parameter with upper and lower boundaries and no precision limit. Rarely used as it creates a space with a near infinite number of possibilities.
|
||||||
* `CategoricalParameter` - defines a parameter with a predetermined number of choices.
|
* `CategoricalParameter` - defines a parameter with a predetermined number of choices.
|
||||||
* `BooleanParameter` - Shorthand for `CategoricalParameter([True, False])` - great for "enable" parameters.
|
|
||||||
|
|
||||||
!!! Tip "Disabling parameter optimization"
|
!!! Tip "Disabling parameter optimization"
|
||||||
Each parameter takes two boolean parameters:
|
Each parameter takes two boolean parameters:
|
||||||
@ -346,10 +324,9 @@ There are four parameter types each suited for different purposes.
|
|||||||
!!! Warning
|
!!! Warning
|
||||||
Hyperoptable parameters cannot be used in `populate_indicators` - as hyperopt does not recalculate indicators for each epoch, so the starting value would be used in this case.
|
Hyperoptable parameters cannot be used in `populate_indicators` - as hyperopt does not recalculate indicators for each epoch, so the starting value would be used in this case.
|
||||||
|
|
||||||
## Optimizing an indicator parameter
|
### Optimizing an indicator parameter
|
||||||
|
|
||||||
Assuming you have a simple strategy in mind - a EMA cross strategy (2 Moving averages crossing) - and you'd like to find the ideal parameters for this strategy.
|
Assuming you have a simple strategy in mind - a EMA cross strategy (2 Moving averages crossing) - and you'd like to find the ideal parameters for this strategy.
|
||||||
By default, we assume a stoploss of 5% - and a take-profit (`minimal_roi`) of 10% - which means freqtrade will sell the trade once 10% profit has been reached.
|
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
@ -357,16 +334,13 @@ from functools import reduce
|
|||||||
|
|
||||||
import talib.abstract as ta
|
import talib.abstract as ta
|
||||||
|
|
||||||
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter,
|
from freqtrade.strategy import IStrategy
|
||||||
IStrategy, IntParameter)
|
from freqtrade.strategy import CategoricalParameter, DecimalParameter, IntParameter
|
||||||
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||||
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
class MyAwesomeStrategy(IStrategy):
|
||||||
stoploss = -0.05
|
stoploss = -0.05
|
||||||
timeframe = '15m'
|
timeframe = '15m'
|
||||||
minimal_roi = {
|
|
||||||
"0": 0.10
|
|
||||||
}
|
|
||||||
# Define the parameter spaces
|
# Define the parameter spaces
|
||||||
buy_ema_short = IntParameter(3, 50, default=5)
|
buy_ema_short = IntParameter(3, 50, default=5)
|
||||||
buy_ema_long = IntParameter(15, 200, default=50)
|
buy_ema_long = IntParameter(15, 200, default=50)
|
||||||
@ -385,7 +359,7 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
conditions = []
|
conditions = []
|
||||||
conditions.append(qtpylib.crossed_above(
|
conditions.append(qtpylib.crossed_above(
|
||||||
dataframe[f'ema_short_{self.buy_ema_short.value}'], dataframe[f'ema_long_{self.buy_ema_long.value}']
|
dataframe[f'ema_short_{self.buy_ema_short.value}'], dataframe[f'ema_long_{self.buy_ema_long.value}']
|
||||||
@ -397,10 +371,10 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
if conditions:
|
if conditions:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
reduce(lambda x, y: x & y, conditions),
|
reduce(lambda x, y: x & y, conditions),
|
||||||
'enter_long'] = 1
|
'buy'] = 1
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
conditions = []
|
conditions = []
|
||||||
conditions.append(qtpylib.crossed_above(
|
conditions.append(qtpylib.crossed_above(
|
||||||
dataframe[f'ema_long_{self.buy_ema_long.value}'], dataframe[f'ema_short_{self.buy_ema_short.value}']
|
dataframe[f'ema_long_{self.buy_ema_long.value}'], dataframe[f'ema_short_{self.buy_ema_short.value}']
|
||||||
@ -412,7 +386,7 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
if conditions:
|
if conditions:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
reduce(lambda x, y: x & y, conditions),
|
reduce(lambda x, y: x & y, conditions),
|
||||||
'exit_long'] = 1
|
'sell'] = 1
|
||||||
return dataframe
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -422,153 +396,17 @@ Using `self.buy_ema_short.range` will return a range object containing all entri
|
|||||||
In this case (`IntParameter(3, 50, default=5)`), the loop would run for all numbers between 3 and 50 (`[3, 4, 5, ... 49, 50]`).
|
In this case (`IntParameter(3, 50, default=5)`), the loop would run for all numbers between 3 and 50 (`[3, 4, 5, ... 49, 50]`).
|
||||||
By using this in a loop, hyperopt will generate 48 new columns (`['buy_ema_3', 'buy_ema_4', ... , 'buy_ema_50']`).
|
By using this in a loop, hyperopt will generate 48 new columns (`['buy_ema_3', 'buy_ema_4', ... , 'buy_ema_50']`).
|
||||||
|
|
||||||
Hyperopt itself will then use the selected value to create the buy and sell signals.
|
Hyperopt itself will then use the selected value to create the buy and sell signals
|
||||||
|
|
||||||
While this strategy is most likely too simple to provide consistent profit, it should serve as an example how optimize indicator parameters.
|
While this strategy is most likely too simple to provide consistent profit, it should serve as an example how optimize indicator parameters.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
`self.buy_ema_short.range` will act differently between hyperopt and other modes. For hyperopt, the above example may generate 48 new columns, however for all other modes (backtesting, dry/live), it will only generate the column for the selected value. You should therefore avoid using the resulting column with explicit values (values other than `self.buy_ema_short.value`).
|
`self.buy_ema_short.range` will act differently between hyperopt and other modes. For hyperopt, the above example may generate 48 new columns, however for all other modes (backtesting, dry/live), it will only generate the column for the selected value. You should therefore avoid using the resulting column with explicit values (values other than `self.buy_ema_short.value`).
|
||||||
|
|
||||||
!!! Note
|
|
||||||
`range` property may also be used with `DecimalParameter` and `CategoricalParameter`. `RealParameter` does not provide this property due to infinite search space.
|
|
||||||
|
|
||||||
??? Hint "Performance tip"
|
??? Hint "Performance tip"
|
||||||
During normal hyperopting, indicators are calculated once and supplied to each epoch, linearly increasing RAM usage as a factor of increasing cores. As this also has performance implications, hyperopt provides `--analyze-per-epoch` which will move the execution of `populate_indicators()` to the epoch process, calculating a single value per parameter per epoch instead of using the `.range` functionality. In this case, `.range` functionality will only return the actually used value. This will reduce RAM usage, but increase CPU usage. However, your hyperopting run will be less likely to fail due to Out Of Memory (OOM) issues.
|
By doing the calculation of all possible indicators in `populate_indicators()`, the calculation of the indicator happens only once for every parameter.
|
||||||
|
While this may slow down the hyperopt startup speed, the overall performance will increase as the Hyperopt execution itself may pick the same value for multiple epochs (changing other values).
|
||||||
In either case, you should try to use space ranges as small as possible this will improve CPU/RAM usage in both scenarios.
|
You should however try to use space ranges as small as possible. Every new column will require more memory, and every possibility hyperopt can try will increase the search space.
|
||||||
|
|
||||||
|
|
||||||
## Optimizing protections
|
|
||||||
|
|
||||||
Freqtrade can also optimize protections. How you optimize protections is up to you, and the following should be considered as example only.
|
|
||||||
|
|
||||||
The strategy will simply need to define the "protections" entry as property returning a list of protection configurations.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from pandas import DataFrame
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
import talib.abstract as ta
|
|
||||||
|
|
||||||
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter,
|
|
||||||
IStrategy, IntParameter)
|
|
||||||
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
|
||||||
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
stoploss = -0.05
|
|
||||||
timeframe = '15m'
|
|
||||||
# Define the parameter spaces
|
|
||||||
cooldown_lookback = IntParameter(2, 48, default=5, space="protection", optimize=True)
|
|
||||||
stop_duration = IntParameter(12, 200, default=5, space="protection", optimize=True)
|
|
||||||
use_stop_protection = BooleanParameter(default=True, space="protection", optimize=True)
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
|
||||||
def protections(self):
|
|
||||||
prot = []
|
|
||||||
|
|
||||||
prot.append({
|
|
||||||
"method": "CooldownPeriod",
|
|
||||||
"stop_duration_candles": self.cooldown_lookback.value
|
|
||||||
})
|
|
||||||
if self.use_stop_protection.value:
|
|
||||||
prot.append({
|
|
||||||
"method": "StoplossGuard",
|
|
||||||
"lookback_period_candles": 24 * 3,
|
|
||||||
"trade_limit": 4,
|
|
||||||
"stop_duration_candles": self.stop_duration.value,
|
|
||||||
"only_per_pair": False
|
|
||||||
})
|
|
||||||
|
|
||||||
return prot
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
# ...
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
You can then run hyperopt as follows:
|
|
||||||
`freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy MyAwesomeStrategy --spaces protection`
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
The protection space is not part of the default space, and is only available with the Parameters Hyperopt interface, not with the legacy hyperopt interface (which required separate hyperopt files).
|
|
||||||
Freqtrade will also automatically change the "--enable-protections" flag if the protection space is selected.
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
If protections are defined as property, entries from the configuration will be ignored.
|
|
||||||
It is therefore recommended to not define protections in the configuration.
|
|
||||||
|
|
||||||
### Migrating from previous property setups
|
|
||||||
|
|
||||||
A migration from a previous setup is pretty simple, and can be accomplished by converting the protections entry to a property.
|
|
||||||
In simple terms, the following configuration will be converted to the below.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
protections = [
|
|
||||||
{
|
|
||||||
"method": "CooldownPeriod",
|
|
||||||
"stop_duration_candles": 4
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
Result
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
@property
|
|
||||||
def protections(self):
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"method": "CooldownPeriod",
|
|
||||||
"stop_duration_candles": 4
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
You will then obviously also change potential interesting entries to parameters to allow hyper-optimization.
|
|
||||||
|
|
||||||
### Optimizing `max_entry_position_adjustment`
|
|
||||||
|
|
||||||
While `max_entry_position_adjustment` is not a separate space, it can still be used in hyperopt by using the property approach shown above.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from pandas import DataFrame
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
import talib.abstract as ta
|
|
||||||
|
|
||||||
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter,
|
|
||||||
IStrategy, IntParameter)
|
|
||||||
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
|
||||||
|
|
||||||
class MyAwesomeStrategy(IStrategy):
|
|
||||||
stoploss = -0.05
|
|
||||||
timeframe = '15m'
|
|
||||||
|
|
||||||
# Define the parameter spaces
|
|
||||||
max_epa = CategoricalParameter([-1, 0, 1, 3, 5, 10], default=1, space="buy", optimize=True)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_entry_position_adjustment(self):
|
|
||||||
return self.max_epa.value
|
|
||||||
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
# ...
|
|
||||||
```
|
|
||||||
|
|
||||||
??? Tip "Using `IntParameter`"
|
|
||||||
You can also use the `IntParameter` for this optimization, but you must explicitly return an integer:
|
|
||||||
``` python
|
|
||||||
max_epa = IntParameter(-1, 10, default=1, space="buy", optimize=True)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_entry_position_adjustment(self):
|
|
||||||
return int(self.max_epa.value)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Loss-functions
|
## Loss-functions
|
||||||
|
|
||||||
@ -579,16 +417,12 @@ This class should be in its own file within the `user_data/hyperopts/` directory
|
|||||||
|
|
||||||
Currently, the following loss functions are builtin:
|
Currently, the following loss functions are builtin:
|
||||||
|
|
||||||
* `ShortTradeDurHyperOptLoss` - (default legacy Freqtrade hyperoptimization loss function) - Mostly for short trade duration and avoiding losses.
|
* `ShortTradeDurHyperOptLoss` (default legacy Freqtrade hyperoptimization loss function) - Mostly for short trade duration and avoiding losses.
|
||||||
* `OnlyProfitHyperOptLoss` - takes only amount of profit into consideration.
|
* `OnlyProfitHyperOptLoss` (which takes only amount of profit into consideration)
|
||||||
* `SharpeHyperOptLoss` - optimizes Sharpe Ratio calculated on trade returns relative to standard deviation.
|
* `SharpeHyperOptLoss` (optimizes Sharpe Ratio calculated on trade returns relative to standard deviation)
|
||||||
* `SharpeHyperOptLossDaily` - optimizes Sharpe Ratio calculated on **daily** trade returns relative to standard deviation.
|
* `SharpeHyperOptLossDaily` (optimizes Sharpe Ratio calculated on **daily** trade returns relative to standard deviation)
|
||||||
* `SortinoHyperOptLoss` - optimizes Sortino Ratio calculated on trade returns relative to **downside** standard deviation.
|
* `SortinoHyperOptLoss` (optimizes Sortino Ratio calculated on trade returns relative to **downside** standard deviation)
|
||||||
* `SortinoHyperOptLossDaily` - optimizes Sortino Ratio calculated on **daily** trade returns relative to **downside** standard deviation.
|
* `SortinoHyperOptLossDaily` (optimizes Sortino Ratio calculated on **daily** trade returns relative to **downside** standard deviation)
|
||||||
* `MaxDrawDownHyperOptLoss` - Optimizes Maximum absolute drawdown.
|
|
||||||
* `MaxDrawDownRelativeHyperOptLoss` - Optimizes both maximum absolute drawdown while also adjusting for maximum relative drawdown.
|
|
||||||
* `CalmarHyperOptLoss` - Optimizes Calmar Ratio calculated on trade returns relative to max drawdown.
|
|
||||||
* `ProfitDrawDownHyperOptLoss` - Optimizes by max Profit & min Drawdown objective. `DRAWDOWN_MULT` variable within the hyperoptloss file can be adjusted to be stricter or more flexible on drawdown purposes.
|
|
||||||
|
|
||||||
Creation of a custom loss function is covered in the [Advanced Hyperopt](advanced-hyperopt.md) part of the documentation.
|
Creation of a custom loss function is covered in the [Advanced Hyperopt](advanced-hyperopt.md) part of the documentation.
|
||||||
|
|
||||||
@ -626,7 +460,7 @@ For example, to use one month of data, pass `--timerange 20210101-20210201` (fro
|
|||||||
Full command:
|
Full command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
freqtrade hyperopt --strategy <strategyname> --timerange 20210101-20210201
|
freqtrade hyperopt --hyperopt <hyperoptname> --strategy <strategyname> --timerange 20210101-20210201
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running Hyperopt with Smaller Search Space
|
### Running Hyperopt with Smaller Search Space
|
||||||
@ -644,9 +478,7 @@ Legal values are:
|
|||||||
* `roi`: just optimize the minimal profit table for your strategy
|
* `roi`: just optimize the minimal profit table for your strategy
|
||||||
* `stoploss`: search for the best stoploss value
|
* `stoploss`: search for the best stoploss value
|
||||||
* `trailing`: search for the best trailing stop values
|
* `trailing`: search for the best trailing stop values
|
||||||
* `trades`: search for the best max open trades values
|
* `default`: `all` except `trailing`
|
||||||
* `protection`: search for the best protection parameters (read the [protections section](#optimizing-protections) on how to properly define these)
|
|
||||||
* `default`: `all` except `trailing` and `protection`
|
|
||||||
* space-separated list of any of the above values for example `--spaces roi stoploss`
|
* space-separated list of any of the above values for example `--spaces roi stoploss`
|
||||||
|
|
||||||
The default Hyperopt Search Space, used when no `--space` command line option is specified, does not include the `trailing` hyperspace. We recommend you to run optimization for the `trailing` hyperspace separately, when the best parameters for other hyperspaces were found, validated and pasted into your custom strategy.
|
The default Hyperopt Search Space, used when no `--space` command line option is specified, does not include the `trailing` hyperspace. We recommend you to run optimization for the `trailing` hyperspace separately, when the best parameters for other hyperspaces were found, validated and pasted into your custom strategy.
|
||||||
@ -677,13 +509,7 @@ You should understand this result like:
|
|||||||
* You should not use ADX because `'buy_adx_enabled': False`.
|
* You should not use ADX because `'buy_adx_enabled': False`.
|
||||||
* You should **consider** using the RSI indicator (`'buy_rsi_enabled': True`) and the best value is `29.0` (`'buy_rsi': 29.0`)
|
* You should **consider** using the RSI indicator (`'buy_rsi_enabled': True`) and the best value is `29.0` (`'buy_rsi': 29.0`)
|
||||||
|
|
||||||
### Automatic parameter application to the strategy
|
Your strategy class can immediately take advantage of these results. Simply copy hyperopt results block and paste them at class level, replacing old parameters (if any). New parameters will automatically be loaded next time strategy is executed.
|
||||||
|
|
||||||
When using Hyperoptable parameters, the result of your hyperopt-run will be written to a json file next to your strategy (so for `MyAwesomeStrategy.py`, the file would be `MyAwesomeStrategy.json`).
|
|
||||||
This file is also updated when using the `hyperopt-show` sub-command, unless `--disable-param-export` is provided to either of the 2 commands.
|
|
||||||
|
|
||||||
|
|
||||||
Your strategy class can also contain these results explicitly. Simply copy hyperopt results block and paste them at class level, replacing old parameters (if any). New parameters will automatically be loaded next time strategy is executed.
|
|
||||||
|
|
||||||
Transferring your whole hyperopt result to your strategy would then look like:
|
Transferring your whole hyperopt result to your strategy would then look like:
|
||||||
|
|
||||||
@ -699,10 +525,6 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Values in the configuration file will overwrite Parameter-file level parameters - and both will overwrite parameters within the strategy.
|
|
||||||
The prevalence is therefore: config > parameter file > strategy `*_params` > parameter default
|
|
||||||
|
|
||||||
### Understand Hyperopt ROI results
|
### Understand Hyperopt ROI results
|
||||||
|
|
||||||
If you are optimizing ROI (i.e. if optimization search-space contains 'all', 'default' or 'roi'), your result will look as follows and include a ROI table:
|
If you are optimizing ROI (i.e. if optimization search-space contains 'all', 'default' or 'roi'), your result will look as follows and include a ROI table:
|
||||||
@ -749,11 +571,11 @@ If you are optimizing ROI, Freqtrade creates the 'roi' optimization hyperspace f
|
|||||||
|
|
||||||
These ranges should be sufficient in most cases. The minutes in the steps (ROI dict keys) are scaled linearly depending on the timeframe used. The ROI values in the steps (ROI dict values) are scaled logarithmically depending on the timeframe used.
|
These ranges should be sufficient in most cases. The minutes in the steps (ROI dict keys) are scaled linearly depending on the timeframe used. The ROI values in the steps (ROI dict values) are scaled logarithmically depending on the timeframe used.
|
||||||
|
|
||||||
If you have the `generate_roi_table()` and `roi_space()` methods in your custom hyperopt, remove them in order to utilize these adaptive ROI tables and the ROI hyperoptimization space generated by Freqtrade by default.
|
If you have the `generate_roi_table()` and `roi_space()` methods in your custom hyperopt file, remove them in order to utilize these adaptive ROI tables and the ROI hyperoptimization space generated by Freqtrade by default.
|
||||||
|
|
||||||
Override the `roi_space()` method if you need components of the ROI tables to vary in other ranges. Override the `generate_roi_table()` and `roi_space()` methods and implement your own custom approach for generation of the ROI tables during hyperoptimization if you need a different structure of the ROI tables or other amount of rows (steps).
|
Override the `roi_space()` method if you need components of the ROI tables to vary in other ranges. Override the `generate_roi_table()` and `roi_space()` methods and implement your own custom approach for generation of the ROI tables during hyperoptimization if you need a different structure of the ROI tables or other amount of rows (steps).
|
||||||
|
|
||||||
A sample for these methods can be found in the [overriding pre-defined spaces section](advanced-hyperopt.md#overriding-pre-defined-spaces).
|
A sample for these methods can be found in [sample_hyperopt_advanced.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py).
|
||||||
|
|
||||||
!!! Note "Reduced search space"
|
!!! Note "Reduced search space"
|
||||||
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#pverriding-pre-defined-spaces) to change this to your needs.
|
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#pverriding-pre-defined-spaces) to change this to your needs.
|
||||||
@ -795,7 +617,7 @@ If you are optimizing stoploss values, Freqtrade creates the 'stoploss' optimiza
|
|||||||
|
|
||||||
If you have the `stoploss_space()` method in your custom hyperopt file, remove it in order to utilize Stoploss hyperoptimization space generated by Freqtrade by default.
|
If you have the `stoploss_space()` method in your custom hyperopt file, remove it in order to utilize Stoploss hyperoptimization space generated by Freqtrade by default.
|
||||||
|
|
||||||
Override the `stoploss_space()` method and define the desired range in it if you need stoploss values to vary in other range during hyperoptimization. A sample for this method can be found in the [overriding pre-defined spaces section](advanced-hyperopt.md#overriding-pre-defined-spaces).
|
Override the `stoploss_space()` method and define the desired range in it if you need stoploss values to vary in other range during hyperoptimization. A sample for this method can be found in [user_data/hyperopts/sample_hyperopt_advanced.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py).
|
||||||
|
|
||||||
!!! Note "Reduced search space"
|
!!! Note "Reduced search space"
|
||||||
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#pverriding-pre-defined-spaces) to change this to your needs.
|
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#pverriding-pre-defined-spaces) to change this to your needs.
|
||||||
@ -833,10 +655,10 @@ As stated in the comment, you can also use it as the values of the corresponding
|
|||||||
|
|
||||||
If you are optimizing trailing stop values, Freqtrade creates the 'trailing' optimization hyperspace for you. By default, the `trailing_stop` parameter is always set to True in that hyperspace, the value of the `trailing_only_offset_is_reached` vary between True and False, the values of the `trailing_stop_positive` and `trailing_stop_positive_offset` parameters vary in the ranges 0.02...0.35 and 0.01...0.1 correspondingly, which is sufficient in most cases.
|
If you are optimizing trailing stop values, Freqtrade creates the 'trailing' optimization hyperspace for you. By default, the `trailing_stop` parameter is always set to True in that hyperspace, the value of the `trailing_only_offset_is_reached` vary between True and False, the values of the `trailing_stop_positive` and `trailing_stop_positive_offset` parameters vary in the ranges 0.02...0.35 and 0.01...0.1 correspondingly, which is sufficient in most cases.
|
||||||
|
|
||||||
Override the `trailing_space()` method and define the desired range in it if you need values of the trailing stop parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in the [overriding pre-defined spaces section](advanced-hyperopt.md#overriding-pre-defined-spaces).
|
Override the `trailing_space()` method and define the desired range in it if you need values of the trailing stop parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in [user_data/hyperopts/sample_hyperopt_advanced.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py).
|
||||||
|
|
||||||
!!! Note "Reduced search space"
|
!!! Note "Reduced search space"
|
||||||
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#overriding-pre-defined-spaces) to change this to your needs.
|
To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however [overriding pre-defined spaces](advanced-hyperopt.md#pverriding-pre-defined-spaces) to change this to your needs.
|
||||||
|
|
||||||
### Reproducible results
|
### Reproducible results
|
||||||
|
|
||||||
@ -883,29 +705,10 @@ You can also enable position stacking in the configuration file by explicitly se
|
|||||||
As hyperopt consumes a lot of memory (the complete data needs to be in memory once per parallel backtesting process), it's likely that you run into "out of memory" errors.
|
As hyperopt consumes a lot of memory (the complete data needs to be in memory once per parallel backtesting process), it's likely that you run into "out of memory" errors.
|
||||||
To combat these, you have multiple options:
|
To combat these, you have multiple options:
|
||||||
|
|
||||||
* Reduce the amount of pairs.
|
* reduce the amount of pairs
|
||||||
* Reduce the timerange used (`--timerange <timerange>`).
|
* reduce the timerange used (`--timerange <timerange>`)
|
||||||
* Avoid using `--timeframe-detail` (this loads a lot of additional data into memory).
|
* reduce the number of parallel processes (`-j <n>`)
|
||||||
* Reduce the number of parallel processes (`-j <n>`).
|
* Increase the memory of your machine
|
||||||
* Increase the memory of your machine.
|
|
||||||
* Use `--analyze-per-epoch` if you're using a lot of parameters with `.range` functionality.
|
|
||||||
|
|
||||||
|
|
||||||
## The objective has been evaluated at this point before.
|
|
||||||
|
|
||||||
If you see `The objective has been evaluated at this point before.` - then this is a sign that your space has been exhausted, or is close to that.
|
|
||||||
Basically all points in your space have been hit (or a local minima has been hit) - and hyperopt does no longer find points in the multi-dimensional space it did not try yet.
|
|
||||||
Freqtrade tries to counter the "local minima" problem by using new, randomized points in this case.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
``` python
|
|
||||||
buy_ema_short = IntParameter(5, 20, default=10, space="buy", optimize=True)
|
|
||||||
# This is the only parameter in the buy space
|
|
||||||
```
|
|
||||||
|
|
||||||
The `buy_ema_short` space has 15 possible values (`5, 6, ... 19, 20`). If you now run hyperopt for the buy space, hyperopt will only have 15 values to try before running out of options.
|
|
||||||
Your epochs should therefore be aligned to the possible values - or you should be ready to interrupt a run if you norice a lot of `The objective has been evaluated at this point before.` warnings.
|
|
||||||
|
|
||||||
## Show details of Hyperopt results
|
## Show details of Hyperopt results
|
||||||
|
|
||||||
@ -915,8 +718,8 @@ After you run Hyperopt for the desired amount of epochs, you can later list all
|
|||||||
|
|
||||||
Once the optimized strategy has been implemented into your strategy, you should backtest this strategy to make sure everything is working as expected.
|
Once the optimized strategy has been implemented into your strategy, you should backtest this strategy to make sure everything is working as expected.
|
||||||
|
|
||||||
To achieve same the results (number of trades, their durations, profit, etc.) as during Hyperopt, please use the same configuration and parameters (timerange, timeframe, ...) used for hyperopt `--dmmp`/`--disable-max-market-positions` and `--eps`/`--enable-position-stacking` for Backtesting.
|
To achieve same results (number of trades, their durations, profit, etc.) than during Hyperopt, please use same configuration and parameters (timerange, timeframe, ...) used for hyperopt `--dmmp`/`--disable-max-market-positions` and `--eps`/`--enable-position-stacking` for Backtesting.
|
||||||
|
|
||||||
Should results not match, please double-check to make sure you transferred all conditions correctly.
|
Should results don't match, please double-check to make sure you transferred all conditions correctly.
|
||||||
Pay special care to the stoploss, max_open_trades and trailing stoploss parameters, as these are often set in configuration files, which override changes to the strategy.
|
Pay special care to the stoploss (and trailing stoploss) parameters, as these are often set in configuration files, which override changes to the strategy.
|
||||||
You should also carefully review the log of your backtest to ensure that there were no parameters inadvertently set by the configuration (like `stoploss`, `max_open_trades` or `trailing_stop`).
|
You should also carefully review the log of your backtest to ensure that there were no parameters inadvertently set by the configuration (like `stoploss` or `trailing_stop`).
|
||||||
|
@ -22,10 +22,7 @@ You may also use something like `.*DOWN/BTC` or `.*UP/BTC` to exclude leveraged
|
|||||||
|
|
||||||
* [`StaticPairList`](#static-pair-list) (default, if not configured differently)
|
* [`StaticPairList`](#static-pair-list) (default, if not configured differently)
|
||||||
* [`VolumePairList`](#volume-pair-list)
|
* [`VolumePairList`](#volume-pair-list)
|
||||||
* [`ProducerPairList`](#producerpairlist)
|
|
||||||
* [`RemotePairList`](#remotepairlist)
|
|
||||||
* [`AgeFilter`](#agefilter)
|
* [`AgeFilter`](#agefilter)
|
||||||
* [`OffsetFilter`](#offsetfilter)
|
|
||||||
* [`PerformanceFilter`](#performancefilter)
|
* [`PerformanceFilter`](#performancefilter)
|
||||||
* [`PrecisionFilter`](#precisionfilter)
|
* [`PrecisionFilter`](#precisionfilter)
|
||||||
* [`PriceFilter`](#pricefilter)
|
* [`PriceFilter`](#pricefilter)
|
||||||
@ -46,7 +43,7 @@ It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklis
|
|||||||
```json
|
```json
|
||||||
"pairlists": [
|
"pairlists": [
|
||||||
{"method": "StaticPairList"}
|
{"method": "StaticPairList"}
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, only currently enabled pairs are allowed.
|
By default, only currently enabled pairs are allowed.
|
||||||
@ -54,204 +51,43 @@ To skip pair validation against active markets, set `"allow_inactive": true` wit
|
|||||||
This can be useful for backtesting expired pairs (like quarterly spot-markets).
|
This can be useful for backtesting expired pairs (like quarterly spot-markets).
|
||||||
This option must be configured along with `exchange.skip_pair_validation` in the exchange configuration.
|
This option must be configured along with `exchange.skip_pair_validation` in the exchange configuration.
|
||||||
|
|
||||||
When used in a "follow-up" position (e.g. after VolumePairlist), all pairs in `'pair_whitelist'` will be added to the end of the pairlist.
|
|
||||||
|
|
||||||
#### Volume Pair List
|
#### Volume Pair List
|
||||||
|
|
||||||
`VolumePairList` employs sorting/filtering of pairs by their trading volume. It selects `number_assets` top pairs with sorting based on the `sort_key` (which can only be `quoteVolume`).
|
`VolumePairList` employs sorting/filtering of pairs by their trading volume. It selects `number_assets` top pairs with sorting based on the `sort_key` (which can only be `quoteVolume`).
|
||||||
|
|
||||||
When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), `VolumePairList` considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.
|
When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), `VolumePairList` considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.
|
||||||
|
|
||||||
When used in the leading position of the chain of Pairlist Handlers, the `pair_whitelist` configuration setting is ignored. Instead, `VolumePairList` selects the top assets from all available markets with matching stake-currency on the exchange.
|
When used on the leading position of the chain of Pairlist Handlers, it does not consider `pair_whitelist` configuration setting, but selects the top assets from all available markets (with matching stake-currency) on the exchange.
|
||||||
|
|
||||||
The `refresh_period` setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes).
|
The `refresh_period` setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes).
|
||||||
The pairlist cache (`refresh_period`) on `VolumePairList` is only applicable to generating pairlists.
|
The pairlist cache (`refresh_period`) on `VolumePairList` is only applicable to generating pairlists.
|
||||||
Filtering instances (not the first position in the list) will not apply any cache and will always use up-to-date data.
|
Filtering instances (not the first position in the list) will not apply any cache and will always use up-to-date data.
|
||||||
|
|
||||||
`VolumePairList` is per default based on the ticker data from exchange, as reported by the ccxt library:
|
`VolumePairList` is based on the ticker data from exchange, as reported by the ccxt library:
|
||||||
|
|
||||||
* The `quoteVolume` is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
|
* The `quoteVolume` is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"pairlists": [
|
"pairlists": [{
|
||||||
{
|
|
||||||
"method": "VolumePairList",
|
"method": "VolumePairList",
|
||||||
"number_assets": 20,
|
"number_assets": 20,
|
||||||
"sort_key": "quoteVolume",
|
"sort_key": "quoteVolume",
|
||||||
"min_value": 0,
|
|
||||||
"refresh_period": 1800
|
"refresh_period": 1800
|
||||||
}
|
}],
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
You can define a minimum volume with `min_value` - which will filter out pairs with a volume lower than the specified value in the specified timerange.
|
|
||||||
|
|
||||||
##### VolumePairList Advanced mode
|
|
||||||
|
|
||||||
`VolumePairList` can also operate in an advanced mode to build volume over a given timerange of specified candle size. It utilizes exchange historical candle data, builds a typical price (calculated by (open+high+low)/3) and multiplies the typical price with every candle's volume. The sum is the `quoteVolume` over the given range. This allows different scenarios, for a more smoothened volume, when using longer ranges with larger candle sizes, or the opposite when using a short range with small candles.
|
|
||||||
|
|
||||||
For convenience `lookback_days` can be specified, which will imply that 1d candles will be used for the lookback. In the example below the pairlist would be created based on the last 7 days:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "VolumePairList",
|
|
||||||
"number_assets": 20,
|
|
||||||
"sort_key": "quoteVolume",
|
|
||||||
"min_value": 0,
|
|
||||||
"refresh_period": 86400,
|
|
||||||
"lookback_days": 7
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning "Range look back and refresh period"
|
|
||||||
When used in conjunction with `lookback_days` and `lookback_timeframe` the `refresh_period` can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.
|
|
||||||
|
|
||||||
!!! Warning "Performance implications when using lookback range"
|
|
||||||
If used in first position in combination with lookback, the computation of the range based volume can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with `VolumeFilter` to narrow the pairlist down for further range volume calculation.
|
|
||||||
|
|
||||||
??? Tip "Unsupported exchanges (Bittrex, Gemini)"
|
|
||||||
On some exchanges (like Bittrex and Gemini), regular VolumePairList does not work as the api does not natively provide 24h volume. This can be worked around by using candle data to build the volume.
|
|
||||||
To roughly simulate 24h volume, you can use the following configuration.
|
|
||||||
Please note that These pairlists will only refresh once per day.
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "VolumePairList",
|
|
||||||
"number_assets": 20,
|
|
||||||
"sort_key": "quoteVolume",
|
|
||||||
"min_value": 0,
|
|
||||||
"refresh_period": 86400,
|
|
||||||
"lookback_days": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
More sophisticated approach can be used, by using `lookback_timeframe` for candle size and `lookback_period` which specifies the amount of candles. This example will build the volume pairs based on a rolling period of 3 days of 1h candles:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "VolumePairList",
|
|
||||||
"number_assets": 20,
|
|
||||||
"sort_key": "quoteVolume",
|
|
||||||
"min_value": 0,
|
|
||||||
"refresh_period": 3600,
|
|
||||||
"lookback_timeframe": "1h",
|
|
||||||
"lookback_period": 72
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
`VolumePairList` does not support backtesting mode.
|
`VolumePairList` does not support backtesting mode.
|
||||||
|
|
||||||
#### ProducerPairList
|
|
||||||
|
|
||||||
With `ProducerPairList`, you can reuse the pairlist from a [Producer](producer-consumer.md) without explicitly defining the pairlist on each consumer.
|
|
||||||
|
|
||||||
[Consumer mode](producer-consumer.md) is required for this pairlist to work.
|
|
||||||
|
|
||||||
The pairlist will perform a check on active pairs against the current exchange configuration to avoid attempting to trade on invalid markets.
|
|
||||||
|
|
||||||
You can limit the length of the pairlist with the optional parameter `number_assets`. Using `"number_assets"=0` or omitting this key will result in the reuse of all producer pairs valid for the current setup.
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "ProducerPairList",
|
|
||||||
"number_assets": 5,
|
|
||||||
"producer_name": "default",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
!!! Tip "Combining pairlists"
|
|
||||||
This pairlist can be combined with all other pairlists and filters for further pairlist reduction, and can also act as an "additional" pairlist, on top of already defined pairs.
|
|
||||||
`ProducerPairList` can also be used multiple times in sequence, combining the pairs from multiple producers.
|
|
||||||
Obviously in complex such configurations, the Producer may not provide data for all pairs, so the strategy must be fit for this.
|
|
||||||
|
|
||||||
#### RemotePairList
|
|
||||||
|
|
||||||
It allows the user to fetch a pairlist from a remote server or a locally stored json file within the freqtrade directory, enabling dynamic updates and customization of the trading pairlist.
|
|
||||||
|
|
||||||
The RemotePairList is defined in the pairlists section of the configuration settings. It uses the following configuration options:
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
{
|
|
||||||
"method": "RemotePairList",
|
|
||||||
"pairlist_url": "https://example.com/pairlist",
|
|
||||||
"number_assets": 10,
|
|
||||||
"refresh_period": 1800,
|
|
||||||
"keep_pairlist_on_failure": true,
|
|
||||||
"read_timeout": 60,
|
|
||||||
"bearer_token": "my-bearer-token"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
The `pairlist_url` option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist.
|
|
||||||
|
|
||||||
The user is responsible for providing a server or local file that returns a JSON object with the following structure:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"pairs": ["XRP/USDT", "ETH/USDT", "LTC/USDT"],
|
|
||||||
"refresh_period": 1800,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `pairs` property should contain a list of strings with the trading pairs to be used by the bot. The `refresh_period` property is optional and specifies the number of seconds that the pairlist should be cached before being refreshed.
|
|
||||||
|
|
||||||
The optional `keep_pairlist_on_failure` specifies whether the previous received pairlist should be used if the remote server is not reachable or returns an error. The default value is true.
|
|
||||||
|
|
||||||
The optional `read_timeout` specifies the maximum amount of time (in seconds) to wait for a response from the remote source, The default value is 60.
|
|
||||||
|
|
||||||
The optional `bearer_token` will be included in the requests Authorization Header.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
In case of a server error the last received pairlist will be kept if `keep_pairlist_on_failure` is set to true, when set to false a empty pairlist is returned.
|
|
||||||
|
|
||||||
#### AgeFilter
|
#### AgeFilter
|
||||||
|
|
||||||
Removes pairs that have been listed on the exchange for less than `min_days_listed` days (defaults to `10`) or more than `max_days_listed` days (defaults `None` mean infinity).
|
Removes pairs that have been listed on the exchange for less than `min_days_listed` days (defaults to `10`).
|
||||||
|
|
||||||
When pairs are first listed on an exchange they can suffer huge price drops and volatility
|
When pairs are first listed on an exchange they can suffer huge price drops and volatility
|
||||||
in the first few days while the pair goes through its price-discovery period. Bots can often
|
in the first few days while the pair goes through its price-discovery period. Bots can often
|
||||||
be caught out buying before the pair has finished dropping in price.
|
be caught out buying before the pair has finished dropping in price.
|
||||||
|
|
||||||
This filter allows freqtrade to ignore pairs until they have been listed for at least `min_days_listed` days and listed before `max_days_listed`.
|
This filter allows freqtrade to ignore pairs until they have been listed for at least `min_days_listed` days.
|
||||||
|
|
||||||
#### OffsetFilter
|
|
||||||
|
|
||||||
Offsets an incoming pairlist by a given `offset` value.
|
|
||||||
|
|
||||||
As an example it can be used in conjunction with `VolumeFilter` to remove the top X volume pairs. Or to split a larger pairlist on two bot instances.
|
|
||||||
|
|
||||||
Example to remove the first 10 pairs from the pairlist, and takes the next 20 (taking items 10-30 of the initial list):
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
// ...
|
|
||||||
{
|
|
||||||
"method": "OffsetFilter",
|
|
||||||
"offset": 10,
|
|
||||||
"number_assets": 20
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
When `OffsetFilter` is used to split a larger pairlist among multiple bots in combination with `VolumeFilter`
|
|
||||||
it can not be guaranteed that pairs won't overlap due to slightly different refresh intervals for the
|
|
||||||
`VolumeFilter`.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
An offset larger than the total length of the incoming pairlist will result in an empty pairlist.
|
|
||||||
|
|
||||||
#### PerformanceFilter
|
#### PerformanceFilter
|
||||||
|
|
||||||
@ -263,36 +99,13 @@ Sorts pairs by past trade performance, as follows:
|
|||||||
|
|
||||||
Trade count is used as a tie breaker.
|
Trade count is used as a tie breaker.
|
||||||
|
|
||||||
You can use the `minutes` parameter to only consider performance of the past X minutes (rolling window).
|
!!! Note
|
||||||
Not defining this parameter (or setting it to 0) will use all-time performance.
|
|
||||||
|
|
||||||
The optional `min_profit` (as ratio -> a setting of `0.01` corresponds to 1%) parameter defines the minimum profit a pair must have to be considered.
|
|
||||||
Pairs below this level will be filtered out.
|
|
||||||
Using this parameter without `minutes` is highly discouraged, as it can lead to an empty pairlist without a way to recover.
|
|
||||||
|
|
||||||
```json
|
|
||||||
"pairlists": [
|
|
||||||
// ...
|
|
||||||
{
|
|
||||||
"method": "PerformanceFilter",
|
|
||||||
"minutes": 1440, // rolling 24h
|
|
||||||
"min_profit": 0.01 // minimal profit 1%
|
|
||||||
}
|
|
||||||
],
|
|
||||||
```
|
|
||||||
|
|
||||||
As this Filter uses past performance of the bot, it'll have some startup-period - and should only be used after the bot has a few 100 trades in the database.
|
|
||||||
|
|
||||||
!!! Warning "Backtesting"
|
|
||||||
`PerformanceFilter` does not support backtesting mode.
|
`PerformanceFilter` does not support backtesting mode.
|
||||||
|
|
||||||
#### PrecisionFilter
|
#### PrecisionFilter
|
||||||
|
|
||||||
Filters low-value coins which would not allow setting stoplosses.
|
Filters low-value coins which would not allow setting stoplosses.
|
||||||
|
|
||||||
!!! Warning "Backtesting"
|
|
||||||
`PrecisionFilter` does not support backtesting mode using multiple strategies.
|
|
||||||
|
|
||||||
#### PriceFilter
|
#### PriceFilter
|
||||||
|
|
||||||
The `PriceFilter` allows filtering of pairs by price. Currently the following price filters are supported:
|
The `PriceFilter` allows filtering of pairs by price. Currently the following price filters are supported:
|
||||||
@ -311,12 +124,12 @@ This option is disabled by default, and will only apply if set to > 0.
|
|||||||
The `max_value` setting removes pairs where the minimum value change is above a specified value.
|
The `max_value` setting removes pairs where the minimum value change is above a specified value.
|
||||||
This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20\$) as the coin has risen sharply since the last limit adaption.
|
This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20\$) as the coin has risen sharply since the last limit adaption.
|
||||||
As a result of the above, you can only buy for 20\$, or 40\$ - but not for 25\$.
|
As a result of the above, you can only buy for 20\$, or 40\$ - but not for 25\$.
|
||||||
On exchanges that deduct fees from the receiving currency (e.g. binance) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.
|
On exchanges that deduct fees from the receiving currency (e.g. FTX) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.
|
||||||
|
|
||||||
The `low_price_ratio` setting removes pairs where a raise of 1 price unit (pip) is above the `low_price_ratio` ratio.
|
The `low_price_ratio` setting removes pairs where a raise of 1 price unit (pip) is above the `low_price_ratio` ratio.
|
||||||
This option is disabled by default, and will only apply if set to > 0.
|
This option is disabled by default, and will only apply if set to > 0.
|
||||||
|
|
||||||
For `PriceFilter` at least one of its `min_price`, `max_price` or `low_price_ratio` settings must be applied.
|
For `PriceFiler` at least one of its `min_price`, `max_price` or `low_price_ratio` settings must be applied.
|
||||||
|
|
||||||
Calculation example:
|
Calculation example:
|
||||||
|
|
||||||
@ -329,20 +142,8 @@ Min price precision for SHITCOIN/BTC is 8 decimals. If its price is 0.00000011 -
|
|||||||
|
|
||||||
Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.
|
Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.
|
||||||
|
|
||||||
By default, ShuffleFilter will shuffle pairs once per candle.
|
|
||||||
To shuffle on every iteration, set `"shuffle_frequency"` to `"iteration"` instead of the default of `"candle"`.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
{
|
|
||||||
"method": "ShuffleFilter",
|
|
||||||
"shuffle_frequency": "candle",
|
|
||||||
"seed": 42
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Tip
|
!!! Tip
|
||||||
You may set the `seed` value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If `seed` is not set, the pairs are shuffled in the non-repeatable random order. ShuffleFilter will automatically detect runmodes and apply the `seed` only for backtesting modes - if a `seed` value is set.
|
You may set the `seed` value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If `seed` is not set, the pairs are shuffled in the non-repeatable random order.
|
||||||
|
|
||||||
#### SpreadFilter
|
#### SpreadFilter
|
||||||
|
|
||||||
@ -354,10 +155,10 @@ If `DOGE/BTC` maximum bid is 0.00000026 and minimum ask is 0.00000027, the ratio
|
|||||||
|
|
||||||
#### RangeStabilityFilter
|
#### RangeStabilityFilter
|
||||||
|
|
||||||
Removes pairs where the difference between lowest low and highest high over `lookback_days` days is below `min_rate_of_change` or above `max_rate_of_change`. Since this is a filter that requires additional data, the results are cached for `refresh_period`.
|
Removes pairs where the difference between lowest low and highest high over `lookback_days` days is below `min_rate_of_change`. Since this is a filter that requires additional data, the results are cached for `refresh_period`.
|
||||||
|
|
||||||
In the below example:
|
In the below example:
|
||||||
If the trading range over the last 10 days is <1% or >99%, remove the pair from the whitelist.
|
If the trading range over the last 10 days is <1%, remove the pair from the whitelist.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"pairlists": [
|
"pairlists": [
|
||||||
@ -365,7 +166,6 @@ If the trading range over the last 10 days is <1% or >99%, remove the pair from
|
|||||||
"method": "RangeStabilityFilter",
|
"method": "RangeStabilityFilter",
|
||||||
"lookback_days": 10,
|
"lookback_days": 10,
|
||||||
"min_rate_of_change": 0.01,
|
"min_rate_of_change": 0.01,
|
||||||
"max_rate_of_change": 0.99,
|
|
||||||
"refresh_period": 1440
|
"refresh_period": 1440
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -373,11 +173,10 @@ If the trading range over the last 10 days is <1% or >99%, remove the pair from
|
|||||||
|
|
||||||
!!! Tip
|
!!! Tip
|
||||||
This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit.
|
This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit.
|
||||||
Additionally, it can also be used to automatically remove pairs with extreme high/low variance over a given amount of time.
|
|
||||||
|
|
||||||
#### VolatilityFilter
|
#### VolatilityFilter
|
||||||
|
|
||||||
Volatility is the degree of historical variation of a pairs over time, it is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of [`volatility`](https://en.wikipedia.org/wiki/Volatility_(finance)).
|
Volatility is the degree of historical variation of a pairs over time, is is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of [`volatility`](https://en.wikipedia.org/wiki/Volatility_(finance)).
|
||||||
|
|
||||||
This filter removes pairs if the average volatility over a `lookback_days` days is below `min_volatility` or above `max_volatility`. Since this is a filter that requires additional data, the results are cached for `refresh_period`.
|
This filter removes pairs if the average volatility over a `lookback_days` days is below `min_volatility` or above `max_volatility`. Since this is a filter that requires additional data, the results are cached for `refresh_period`.
|
||||||
|
|
||||||
@ -431,5 +230,5 @@ The below example blacklists `BNB/BTC`, uses `VolumePairList` with `20` assets,
|
|||||||
"refresh_period": 86400
|
"refresh_period": 86400
|
||||||
},
|
},
|
||||||
{"method": "ShuffleFilter", "seed": 42}
|
{"method": "ShuffleFilter", "seed": 42}
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
## Prices used for orders
|
## Prices used for orders
|
||||||
|
|
||||||
Prices for regular orders can be controlled via the parameter structures `entry_pricing` for trade entries and `exit_pricing` for trade exits.
|
Prices for regular orders can be controlled via the parameter structures `bid_strategy` for buying and `ask_strategy` for selling.
|
||||||
Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.
|
Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
@ -9,11 +9,20 @@ Prices are always retrieved right before an order is placed, either by querying
|
|||||||
!!! Warning "Using market orders"
|
!!! Warning "Using market orders"
|
||||||
Please read the section [Market order pricing](#market-order-pricing) section when using market orders.
|
Please read the section [Market order pricing](#market-order-pricing) section when using market orders.
|
||||||
|
|
||||||
### Entry price
|
### Buy price
|
||||||
|
|
||||||
#### Enter price side
|
#### Check depth of market
|
||||||
|
|
||||||
The configuration setting `entry_pricing.price_side` defines the side of the orderbook the bot looks for when buying.
|
When check depth of market is enabled (`bid_strategy.check_depth_of_market.enabled=True`), the buy signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.
|
||||||
|
|
||||||
|
Orderbook `bid` (buy) side depth is then divided by the orderbook `ask` (sell) side depth and the resulting delta is compared to the value of the `bid_strategy.check_depth_of_market.bids_to_ask_delta` parameter. The buy order is only executed if the orderbook delta is greater than or equal to the configured delta value.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
A delta value below 1 means that `ask` (sell) orderbook side depth is greater than the depth of the `bid` (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).
|
||||||
|
|
||||||
|
#### Buy price side
|
||||||
|
|
||||||
|
The configuration setting `bid_strategy.price_side` defines the side of the spread the bot looks for when buying.
|
||||||
|
|
||||||
The following displays an orderbook.
|
The following displays an orderbook.
|
||||||
|
|
||||||
@ -29,53 +38,30 @@ The following displays an orderbook.
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
If `entry_pricing.price_side` is set to `"bid"`, then the bot will use 99 as entry price.
|
If `bid_strategy.price_side` is set to `"bid"`, then the bot will use 99 as buying price.
|
||||||
In line with that, if `entry_pricing.price_side` is set to `"ask"`, then the bot will use 101 as entry price.
|
In line with that, if `bid_strategy.price_side` is set to `"ask"`, then the bot will use 101 as buying price.
|
||||||
|
|
||||||
Depending on the order direction (_long_/_short_), this will lead to different results. Therefore we recommend to use `"same"` or `"other"` for this configuration instead.
|
Using `ask` price often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary.
|
||||||
This would result in the following pricing matrix:
|
|
||||||
|
|
||||||
| direction | Order | setting | price | crosses spread |
|
|
||||||
|------ |--------|-----|-----|-----|
|
|
||||||
| long | buy | ask | 101 | yes |
|
|
||||||
| long | buy | bid | 99 | no |
|
|
||||||
| long | buy | same | 99 | no |
|
|
||||||
| long | buy | other | 101 | yes |
|
|
||||||
| short | sell | ask | 101 | no |
|
|
||||||
| short | sell | bid | 99 | yes |
|
|
||||||
| short | sell | same | 101 | no |
|
|
||||||
| short | sell | other | 99 | yes |
|
|
||||||
|
|
||||||
Using the other side of the orderbook often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary.
|
|
||||||
Taker fees instead of maker fees will most likely apply even when using limit buy orders.
|
Taker fees instead of maker fees will most likely apply even when using limit buy orders.
|
||||||
Also, prices at the "other" side of the spread are higher than prices at the "bid" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).
|
Also, prices at the "ask" side of the spread are higher than prices at the "bid" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).
|
||||||
|
|
||||||
#### Entry price with Orderbook enabled
|
#### Buy price with Orderbook enabled
|
||||||
|
|
||||||
When entering a trade with the orderbook enabled (`entry_pricing.use_order_book=True`), Freqtrade fetches the `entry_pricing.order_book_top` entries from the orderbook and uses the entry specified as `entry_pricing.order_book_top` on the configured side (`entry_pricing.price_side`) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.
|
When buying with the orderbook enabled (`bid_strategy.use_order_book=True`), Freqtrade fetches the `bid_strategy.order_book_top` entries from the orderbook and then uses the entry specified as `bid_strategy.order_book_top` on the configured side (`bid_strategy.price_side`) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.
|
||||||
|
|
||||||
#### Entry price without Orderbook enabled
|
#### Buy price without Orderbook enabled
|
||||||
|
|
||||||
The following section uses `side` as the configured `entry_pricing.price_side` (defaults to `"same"`).
|
The following section uses `side` as the configured `bid_strategy.price_side`.
|
||||||
|
|
||||||
When not using orderbook (`entry_pricing.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's below the `last` traded price from the ticker. Otherwise (when the `side` price is above the `last` price), it calculates a rate between `side` and `last` price based on `entry_pricing.price_last_balance`.
|
When not using orderbook (`bid_strategy.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's below the `last` traded price from the ticker. Otherwise (when the `side` price is above the `last` price), it calculates a rate between `side` and `last` price.
|
||||||
|
|
||||||
The `entry_pricing.price_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the `last` price and values between those interpolate between ask and last price.
|
The `bid_strategy.ask_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the `last` price and values between those interpolate between ask and last price.
|
||||||
|
|
||||||
#### Check depth of market
|
### Sell price
|
||||||
|
|
||||||
When check depth of market is enabled (`entry_pricing.check_depth_of_market.enabled=True`), the entry signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.
|
#### Sell price side
|
||||||
|
|
||||||
Orderbook `bid` (buy) side depth is then divided by the orderbook `ask` (sell) side depth and the resulting delta is compared to the value of the `entry_pricing.check_depth_of_market.bids_to_ask_delta` parameter. The entry order is only executed if the orderbook delta is greater than or equal to the configured delta value.
|
The configuration setting `ask_strategy.price_side` defines the side of the spread the bot looks for when selling.
|
||||||
|
|
||||||
!!! Note
|
|
||||||
A delta value below 1 means that `ask` (sell) orderbook side depth is greater than the depth of the `bid` (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).
|
|
||||||
|
|
||||||
### Exit price
|
|
||||||
|
|
||||||
#### Exit price side
|
|
||||||
|
|
||||||
The configuration setting `exit_pricing.price_side` defines the side of the spread the bot looks for when exiting a trade.
|
|
||||||
|
|
||||||
The following displays an orderbook:
|
The following displays an orderbook:
|
||||||
|
|
||||||
@ -91,54 +77,53 @@ The following displays an orderbook:
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
If `exit_pricing.price_side` is set to `"ask"`, then the bot will use 101 as exiting price.
|
If `ask_strategy.price_side` is set to `"ask"`, then the bot will use 101 as selling price.
|
||||||
In line with that, if `exit_pricing.price_side` is set to `"bid"`, then the bot will use 99 as exiting price.
|
In line with that, if `ask_strategy.price_side` is set to `"bid"`, then the bot will use 99 as selling price.
|
||||||
|
|
||||||
Depending on the order direction (_long_/_short_), this will lead to different results. Therefore we recommend to use `"same"` or `"other"` for this configuration instead.
|
#### Sell price with Orderbook enabled
|
||||||
This would result in the following pricing matrix:
|
|
||||||
|
|
||||||
| Direction | Order | setting | price | crosses spread |
|
When selling with the orderbook enabled (`ask_strategy.use_order_book=True`), Freqtrade fetches the `ask_strategy.order_book_max` entries in the orderbook. Then each of the orderbook steps between `ask_strategy.order_book_min` and `ask_strategy.order_book_max` on the configured orderbook side are validated for a profitable sell-possibility based on the strategy configuration (`minimal_roi` conditions) and the sell order is placed at the first profitable spot.
|
||||||
|------ |--------|-----|-----|-----|
|
|
||||||
| long | sell | ask | 101 | no |
|
|
||||||
| long | sell | bid | 99 | yes |
|
|
||||||
| long | sell | same | 101 | no |
|
|
||||||
| long | sell | other | 99 | yes |
|
|
||||||
| short | buy | ask | 101 | yes |
|
|
||||||
| short | buy | bid | 99 | no |
|
|
||||||
| short | buy | same | 99 | no |
|
|
||||||
| short | buy | other | 101 | yes |
|
|
||||||
|
|
||||||
#### Exit price with Orderbook enabled
|
!!! Note
|
||||||
|
Using `order_book_max` higher than `order_book_min` only makes sense when ask_strategy.price_side is set to `"ask"`.
|
||||||
|
|
||||||
When exiting with the orderbook enabled (`exit_pricing.use_order_book=True`), Freqtrade fetches the `exit_pricing.order_book_top` entries in the orderbook and uses the entry specified as `exit_pricing.order_book_top` from the configured side (`exit_pricing.price_side`) as trade exit price.
|
The idea here is to place the sell order early, to be ahead in the queue.
|
||||||
|
|
||||||
1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.
|
A fixed slot (mirroring `bid_strategy.order_book_top`) can be defined by setting `ask_strategy.order_book_min` and `ask_strategy.order_book_max` to the same number.
|
||||||
|
|
||||||
#### Exit price without Orderbook enabled
|
!!! Warning "Order_book_max > 1 - increased risks for stoplosses!"
|
||||||
|
Using `ask_strategy.order_book_max` higher than 1 will increase the risk the stoploss on exchange is cancelled too early, since an eventual [stoploss on exchange](#understand-order_types) will be cancelled as soon as the order is placed.
|
||||||
|
Also, the sell order will remain on the exchange for `unfilledtimeout.sell` (or until it's filled) - which can lead to missed stoplosses (with or without using stoploss on exchange).
|
||||||
|
|
||||||
The following section uses `side` as the configured `exit_pricing.price_side` (defaults to `"ask"`).
|
!!! Warning "Order_book_max > 1 in dry-run"
|
||||||
|
Using `ask_strategy.order_book_max` higher than 1 will result in improper dry-run results (significantly better than real orders executed on exchange), since dry-run assumes orders to be filled almost instantly.
|
||||||
|
It is therefore advised to not use this setting for dry-runs.
|
||||||
|
|
||||||
When not using orderbook (`exit_pricing.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's above the `last` traded price from the ticker. Otherwise (when the `side` price is below the `last` price), it calculates a rate between `side` and `last` price based on `exit_pricing.price_last_balance`.
|
#### Sell price without Orderbook enabled
|
||||||
|
|
||||||
The `exit_pricing.price_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the last price and values between those interpolate between `side` and last price.
|
When not using orderbook (`ask_strategy.use_order_book=False`), the price at the `ask_strategy.price_side` side (defaults to `"ask"`) from the ticker will be used as the sell price.
|
||||||
|
|
||||||
|
When not using orderbook (`ask_strategy.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's below the `last` traded price from the ticker. Otherwise (when the `side` price is above the `last` price), it calculates a rate between `side` and `last` price.
|
||||||
|
|
||||||
|
The `ask_strategy.bid_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the last price and values between those interpolate between `side` and last price.
|
||||||
|
|
||||||
### Market order pricing
|
### Market order pricing
|
||||||
|
|
||||||
When using market orders, prices should be configured to use the "correct" side of the orderbook to allow realistic pricing detection.
|
When using market orders, prices should be configured to use the "correct" side of the orderbook to allow realistic pricing detection.
|
||||||
Assuming both entry and exits are using market orders, a configuration similar to the following must be used
|
Assuming both buy and sell are using market orders, a configuration similar to the following might be used
|
||||||
|
|
||||||
``` jsonc
|
``` jsonc
|
||||||
"order_types": {
|
"order_types": {
|
||||||
"entry": "market",
|
"buy": "market",
|
||||||
"exit": "market"
|
"sell": "market"
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "other",
|
"price_side": "ask",
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
"exit_pricing":{
|
"ask_strategy":{
|
||||||
"price_side": "other",
|
"price_side": "bid",
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
## Protections
|
## Protections
|
||||||
|
|
||||||
!!! Warning "Beta feature"
|
!!! Warning "Beta feature"
|
||||||
This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.
|
This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord, Slack or via Github Issue.
|
||||||
|
|
||||||
Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs.
|
Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs.
|
||||||
All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.
|
All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.
|
||||||
@ -15,10 +15,6 @@ All protection end times are rounded up to the next candle to avoid sudden, unex
|
|||||||
!!! Note "Backtesting"
|
!!! Note "Backtesting"
|
||||||
Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the `--enable-protections` flag.
|
Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the `--enable-protections` flag.
|
||||||
|
|
||||||
!!! Warning "Setting protections from the configuration"
|
|
||||||
Setting protections from the configuration via `"protections": [],` key should be considered deprecated and will be removed in a future version.
|
|
||||||
It is also no longer guaranteed that your protections apply to the strategy in cases where the strategy defines [protections as property](hyperopt.md#optimizing-protections).
|
|
||||||
|
|
||||||
### Available Protections
|
### Available Protections
|
||||||
|
|
||||||
* [`StoplossGuard`](#stoploss-guard) Stop trading if a certain amount of stoploss occurred within a certain time window.
|
* [`StoplossGuard`](#stoploss-guard) Stop trading if a certain amount of stoploss occurred within a certain time window.
|
||||||
@ -48,26 +44,18 @@ If `trade_limit` or more trades resulted in stoploss, trading will stop for `sto
|
|||||||
|
|
||||||
This applies across all pairs, unless `only_per_pair` is set to true, which will then only look at one pair at a time.
|
This applies across all pairs, unless `only_per_pair` is set to true, which will then only look at one pair at a time.
|
||||||
|
|
||||||
Similarly, this protection will by default look at all trades (long and short). For futures bots, setting `only_per_side` will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long stoplosses.
|
|
||||||
|
|
||||||
`required_profit` will determine the required relative profit (or loss) for stoplosses to consider. This should normally not be set and defaults to 0.0 - which means all losing stoplosses will be triggering a block.
|
|
||||||
|
|
||||||
The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.
|
The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@property
|
protections = [
|
||||||
def protections(self):
|
{
|
||||||
return [
|
"method": "StoplossGuard",
|
||||||
{
|
"lookback_period_candles": 24,
|
||||||
"method": "StoplossGuard",
|
"trade_limit": 4,
|
||||||
"lookback_period_candles": 24,
|
"stop_duration_candles": 4,
|
||||||
"trade_limit": 4,
|
"only_per_pair": False
|
||||||
"stop_duration_candles": 4,
|
}
|
||||||
"required_profit": 0.0,
|
]
|
||||||
"only_per_pair": False,
|
|
||||||
"only_per_side": False
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
@ -81,17 +69,15 @@ def protections(self):
|
|||||||
The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of `trade_limit` trades - within the last 48 candles. If desired, `lookback_period` and/or `stop_duration` can be used.
|
The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of `trade_limit` trades - within the last 48 candles. If desired, `lookback_period` and/or `stop_duration` can be used.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@property
|
protections = [
|
||||||
def protections(self):
|
{
|
||||||
return [
|
"method": "MaxDrawdown",
|
||||||
{
|
"lookback_period_candles": 48,
|
||||||
"method": "MaxDrawdown",
|
"trade_limit": 20,
|
||||||
"lookback_period_candles": 48,
|
"stop_duration_candles": 12,
|
||||||
"trade_limit": 20,
|
"max_allowed_drawdown": 0.2
|
||||||
"stop_duration_candles": 12,
|
},
|
||||||
"max_allowed_drawdown": 0.2
|
]
|
||||||
},
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Low Profit Pairs
|
#### Low Profit Pairs
|
||||||
@ -99,23 +85,18 @@ def protections(self):
|
|||||||
`LowProfitPairs` uses all trades for a pair within `lookback_period` in minutes (or in candles when using `lookback_period_candles`) to determine the overall profit ratio.
|
`LowProfitPairs` uses all trades for a pair within `lookback_period` in minutes (or in candles when using `lookback_period_candles`) to determine the overall profit ratio.
|
||||||
If that ratio is below `required_profit`, that pair will be locked for `stop_duration` in minutes (or in candles when using `stop_duration_candles`).
|
If that ratio is below `required_profit`, that pair will be locked for `stop_duration` in minutes (or in candles when using `stop_duration_candles`).
|
||||||
|
|
||||||
For futures bots, setting `only_per_side` will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long losses.
|
|
||||||
|
|
||||||
The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.
|
The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@property
|
protections = [
|
||||||
def protections(self):
|
{
|
||||||
return [
|
"method": "LowProfitPairs",
|
||||||
{
|
"lookback_period_candles": 6,
|
||||||
"method": "LowProfitPairs",
|
"trade_limit": 2,
|
||||||
"lookback_period_candles": 6,
|
"stop_duration": 60,
|
||||||
"trade_limit": 2,
|
"required_profit": 0.02
|
||||||
"stop_duration": 60,
|
}
|
||||||
"required_profit": 0.02,
|
]
|
||||||
"only_per_pair": False,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Cooldown Period
|
#### Cooldown Period
|
||||||
@ -125,14 +106,12 @@ def protections(self):
|
|||||||
The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to "cool down".
|
The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to "cool down".
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@property
|
protections = [
|
||||||
def protections(self):
|
{
|
||||||
return [
|
"method": "CooldownPeriod",
|
||||||
{
|
"stop_duration_candles": 2
|
||||||
"method": "CooldownPeriod",
|
}
|
||||||
"stop_duration_candles": 2
|
]
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
@ -149,7 +128,7 @@ The below example assumes a timeframe of 1 hour:
|
|||||||
* Locks each pair after selling for an additional 5 candles (`CooldownPeriod`), giving other pairs a chance to get filled.
|
* Locks each pair after selling for an additional 5 candles (`CooldownPeriod`), giving other pairs a chance to get filled.
|
||||||
* Stops trading for 4 hours (`4 * 1h candles`) if the last 2 days (`48 * 1h candles`) had 20 trades, which caused a max-drawdown of more than 20%. (`MaxDrawdown`).
|
* Stops trading for 4 hours (`4 * 1h candles`) if the last 2 days (`48 * 1h candles`) had 20 trades, which caused a max-drawdown of more than 20%. (`MaxDrawdown`).
|
||||||
* Stops trading if more than 4 stoploss occur for all pairs within a 1 day (`24 * 1h candles`) limit (`StoplossGuard`).
|
* Stops trading if more than 4 stoploss occur for all pairs within a 1 day (`24 * 1h candles`) limit (`StoplossGuard`).
|
||||||
* Locks all pairs that had 2 Trades within the last 6 hours (`6 * 1h candles`) with a combined profit ratio of below 0.02 (<2%) (`LowProfitPairs`).
|
* Locks all pairs that had 4 Trades within the last 6 hours (`6 * 1h candles`) with a combined profit ratio of below 0.02 (<2%) (`LowProfitPairs`).
|
||||||
* Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (`24 * 1h candles`), a minimum of 4 trades.
|
* Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (`24 * 1h candles`), a minimum of 4 trades.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@ -157,42 +136,39 @@ from freqtrade.strategy import IStrategy
|
|||||||
|
|
||||||
class AwesomeStrategy(IStrategy)
|
class AwesomeStrategy(IStrategy)
|
||||||
timeframe = '1h'
|
timeframe = '1h'
|
||||||
|
protections = [
|
||||||
@property
|
{
|
||||||
def protections(self):
|
"method": "CooldownPeriod",
|
||||||
return [
|
"stop_duration_candles": 5
|
||||||
{
|
},
|
||||||
"method": "CooldownPeriod",
|
{
|
||||||
"stop_duration_candles": 5
|
"method": "MaxDrawdown",
|
||||||
},
|
"lookback_period_candles": 48,
|
||||||
{
|
"trade_limit": 20,
|
||||||
"method": "MaxDrawdown",
|
"stop_duration_candles": 4,
|
||||||
"lookback_period_candles": 48,
|
"max_allowed_drawdown": 0.2
|
||||||
"trade_limit": 20,
|
},
|
||||||
"stop_duration_candles": 4,
|
{
|
||||||
"max_allowed_drawdown": 0.2
|
"method": "StoplossGuard",
|
||||||
},
|
"lookback_period_candles": 24,
|
||||||
{
|
"trade_limit": 4,
|
||||||
"method": "StoplossGuard",
|
"stop_duration_candles": 2,
|
||||||
"lookback_period_candles": 24,
|
"only_per_pair": False
|
||||||
"trade_limit": 4,
|
},
|
||||||
"stop_duration_candles": 2,
|
{
|
||||||
"only_per_pair": False
|
"method": "LowProfitPairs",
|
||||||
},
|
"lookback_period_candles": 6,
|
||||||
{
|
"trade_limit": 2,
|
||||||
"method": "LowProfitPairs",
|
"stop_duration_candles": 60,
|
||||||
"lookback_period_candles": 6,
|
"required_profit": 0.02
|
||||||
"trade_limit": 2,
|
},
|
||||||
"stop_duration_candles": 60,
|
{
|
||||||
"required_profit": 0.02
|
"method": "LowProfitPairs",
|
||||||
},
|
"lookback_period_candles": 24,
|
||||||
{
|
"trade_limit": 4,
|
||||||
"method": "LowProfitPairs",
|
"stop_duration_candles": 2,
|
||||||
"lookback_period_candles": 24,
|
"required_profit": 0.01
|
||||||
"trade_limit": 4,
|
}
|
||||||
"stop_duration_candles": 2,
|
]
|
||||||
"required_profit": 0.01
|
|
||||||
}
|
|
||||||
]
|
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
![freqtrade](assets/freqtrade_poweredby.svg)
|
![freqtrade](assets/freqtrade_poweredby.svg)
|
||||||
|
|
||||||
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/workflows/Freqtrade%20CI/badge.svg)](https://github.com/freqtrade/freqtrade/actions/)
|
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/workflows/Freqtrade%20CI/badge.svg)](https://github.com/freqtrade/freqtrade/actions/)
|
||||||
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04864/status.svg)](https://doi.org/10.21105/joss.04864)
|
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/freqtrade/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
[![Coverage Status](https://coveralls.io/repos/github/freqtrade/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
||||||
[![Maintainability](https://api.codeclimate.com/v1/badges/5737e6d668200b7518ff/maintainability)](https://codeclimate.com/github/freqtrade/freqtrade/maintainability)
|
[![Maintainability](https://api.codeclimate.com/v1/badges/5737e6d668200b7518ff/maintainability)](https://codeclimate.com/github/freqtrade/freqtrade/maintainability)
|
||||||
|
|
||||||
@ -12,7 +11,7 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram or webUI. It contains backtesting, plotting and money management tools as well as strategy optimization by machine learning.
|
Freqtrade is a crypto-currency algorithmic trading software developed in python (3.7+) and supported on Windows, macOS and Linux.
|
||||||
|
|
||||||
!!! Danger "DISCLAIMER"
|
!!! Danger "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.
|
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.
|
||||||
@ -21,8 +20,6 @@ Freqtrade is a free and open source crypto trading bot written in Python. It is
|
|||||||
|
|
||||||
We strongly recommend you to have basic coding skills and Python knowledge. Do not hesitate to read the source code and understand the mechanisms of this bot, algorithms and techniques implemented in it.
|
We strongly recommend you to have basic coding skills and Python knowledge. Do not hesitate to read the source code and understand the mechanisms of this bot, algorithms and techniques implemented in it.
|
||||||
|
|
||||||
![freqtrade screenshot](assets/freqtrade-screenshot.png)
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Develop your Strategy: Write your strategy in python, using [pandas](https://pandas.pydata.org/). Example strategies to inspire you are available in the [strategy repository](https://github.com/freqtrade/freqtrade-strategies).
|
- Develop your Strategy: Write your strategy in python, using [pandas](https://pandas.pydata.org/). Example strategies to inspire you are available in the [strategy repository](https://github.com/freqtrade/freqtrade-strategies).
|
||||||
@ -32,36 +29,24 @@ Freqtrade is a free and open source crypto trading bot written in Python. It is
|
|||||||
- Select markets: Create your static list or use an automatic one based on top traded volumes and/or prices (not available during backtesting). You can also explicitly blacklist markets you don't want to trade.
|
- Select markets: Create your static list or use an automatic one based on top traded volumes and/or prices (not available during backtesting). You can also explicitly blacklist markets you don't want to trade.
|
||||||
- Run: Test your strategy with simulated money (Dry-Run mode) or deploy it with real money (Live-Trade mode).
|
- Run: Test your strategy with simulated money (Dry-Run mode) or deploy it with real money (Live-Trade mode).
|
||||||
- Run using Edge (optional module): The concept is to find the best historical [trade expectancy](edge.md#expectancy) by markets based on variation of the stop-loss and then allow/reject markets to trade. The sizing of the trade is based on a risk of a percentage of your capital.
|
- Run using Edge (optional module): The concept is to find the best historical [trade expectancy](edge.md#expectancy) by markets based on variation of the stop-loss and then allow/reject markets to trade. The sizing of the trade is based on a risk of a percentage of your capital.
|
||||||
- Control/Monitor: Use Telegram or a WebUI (start/stop the bot, show profit/loss, daily summary, current open trades results, etc.).
|
- Control/Monitor: Use Telegram or a REST API (start/stop the bot, show profit/loss, daily summary, current open trades results, etc.).
|
||||||
- Analyze: Further analysis can be performed on either Backtesting data or Freqtrade trading history (SQL database), including automated standard plots, and methods to load the data into [interactive environments](data-analysis.md).
|
- Analyse: Further analysis can be performed on either Backtesting data or Freqtrade trading history (SQL database), including automated standard plots, and methods to load the data into [interactive environments](data-analysis.md).
|
||||||
|
|
||||||
## Supported exchange marketplaces
|
## Supported exchange marketplaces
|
||||||
|
|
||||||
Please read the [exchange specific notes](exchanges.md) to learn about eventual, special configurations needed for each exchange.
|
Please read the [exchange specific notes](exchanges.md) to learn about eventual, special configurations needed for each exchange.
|
||||||
|
|
||||||
- [X] [Binance](https://www.binance.com/)
|
- [X] [Binance](https://www.binance.com/) ([*Note for binance users](exchanges.md#blacklists))
|
||||||
- [X] [Bittrex](https://bittrex.com/)
|
- [X] [Bittrex](https://bittrex.com/)
|
||||||
- [X] [Gate.io](https://www.gate.io/ref/6266643)
|
- [X] [FTX](https://ftx.com)
|
||||||
- [X] [Huobi](http://huobi.com/)
|
|
||||||
- [X] [Kraken](https://kraken.com/)
|
- [X] [Kraken](https://kraken.com/)
|
||||||
- [X] [OKX](https://okx.com/) (Former OKEX)
|
|
||||||
- [ ] [potentially many others through <img alt="ccxt" width="30px" src="assets/ccxt-logo.svg" />](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_
|
- [ ] [potentially many others through <img alt="ccxt" width="30px" src="assets/ccxt-logo.svg" />](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_
|
||||||
|
|
||||||
### Supported Futures Exchanges (experimental)
|
|
||||||
|
|
||||||
- [X] [Binance](https://www.binance.com/)
|
|
||||||
- [X] [Gate.io](https://www.gate.io/ref/6266643)
|
|
||||||
- [X] [OKX](https://okx.com/)
|
|
||||||
- [X] [Bybit](https://bybit.com/)
|
|
||||||
|
|
||||||
Please make sure to read the [exchange specific notes](exchanges.md), as well as the [trading with leverage](leverage.md) documentation before diving in.
|
|
||||||
|
|
||||||
### Community tested
|
### Community tested
|
||||||
|
|
||||||
Exchanges confirmed working by the community:
|
Exchanges confirmed working by the community:
|
||||||
|
|
||||||
- [X] [Bitvavo](https://bitvavo.com/)
|
- [X] [Bitvavo](https://bitvavo.com/)
|
||||||
- [X] [Kucoin](https://www.kucoin.com/)
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@ -79,7 +64,7 @@ To run this bot we recommend you a linux cloud instance with a minimum of:
|
|||||||
|
|
||||||
Alternatively
|
Alternatively
|
||||||
|
|
||||||
- Python 3.8+
|
- Python 3.7+
|
||||||
- pip (pip3)
|
- pip (pip3)
|
||||||
- git
|
- git
|
||||||
- TA-Lib
|
- TA-Lib
|
||||||
@ -87,10 +72,14 @@ Alternatively
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
### Help / Discord
|
### Help / Discord / Slack
|
||||||
|
|
||||||
For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join the Freqtrade [discord server](https://discord.gg/p7nuUNVfP7).
|
For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join our slack channel.
|
||||||
|
|
||||||
|
Please check out our [discord server](https://discord.gg/p7nuUNVfP7).
|
||||||
|
|
||||||
|
You can also join our [Slack channel](https://join.slack.com/t/highfrequencybot/shared_invite/zt-mm786y93-Fxo37glxMY9g8OQC5AoOIw).
|
||||||
|
|
||||||
## Ready to try?
|
## Ready to try?
|
||||||
|
|
||||||
Begin by reading the installation guide [for docker](docker_quickstart.md) (recommended), or for [installation without docker](installation.md).
|
Begin by reading our installation guide [for docker](docker_quickstart.md) (recommended), or for [installation without docker](installation.md).
|
||||||
|
@ -24,31 +24,21 @@ The easiest way to install and run Freqtrade is to clone the bot Github reposito
|
|||||||
The `stable` branch contains the code of the last release (done usually once per month on an approximately one week old snapshot of the `develop` branch to prevent packaging bugs, so potentially it's more stable).
|
The `stable` branch contains the code of the last release (done usually once per month on an approximately one week old snapshot of the `develop` branch to prevent packaging bugs, so potentially it's more stable).
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
Python3.8 or higher and the corresponding `pip` are assumed to be available. The install-script will warn you and stop if that's not the case. `git` is also needed to clone the Freqtrade repository.
|
Python3.7 or higher and the corresponding `pip` are assumed to be available. The install-script will warn you and stop if that's not the case. `git` is also needed to clone the Freqtrade repository.
|
||||||
Also, python headers (`python<yourversion>-dev` / `python<yourversion>-devel`) must be available for the installation to complete successfully.
|
Also, python headers (`python<yourversion>-dev` / `python<yourversion>-devel`) must be available for the installation to complete successfully.
|
||||||
|
|
||||||
!!! Warning "Up-to-date clock"
|
!!! Warning "Up-to-date clock"
|
||||||
The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.
|
The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.
|
||||||
|
|
||||||
!!! Error "Running setup.py install for gym did not run successfully."
|
|
||||||
If you get an error related with gym we suggest you to downgrade setuptools it to version 65.5.0 you can do it with the following command:
|
|
||||||
```bash
|
|
||||||
pip install setuptools==65.5.0
|
|
||||||
```
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
These requirements apply to both [Script Installation](#script-installation) and [Manual Installation](#manual-installation).
|
These requirements apply to both [Script Installation](#script-installation) and [Manual Installation](#manual-installation).
|
||||||
|
|
||||||
!!! Note "ARM64 systems"
|
|
||||||
If you are running an ARM64 system (like a MacOS M1 or an Oracle VM), please use [docker](docker_quickstart.md) to run freqtrade.
|
|
||||||
While native installation is possible with some manual effort, this is not supported at the moment.
|
|
||||||
|
|
||||||
### Install guide
|
### Install guide
|
||||||
|
|
||||||
* [Python >= 3.8.x](http://docs.python-guide.org/en/latest/starting/installation/)
|
* [Python >= 3.7.x](http://docs.python-guide.org/en/latest/starting/installation/)
|
||||||
* [pip](https://pip.pypa.io/en/stable/installing/)
|
* [pip](https://pip.pypa.io/en/stable/installing/)
|
||||||
* [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
* [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
||||||
* [virtualenv](https://virtualenv.pypa.io/en/stable/installation.html) (Recommended)
|
* [virtualenv](https://virtualenv.pypa.io/en/stable/installation.html) (Recommended)
|
||||||
@ -60,7 +50,7 @@ We've included/collected install instructions for Ubuntu, MacOS, and Windows. Th
|
|||||||
OS Specific steps are listed first, the [Common](#common) section below is necessary for all systems.
|
OS Specific steps are listed first, the [Common](#common) section below is necessary for all systems.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
Python3.8 or higher and the corresponding pip are assumed to be available.
|
Python3.7 or higher and the corresponding pip are assumed to be available.
|
||||||
|
|
||||||
=== "Debian/Ubuntu"
|
=== "Debian/Ubuntu"
|
||||||
#### Install necessary dependencies
|
#### Install necessary dependencies
|
||||||
@ -70,18 +60,18 @@ OS Specific steps are listed first, the [Common](#common) section below is neces
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
||||||
# install packages
|
# install packages
|
||||||
sudo apt install -y python3-pip python3-venv python3-dev python3-pandas git curl
|
sudo apt install -y python3-pip python3-venv python3-dev python3-pandas git
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "RaspberryPi/Raspbian"
|
=== "RaspberryPi/Raspbian"
|
||||||
The following assumes the latest [Raspbian Buster lite image](https://www.raspberrypi.org/downloads/raspbian/).
|
The following assumes the latest [Raspbian Buster lite image](https://www.raspberrypi.org/downloads/raspbian/).
|
||||||
This image comes with python3.9 preinstalled, making it easy to get freqtrade up and running.
|
This image comes with python3.7 preinstalled, making it easy to get freqtrade up and running.
|
||||||
|
|
||||||
Tested using a Raspberry Pi 3 with the Raspbian Buster lite image, all updates applied.
|
Tested using a Raspberry Pi 3 with the Raspbian Buster lite image, all updates applied.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt-get install python3-venv libatlas-base-dev cmake curl
|
sudo apt-get install python3-venv libatlas-base-dev cmake
|
||||||
# Use pywheels.org to speed up installation
|
# Use pywheels.org to speed up installation
|
||||||
sudo echo "[global]\nextra-index-url=https://www.piwheels.org/simple" > tee /etc/pip.conf
|
sudo echo "[global]\nextra-index-url=https://www.piwheels.org/simple" > tee /etc/pip.conf
|
||||||
|
|
||||||
@ -123,13 +113,6 @@ git checkout develop
|
|||||||
|
|
||||||
You may later switch between branches at any time with the `git checkout stable`/`git checkout develop` commands.
|
You may later switch between branches at any time with the `git checkout stable`/`git checkout develop` commands.
|
||||||
|
|
||||||
??? Note "Install from pypi"
|
|
||||||
An alternative way to install Freqtrade is from [pypi](https://pypi.org/project/freqtrade/). The downside is that this method requires ta-lib to be correctly installed beforehand, and is therefore currently not the recommended way to install Freqtrade.
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
pip install freqtrade
|
|
||||||
```
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
## Script Installation
|
## Script Installation
|
||||||
@ -175,7 +158,7 @@ You can as well update, configure and reset the codebase of your bot with `./scr
|
|||||||
** --install **
|
** --install **
|
||||||
|
|
||||||
With this option, the script will install the bot and most dependencies:
|
With this option, the script will install the bot and most dependencies:
|
||||||
You will need to have git and python3.8+ installed beforehand for this to work.
|
You will need to have git and python3.7+ installed beforehand for this to work.
|
||||||
|
|
||||||
* Mandatory software as: `ta-lib`
|
* Mandatory software as: `ta-lib`
|
||||||
* Setup your virtualenv under `.env/`
|
* Setup your virtualenv under `.env/`
|
||||||
@ -220,8 +203,6 @@ sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h
|
|||||||
./configure --prefix=/usr/local
|
./configure --prefix=/usr/local
|
||||||
make
|
make
|
||||||
sudo make install
|
sudo make install
|
||||||
# On debian based systems (debian, ubuntu, ...) - updating ldconfig might be necessary.
|
|
||||||
sudo ldconfig
|
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf ./ta-lib*
|
rm -rf ./ta-lib*
|
||||||
```
|
```
|
||||||
@ -290,8 +271,10 @@ cd freqtrade
|
|||||||
|
|
||||||
#### Freqtrade install: Conda Environment
|
#### Freqtrade install: Conda Environment
|
||||||
|
|
||||||
|
Prepare conda-freqtrade environment, using file `environment.yml`, which exist in main freqtrade directory
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
conda create --name freqtrade python=3.10
|
conda env create -n freqtrade-conda -f environment.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note "Creating Conda Environment"
|
!!! Note "Creating Conda Environment"
|
||||||
@ -300,9 +283,12 @@ conda create --name freqtrade python=3.10
|
|||||||
```bash
|
```bash
|
||||||
# choose your own packages
|
# choose your own packages
|
||||||
conda env create -n [name of the environment] [python version] [packages]
|
conda env create -n [name of the environment] [python version] [packages]
|
||||||
|
|
||||||
|
# point to file with packages
|
||||||
|
conda env create -n [name of the environment] -f [file]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Enter/exit freqtrade environment
|
#### Enter/exit freqtrade-conda environment
|
||||||
|
|
||||||
To check available environments, type
|
To check available environments, type
|
||||||
|
|
||||||
@ -314,7 +300,7 @@ Enter installed environment
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# enter conda environment
|
# enter conda environment
|
||||||
conda activate freqtrade
|
conda activate freqtrade-conda
|
||||||
|
|
||||||
# exit conda environment - don't do it now
|
# exit conda environment - don't do it now
|
||||||
conda deactivate
|
conda deactivate
|
||||||
@ -324,20 +310,9 @@ Install last python dependencies with pip
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install -r requirements.txt
|
|
||||||
python3 -m pip install -e .
|
python3 -m pip install -e .
|
||||||
```
|
```
|
||||||
|
|
||||||
Patch conda libta-lib (Linux only)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Ensure that the environment is active!
|
|
||||||
conda activate freqtrade
|
|
||||||
|
|
||||||
cd build_helpers
|
|
||||||
bash install_ta-lib.sh ${CONDA_PREFIX} nosudo
|
|
||||||
```
|
|
||||||
|
|
||||||
### Congratulations
|
### Congratulations
|
||||||
|
|
||||||
[You are ready](#you-are-ready), and run the bot
|
[You are ready](#you-are-ready), and run the bot
|
||||||
@ -351,8 +326,8 @@ conda env list
|
|||||||
# activate base environment
|
# activate base environment
|
||||||
conda activate
|
conda activate
|
||||||
|
|
||||||
# activate freqtrade environment
|
# activate freqtrade-conda environment
|
||||||
conda activate freqtrade
|
conda activate freqtrade-conda
|
||||||
|
|
||||||
#deactivate any conda environments
|
#deactivate any conda environments
|
||||||
conda deactivate
|
conda deactivate
|
||||||
@ -432,3 +407,16 @@ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10
|
|||||||
```
|
```
|
||||||
|
|
||||||
If this file is inexistent, then you're probably on a different version of MacOS, so you may need to consult the internet for specific resolution details.
|
If this file is inexistent, then you're probably on a different version of MacOS, so you may need to consult the internet for specific resolution details.
|
||||||
|
|
||||||
|
### MacOS installation error with python 3.9
|
||||||
|
|
||||||
|
When using python 3.9 on macOS, it's currently necessary to install some os-level modules to allow dependencies to compile.
|
||||||
|
The errors you'll see happen during installation and are related to the installation of `tables` or `blosc`.
|
||||||
|
|
||||||
|
You can install the necessary libraries with the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install hdf5 c-blosc
|
||||||
|
```
|
||||||
|
|
||||||
|
After this, please run the installation (script) again.
|
||||||
|
143
docs/leverage.md
@ -1,143 +0,0 @@
|
|||||||
# Trading with Leverage
|
|
||||||
|
|
||||||
!!! Warning "Beta feature"
|
|
||||||
This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.
|
|
||||||
|
|
||||||
!!! Note "Multiple bots on one account"
|
|
||||||
You can't run 2 bots on the same account with leverage. For leveraged / margin trading, freqtrade assumes it's the only user of the account, and all liquidation levels are calculated based on this assumption.
|
|
||||||
|
|
||||||
!!! Danger "Trading with leverage is very risky"
|
|
||||||
Do not trade with a leverage > 1 using a strategy that hasn't shown positive results in a live run using the spot market. Check the stoploss of your strategy. With a leverage of 2, a stoploss of 0.5 (50%) would be too low, and these trades would be liquidated before reaching that stoploss.
|
|
||||||
We do not assume any responsibility for eventual losses that occur from using this software or this mode.
|
|
||||||
|
|
||||||
Please only use advanced trading modes when you know how freqtrade (and your strategy) works.
|
|
||||||
Also, never risk more than what you can afford to lose.
|
|
||||||
|
|
||||||
If you already have an existing strategy, please read the [strategy migration guide](strategy_migration.md#strategy-migration-between-v2-and-v3) to migrate your strategy from a freqtrade v2 strategy, to strategy of version 3 which can short and trade futures.
|
|
||||||
|
|
||||||
## Shorting
|
|
||||||
|
|
||||||
Shorting is not possible when trading with [`trading_mode`](#understand-tradingmode) set to `spot`. To short trade, `trading_mode` must be set to `margin`(currently unavailable) or [`futures`](#futures), with [`margin_mode`](#margin-mode) set to `cross`(currently unavailable) or [`isolated`](#isolated-margin-mode)
|
|
||||||
|
|
||||||
For a strategy to short, the strategy class must set the class variable `can_short = True`
|
|
||||||
|
|
||||||
Please read [strategy customization](strategy-customization.md#entry-signal-rules) for instructions on how to set signals to enter and exit short trades.
|
|
||||||
|
|
||||||
## Understand `trading_mode`
|
|
||||||
|
|
||||||
The possible values are: `spot` (default), `margin`(*Currently unavailable*) or `futures`.
|
|
||||||
|
|
||||||
### Spot
|
|
||||||
|
|
||||||
Regular trading mode (low risk)
|
|
||||||
|
|
||||||
- Long trades only (No short trades).
|
|
||||||
- No leverage.
|
|
||||||
- No Liquidation.
|
|
||||||
- Profits gained/lost are equal to the change in value of the assets (minus trading fees).
|
|
||||||
|
|
||||||
### Leverage trading modes
|
|
||||||
|
|
||||||
With leverage, a trader borrows capital from the exchange. The capital must be re-payed fully to the exchange (potentially with interest), and the trader keeps any profits, or pays any losses, from any trades made using the borrowed capital.
|
|
||||||
|
|
||||||
Because the capital must always be re-payed, exchanges will **liquidate** (forcefully sell the traders assets) a trade made using borrowed capital when the total value of assets in the leverage account drops to a certain point (a point where the total value of losses is less than the value of the collateral that the trader actually owns in the leverage account), in order to ensure that the trader has enough capital to pay the borrowed assets back to the exchange. The exchange will also charge a **liquidation fee**, adding to the traders losses.
|
|
||||||
|
|
||||||
For this reason, **DO NOT TRADE WITH LEVERAGE IF YOU DON'T KNOW EXACTLY WHAT YOUR DOING. LEVERAGE TRADING IS HIGH RISK, AND CAN RESULT IN THE VALUE OF YOUR ASSETS DROPPING TO 0 VERY QUICKLY, WITH NO CHANCE OF INCREASING IN VALUE AGAIN.**
|
|
||||||
|
|
||||||
#### Margin (currently unavailable)
|
|
||||||
|
|
||||||
Trading occurs on the spot market, but the exchange lends currency to you in an amount equal to the chosen leverage. You pay the amount lent to you back to the exchange with interest, and your profits/losses are multiplied by the leverage specified.
|
|
||||||
|
|
||||||
#### Futures
|
|
||||||
|
|
||||||
Perpetual swaps (also known as Perpetual Futures) are contracts traded at a price that is closely tied to the underlying asset they are based off of (ex.). You are not trading the actual asset but instead are trading a derivative contract. Perpetual swap contracts can last indefinitely, in contrast to futures or option contracts.
|
|
||||||
|
|
||||||
In addition to the gains/losses from the change in price of the futures contract, traders also exchange _funding fees_, which are gains/losses worth an amount that is derived from the difference in price between the futures contract and the underlying asset. The difference in price between a futures contract and the underlying asset varies between exchanges.
|
|
||||||
|
|
||||||
To trade in futures markets, you'll have to set `trading_mode` to "futures".
|
|
||||||
You will also have to pick a "margin mode" (explanation below) - with freqtrade currently only supporting isolated margin.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
"trading_mode": "futures",
|
|
||||||
"margin_mode": "isolated"
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Pair namings
|
|
||||||
|
|
||||||
Freqtrade follows the [ccxt naming conventions for futures](https://docs.ccxt.com/en/latest/manual.html?#perpetual-swap-perpetual-future).
|
|
||||||
A futures pair will therefore have the naming of `base/quote:settle` (e.g. `ETH/USDT:USDT`).
|
|
||||||
|
|
||||||
### Margin mode
|
|
||||||
|
|
||||||
On top of `trading_mode` - you will also have to configure your `margin_mode`.
|
|
||||||
While freqtrade currently only supports one margin mode, this will change, and by configuring it now you're all set for future updates.
|
|
||||||
|
|
||||||
The possible values are: `isolated`, or `cross`(*currently unavailable*).
|
|
||||||
|
|
||||||
#### Isolated margin mode
|
|
||||||
|
|
||||||
Each market(trading pair), keeps collateral in a separate account
|
|
||||||
|
|
||||||
``` json
|
|
||||||
"margin_mode": "isolated"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Cross margin mode (currently unavailable)
|
|
||||||
|
|
||||||
One account is used to share collateral between markets (trading pairs). Margin is taken from total account balance to avoid liquidation when needed.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
"margin_mode": "cross"
|
|
||||||
```
|
|
||||||
|
|
||||||
Please read the [exchange specific notes](exchanges.md) for exchanges that support this mode and how they differ.
|
|
||||||
|
|
||||||
## Set leverage to use
|
|
||||||
|
|
||||||
Different strategies and risk profiles will require different levels of leverage.
|
|
||||||
While you could configure one static leverage value - freqtrade offers you the flexibility to adjust this via [strategy leverage callback](strategy-callbacks.md#leverage-callback) - which allows you to use different leverages by pair, or based on some other factor benefitting your strategy result.
|
|
||||||
|
|
||||||
If not implemented, leverage defaults to 1x (no leverage).
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Higher leverage also equals higher risk - be sure you fully understand the implications of using leverage!
|
|
||||||
|
|
||||||
## Understand `liquidation_buffer`
|
|
||||||
|
|
||||||
*Defaults to `0.05`*
|
|
||||||
|
|
||||||
A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price.
|
|
||||||
This artificial liquidation price is calculated as:
|
|
||||||
|
|
||||||
`freqtrade_liquidation_price = liquidation_price ± (abs(open_rate - liquidation_price) * liquidation_buffer)`
|
|
||||||
|
|
||||||
- `±` = `+` for long trades
|
|
||||||
- `±` = `-` for short trades
|
|
||||||
|
|
||||||
Possible values are any floats between 0.0 and 0.99
|
|
||||||
|
|
||||||
**ex:** If a trade is entered at a price of 10 coin/USDT, and the liquidation price of this trade is 8 coin/USDT, then with `liquidation_buffer` set to `0.05` the minimum stoploss for this trade would be $8 + ((10 - 8) * 0.05) = 8 + 0.1 = 8.1$
|
|
||||||
|
|
||||||
!!! Danger "A `liquidation_buffer` of 0.0, or a low `liquidation_buffer` is likely to result in liquidations, and liquidation fees"
|
|
||||||
Currently Freqtrade is able to calculate liquidation prices, but does not calculate liquidation fees. Setting your `liquidation_buffer` to 0.0, or using a low `liquidation_buffer` could result in your positions being liquidated. Freqtrade does not track liquidation fees, so liquidations will result in inaccurate profit/loss results for your bot. If you use a low `liquidation_buffer`, it is recommended to use `stoploss_on_exchange` if your exchange supports this.
|
|
||||||
|
|
||||||
## Unavailable funding rates
|
|
||||||
|
|
||||||
For futures data, exchanges commonly provide the futures candles, the marks, and the funding rates. However, it is common that whilst candles and marks might be available, the funding rates are not. This can affect backtesting timeranges, i.e. you may only be able to test recent timeranges and not earlier, experiencing the `No data found. Terminating.` error. To get around this, add the `futures_funding_rate` config option as listed in [configuration.md](configuration.md), and it is recommended that you set this to `0`, unless you know a given specific funding rate for your pair, exchange and timerange. Setting this to anything other than `0` can have drastic effects on your profit calculations within strategy, e.g. within the `custom_exit`, `custom_stoploss`, etc functions.
|
|
||||||
|
|
||||||
!!! Warning "This will mean your backtests are inaccurate."
|
|
||||||
This will not overwrite funding rates that are available from the exchange, but bear in mind that setting a false funding rate will mean backtesting results will be inaccurate for historical timeranges where funding rates are not available.
|
|
||||||
|
|
||||||
### Developer
|
|
||||||
|
|
||||||
#### Margin mode
|
|
||||||
|
|
||||||
For shorts, the currency which pays the interest fee for the `borrowed` currency is purchased at the same time of the closing trade (This means that the amount purchased in short closing trades is greater than the amount sold in short opening trades).
|
|
||||||
|
|
||||||
For longs, the currency which pays the interest fee for the `borrowed` will already be owned by the user and does not need to be purchased. The interest is subtracted from the `close_value` of the trade.
|
|
||||||
|
|
||||||
All Fees are included in `current_profit` calculations during the trade.
|
|
||||||
|
|
||||||
#### Futures mode
|
|
||||||
|
|
||||||
Funding fees are either added or subtracted from the total amount of a trade
|
|
@ -11,6 +11,9 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" {{ hidden }}>
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" {{ hidden }}>
|
||||||
<div class="md-sidebar__scrollwrap">
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div id="widget-wrapper">
|
||||||
|
|
||||||
|
</div>
|
||||||
<div class="md-sidebar__inner">
|
<div class="md-sidebar__inner">
|
||||||
{% include "partials/nav.html" %}
|
{% include "partials/nav.html" %}
|
||||||
</div>
|
</div>
|
||||||
@ -41,4 +44,25 @@
|
|||||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
|
||||||
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
<!-- Load binance SDK -->
|
||||||
|
<script async defer src="https://public.bnbstatic.com/static/js/broker-sdk/broker-sdk@1.0.0.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.onload = function () {
|
||||||
|
var sidebar = document.getElementById('widget-wrapper')
|
||||||
|
var newDiv = document.createElement("div");
|
||||||
|
newDiv.id = "widget";
|
||||||
|
try {
|
||||||
|
sidebar.prepend(newDiv);
|
||||||
|
|
||||||
|
window.binanceBrokerPortalSdk.initBrokerSDK('#widget', {
|
||||||
|
apiHost: 'https://www.binance.com',
|
||||||
|
brokerId: 'R4BD3S82',
|
||||||
|
slideTime: 4e4,
|
||||||
|
});
|
||||||
|
} catch(err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
130
docs/plotting.md
@ -14,7 +14,7 @@ pip install -U -r requirements-plot.txt
|
|||||||
|
|
||||||
The `freqtrade plot-dataframe` subcommand shows an interactive graph with three subplots:
|
The `freqtrade plot-dataframe` subcommand shows an interactive graph with three subplots:
|
||||||
|
|
||||||
* Main plot with candlesticks and indicators following price (sma/ema)
|
* Main plot with candlestics and indicators following price (sma/ema)
|
||||||
* Volume bars
|
* Volume bars
|
||||||
* Additional indicators as specified by `--indicators2`
|
* Additional indicators as specified by `--indicators2`
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ optional arguments:
|
|||||||
_today.json`
|
_today.json`
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
-i TIMEFRAME, --timeframe TIMEFRAME
|
-i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
|
||||||
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
||||||
--no-trades Skip using trades from backtesting file and DB.
|
--no-trades Skip using trades from backtesting file and DB.
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ Strategy arguments:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
freqtrade plot-dataframe -p BTC/ETH --strategy AwesomeStrategy
|
freqtrade plot-dataframe -p BTC/ETH
|
||||||
```
|
```
|
||||||
|
|
||||||
The `-p/--pairs` argument can be used to specify pairs you would like to plot.
|
The `-p/--pairs` argument can be used to specify pairs you would like to plot.
|
||||||
@ -107,6 +107,9 @@ The `-p/--pairs` argument can be used to specify pairs you would like to plot.
|
|||||||
Specify custom indicators.
|
Specify custom indicators.
|
||||||
Use `--indicators1` for the main plot and `--indicators2` for the subplot below (if values are in a different range than prices).
|
Use `--indicators1` for the main plot and `--indicators2` for the subplot below (if values are in a different range than prices).
|
||||||
|
|
||||||
|
!!! Tip
|
||||||
|
You will almost certainly want to specify a custom strategy! This can be done by adding `-s Classname` / `--strategy ClassName` to the command.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --indicators1 sma ema --indicators2 macd
|
freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --indicators1 sma ema --indicators2 macd
|
||||||
```
|
```
|
||||||
@ -161,7 +164,7 @@ The resulting plot will have the following elements:
|
|||||||
|
|
||||||
An advanced plot configuration can be specified in the strategy in the `plot_config` parameter.
|
An advanced plot configuration can be specified in the strategy in the `plot_config` parameter.
|
||||||
|
|
||||||
Additional features when using `plot_config` include:
|
Additional features when using plot_config include:
|
||||||
|
|
||||||
* Specify colors per indicator
|
* Specify colors per indicator
|
||||||
* Specify additional subplots
|
* Specify additional subplots
|
||||||
@ -171,7 +174,6 @@ The sample plot configuration below specifies fixed colors for the indicators. O
|
|||||||
It also allows multiple subplots to display both MACD and RSI at the same time.
|
It also allows multiple subplots to display both MACD and RSI at the same time.
|
||||||
|
|
||||||
Plot type can be configured using `type` key. Possible types are:
|
Plot type can be configured using `type` key. Possible types are:
|
||||||
|
|
||||||
* `scatter` corresponding to `plotly.graph_objects.Scatter` class (default).
|
* `scatter` corresponding to `plotly.graph_objects.Scatter` class (default).
|
||||||
* `bar` corresponding to `plotly.graph_objects.Bar` class.
|
* `bar` corresponding to `plotly.graph_objects.Bar` class.
|
||||||
|
|
||||||
@ -180,88 +182,39 @@ Extra parameters to `plotly.graph_objects.*` constructor can be specified in `pl
|
|||||||
Sample configuration with inline comments explaining the process:
|
Sample configuration with inline comments explaining the process:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@property
|
plot_config = {
|
||||||
def plot_config(self):
|
'main_plot': {
|
||||||
"""
|
# Configuration for main plot indicators.
|
||||||
There are a lot of solutions how to build the return dictionary.
|
# Specifies `ema10` to be red, and `ema50` to be a shade of gray
|
||||||
The only important point is the return value.
|
'ema10': {'color': 'red'},
|
||||||
Example:
|
'ema50': {'color': '#CCCCCC'},
|
||||||
plot_config = {'main_plot': {}, 'subplots': {}}
|
# By omitting color, a random color is selected.
|
||||||
|
'sar': {},
|
||||||
"""
|
# fill area between senkou_a and senkou_b
|
||||||
plot_config = {}
|
'senkou_a': {
|
||||||
plot_config['main_plot'] = {
|
'color': 'green', #optional
|
||||||
# Configuration for main plot indicators.
|
'fill_to': 'senkou_b',
|
||||||
# Assumes 2 parameters, emashort and emalong to be specified.
|
'fill_label': 'Ichimoku Cloud', #optional
|
||||||
f'ema_{self.emashort.value}': {'color': 'red'},
|
'fill_color': 'rgba(255,76,46,0.2)', #optional
|
||||||
f'ema_{self.emalong.value}': {'color': '#CCCCCC'},
|
},
|
||||||
# By omitting color, a random color is selected.
|
# plot senkou_b, too. Not only the area to it.
|
||||||
'sar': {},
|
'senkou_b': {}
|
||||||
# fill area between senkou_a and senkou_b
|
|
||||||
'senkou_a': {
|
|
||||||
'color': 'green', #optional
|
|
||||||
'fill_to': 'senkou_b',
|
|
||||||
'fill_label': 'Ichimoku Cloud', #optional
|
|
||||||
'fill_color': 'rgba(255,76,46,0.2)', #optional
|
|
||||||
},
|
},
|
||||||
# plot senkou_b, too. Not only the area to it.
|
'subplots': {
|
||||||
'senkou_b': {}
|
# Create subplot MACD
|
||||||
}
|
"MACD": {
|
||||||
plot_config['subplots'] = {
|
'macd': {'color': 'blue', 'fill_to': 'macdhist'},
|
||||||
# Create subplot MACD
|
'macdsignal': {'color': 'orange'},
|
||||||
"MACD": {
|
'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}
|
||||||
'macd': {'color': 'blue', 'fill_to': 'macdhist'},
|
|
||||||
'macdsignal': {'color': 'orange'},
|
|
||||||
'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}
|
|
||||||
},
|
|
||||||
# Additional subplot RSI
|
|
||||||
"RSI": {
|
|
||||||
'rsi': {'color': 'red'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return plot_config
|
|
||||||
```
|
|
||||||
|
|
||||||
??? Note "As attribute (former method)"
|
|
||||||
Assigning plot_config is also possible as Attribute (this used to be the default way).
|
|
||||||
This has the disadvantage that strategy parameters are not available, preventing certain configurations from working.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
plot_config = {
|
|
||||||
'main_plot': {
|
|
||||||
# Configuration for main plot indicators.
|
|
||||||
# Specifies `ema10` to be red, and `ema50` to be a shade of gray
|
|
||||||
'ema10': {'color': 'red'},
|
|
||||||
'ema50': {'color': '#CCCCCC'},
|
|
||||||
# By omitting color, a random color is selected.
|
|
||||||
'sar': {},
|
|
||||||
# fill area between senkou_a and senkou_b
|
|
||||||
'senkou_a': {
|
|
||||||
'color': 'green', #optional
|
|
||||||
'fill_to': 'senkou_b',
|
|
||||||
'fill_label': 'Ichimoku Cloud', #optional
|
|
||||||
'fill_color': 'rgba(255,76,46,0.2)', #optional
|
|
||||||
},
|
},
|
||||||
# plot senkou_b, too. Not only the area to it.
|
# Additional subplot RSI
|
||||||
'senkou_b': {}
|
"RSI": {
|
||||||
},
|
'rsi': {'color': 'red'}
|
||||||
'subplots': {
|
|
||||||
# Create subplot MACD
|
|
||||||
"MACD": {
|
|
||||||
'macd': {'color': 'blue', 'fill_to': 'macdhist'},
|
|
||||||
'macdsignal': {'color': 'orange'},
|
|
||||||
'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}
|
|
||||||
},
|
|
||||||
# Additional subplot RSI
|
|
||||||
"RSI": {
|
|
||||||
'rsi': {'color': 'red'}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
The above configuration assumes that `ema10`, `ema50`, `senkou_a`, `senkou_b`,
|
The above configuration assumes that `ema10`, `ema50`, `senkou_a`, `senkou_b`,
|
||||||
@ -270,9 +223,6 @@ def plot_config(self):
|
|||||||
!!! Warning
|
!!! Warning
|
||||||
`plotly` arguments are only supported with plotly library and will not work with freq-ui.
|
`plotly` arguments are only supported with plotly library and will not work with freq-ui.
|
||||||
|
|
||||||
!!! Note "Trade position adjustments"
|
|
||||||
If `position_adjustment_enable` / `adjust_trade_position()` is used, the trade initial buy price is averaged over multiple orders and the trade start price will most likely appear outside the candle range.
|
|
||||||
|
|
||||||
## Plot profit
|
## Plot profit
|
||||||
|
|
||||||
![plot-profit](assets/plot-profit.png)
|
![plot-profit](assets/plot-profit.png)
|
||||||
@ -283,8 +233,6 @@ The `plot-profit` subcommand shows an interactive graph with three plots:
|
|||||||
* The summarized profit made by backtesting.
|
* The summarized profit made by backtesting.
|
||||||
Note that this is not the real-world profit, but more of an estimate.
|
Note that this is not the real-world profit, but more of an estimate.
|
||||||
* Profit for each individual pair.
|
* Profit for each individual pair.
|
||||||
* Parallelism of trades.
|
|
||||||
* Underwater (Periods of drawdown).
|
|
||||||
|
|
||||||
The first graph is good to get a grip of how the overall market progresses.
|
The first graph is good to get a grip of how the overall market progresses.
|
||||||
|
|
||||||
@ -294,8 +242,6 @@ This graph will also highlight the start (and end) of the Max drawdown period.
|
|||||||
|
|
||||||
The third graph can be useful to spot outliers, events in pairs that cause profit spikes.
|
The third graph can be useful to spot outliers, events in pairs that cause profit spikes.
|
||||||
|
|
||||||
The forth graph can help you analyze trade parallelism, showing how often max_open_trades have been maxed out.
|
|
||||||
|
|
||||||
Possible options for the `freqtrade plot-profit` subcommand:
|
Possible options for the `freqtrade plot-profit` subcommand:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -315,8 +261,8 @@ optional arguments:
|
|||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
--export EXPORT Export backtest results, argument are: trades.
|
--export EXPORT Export backtest results, argument are: trades.
|
||||||
Example: `--export=trades`
|
Example: `--export=trades`
|
||||||
--export-filename PATH, --backtest-filename PATH
|
--export-filename PATH
|
||||||
Use backtest results from this filename.
|
Save backtest results to the file with this filename.
|
||||||
Requires `--export` to be set as well. Example:
|
Requires `--export` to be set as well. Example:
|
||||||
`--export-filename=user_data/backtest_results/backtest
|
`--export-filename=user_data/backtest_results/backtest
|
||||||
_today.json`
|
_today.json`
|
||||||
@ -327,7 +273,7 @@ optional arguments:
|
|||||||
--trade-source {DB,file}
|
--trade-source {DB,file}
|
||||||
Specify the source for trades (Can be DB or file
|
Specify the source for trades (Can be DB or file
|
||||||
(backtest file)) Default: file
|
(backtest file)) Default: file
|
||||||
-i TIMEFRAME, --timeframe TIMEFRAME
|
-i TIMEFRAME, --timeframe TIMEFRAME, --ticker-interval TIMEFRAME
|
||||||
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).
|
||||||
--auto-open Automatically open generated plot.
|
--auto-open Automatically open generated plot.
|
||||||
|
|
||||||
|
@ -1,165 +0,0 @@
|
|||||||
# Producer / Consumer mode
|
|
||||||
|
|
||||||
freqtrade provides a mechanism whereby an instance (also called `consumer`) may listen to messages from an upstream freqtrade instance (also called `producer`) using the message websocket. Mainly, `analyzed_df` and `whitelist` messages. This allows the reuse of computed indicators (and signals) for pairs in multiple bots without needing to compute them multiple times.
|
|
||||||
|
|
||||||
See [Message Websocket](rest-api.md#message-websocket) in the Rest API docs for setting up the `api_server` configuration for your message websocket (this will be your producer).
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
We strongly recommend to set `ws_token` to something random and known only to yourself to avoid unauthorized access to your bot.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Enable subscribing to an instance by adding the `external_message_consumer` section to the consumer's config file.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
//...
|
|
||||||
"external_message_consumer": {
|
|
||||||
"enabled": true,
|
|
||||||
"producers": [
|
|
||||||
{
|
|
||||||
"name": "default", // This can be any name you'd like, default is "default"
|
|
||||||
"host": "127.0.0.1", // The host from your producer's api_server config
|
|
||||||
"port": 8080, // The port from your producer's api_server config
|
|
||||||
"secure": false, // Use a secure websockets connection, default false
|
|
||||||
"ws_token": "sercet_Ws_t0ken" // The ws_token from your producer's api_server config
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// The following configurations are optional, and usually not required
|
|
||||||
// "wait_timeout": 300,
|
|
||||||
// "ping_timeout": 10,
|
|
||||||
// "sleep_time": 10,
|
|
||||||
// "remove_entry_exit_signals": false,
|
|
||||||
// "message_size_limit": 8
|
|
||||||
}
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
| Parameter | Description |
|
|
||||||
|------------|-------------|
|
|
||||||
| `enabled` | **Required.** Enable consumer mode. If set to false, all other settings in this section are ignored.<br>*Defaults to `false`.*<br> **Datatype:** boolean .
|
|
||||||
| `producers` | **Required.** List of producers <br> **Datatype:** Array.
|
|
||||||
| `producers.name` | **Required.** Name of this producer. This name must be used in calls to `get_producer_pairs()` and `get_producer_df()` if more than one producer is used.<br> **Datatype:** string
|
|
||||||
| `producers.host` | **Required.** The hostname or IP address from your producer.<br> **Datatype:** string
|
|
||||||
| `producers.port` | **Required.** The port matching the above host.<br>*Defaults to `8080`.*<br> **Datatype:** Integer
|
|
||||||
| `producers.secure` | **Optional.** Use ssl in websockets connection. Default False.<br> **Datatype:** string
|
|
||||||
| `producers.ws_token` | **Required.** `ws_token` as configured on the producer.<br> **Datatype:** string
|
|
||||||
| | **Optional settings**
|
|
||||||
| `wait_timeout` | Timeout until we ping again if no message is received. <br>*Defaults to `300`.*<br> **Datatype:** Integer - in seconds.
|
|
||||||
| `ping_timeout` | Ping timeout <br>*Defaults to `10`.*<br> **Datatype:** Integer - in seconds.
|
|
||||||
| `sleep_time` | Sleep time before retrying to connect.<br>*Defaults to `10`.*<br> **Datatype:** Integer - in seconds.
|
|
||||||
| `remove_entry_exit_signals` | Remove signal columns from the dataframe (set them to 0) on dataframe receipt.<br>*Defaults to `False`.*<br> **Datatype:** Boolean.
|
|
||||||
| `message_size_limit` | Size limit per message<br>*Defaults to `8`.*<br> **Datatype:** Integer - Megabytes.
|
|
||||||
|
|
||||||
Instead of (or as well as) calculating indicators in `populate_indicators()` the follower instance listens on the connection to a producer instance's messages (or multiple producer instances in advanced configurations) and requests the producer's most recently analyzed dataframes for each pair in the active whitelist.
|
|
||||||
|
|
||||||
A consumer instance will then have a full copy of the analyzed dataframes without the need to calculate them itself.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Example - Producer Strategy
|
|
||||||
|
|
||||||
A simple strategy with multiple indicators. No special considerations are required in the strategy itself.
|
|
||||||
|
|
||||||
```py
|
|
||||||
class ProducerStrategy(IStrategy):
|
|
||||||
#...
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
"""
|
|
||||||
Calculate indicators in the standard freqtrade way which can then be broadcast to other instances
|
|
||||||
"""
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe)
|
|
||||||
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
|
|
||||||
dataframe['bb_lowerband'] = bollinger['lower']
|
|
||||||
dataframe['bb_middleband'] = bollinger['mid']
|
|
||||||
dataframe['bb_upperband'] = bollinger['upper']
|
|
||||||
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
"""
|
|
||||||
Populates the entry signal for the given dataframe
|
|
||||||
"""
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)) &
|
|
||||||
(dataframe['tema'] <= dataframe['bb_middleband']) &
|
|
||||||
(dataframe['tema'] > dataframe['tema'].shift(1)) &
|
|
||||||
(dataframe['volume'] > 0)
|
|
||||||
),
|
|
||||||
'enter_long'] = 1
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Tip "FreqAI"
|
|
||||||
You can use this to setup [FreqAI](freqai.md) on a powerful machine, while you run consumers on simple machines like raspberries, which can interpret the signals generated from the producer in different ways.
|
|
||||||
|
|
||||||
|
|
||||||
### Example - Consumer Strategy
|
|
||||||
|
|
||||||
A logically equivalent strategy which calculates no indicators itself, but will have the same analyzed dataframes available to make trading decisions based on the indicators calculated in the producer. In this example the consumer has the same entry criteria, however this is not necessary. The consumer may use different logic to enter/exit trades, and only use the indicators as specified.
|
|
||||||
|
|
||||||
```py
|
|
||||||
class ConsumerStrategy(IStrategy):
|
|
||||||
#...
|
|
||||||
process_only_new_candles = False # required for consumers
|
|
||||||
|
|
||||||
_columns_to_expect = ['rsi_default', 'tema_default', 'bb_middleband_default']
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
"""
|
|
||||||
Use the websocket api to get pre-populated indicators from another freqtrade instance.
|
|
||||||
Use `self.dp.get_producer_df(pair)` to get the dataframe
|
|
||||||
"""
|
|
||||||
pair = metadata['pair']
|
|
||||||
timeframe = self.timeframe
|
|
||||||
|
|
||||||
producer_pairs = self.dp.get_producer_pairs()
|
|
||||||
# You can specify which producer to get pairs from via:
|
|
||||||
# self.dp.get_producer_pairs("my_other_producer")
|
|
||||||
|
|
||||||
# This func returns the analyzed dataframe, and when it was analyzed
|
|
||||||
producer_dataframe, _ = self.dp.get_producer_df(pair)
|
|
||||||
# You can get other data if the producer makes it available:
|
|
||||||
# self.dp.get_producer_df(
|
|
||||||
# pair,
|
|
||||||
# timeframe="1h",
|
|
||||||
# candle_type=CandleType.SPOT,
|
|
||||||
# producer_name="my_other_producer"
|
|
||||||
# )
|
|
||||||
|
|
||||||
if not producer_dataframe.empty:
|
|
||||||
# If you plan on passing the producer's entry/exit signal directly,
|
|
||||||
# specify ffill=False or it will have unintended results
|
|
||||||
merged_dataframe = merge_informative_pair(dataframe, producer_dataframe,
|
|
||||||
timeframe, timeframe,
|
|
||||||
append_timeframe=False,
|
|
||||||
suffix="default")
|
|
||||||
return merged_dataframe
|
|
||||||
else:
|
|
||||||
dataframe[self._columns_to_expect] = 0
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
"""
|
|
||||||
Populates the entry signal for the given dataframe
|
|
||||||
"""
|
|
||||||
# Use the dataframe columns as if we calculated them ourselves
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_above(dataframe['rsi_default'], self.buy_rsi.value)) &
|
|
||||||
(dataframe['tema_default'] <= dataframe['bb_middleband_default']) &
|
|
||||||
(dataframe['tema_default'] > dataframe['tema_default'].shift(1)) &
|
|
||||||
(dataframe['volume'] > 0)
|
|
||||||
),
|
|
||||||
'enter_long'] = 1
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Tip "Using upstream signals"
|
|
||||||
By setting `remove_entry_exit_signals=false`, you can also use the producer's signals directly. They should be available as `enter_long_default` (assuming `suffix="default"` was used) - and can be used as either signal directly, or as additional indicator.
|
|
@ -1,6 +1,4 @@
|
|||||||
markdown==3.3.7
|
mkdocs==1.2.1
|
||||||
mkdocs==1.4.2
|
mkdocs-material==7.1.8
|
||||||
mkdocs-material==9.1.6
|
mdx_truly_sane_lists==1.2
|
||||||
mdx_truly_sane_lists==1.3
|
pymdown-extensions==8.2
|
||||||
pymdown-extensions==9.11
|
|
||||||
jinja2==3.1.2
|
|
||||||
|
184
docs/rest-api.md
@ -9,6 +9,9 @@ This same command can also be used to update freqUI, should there be a new relea
|
|||||||
|
|
||||||
Once the bot is started in trade / dry-run mode (with `freqtrade trade`) - the UI will be available under the configured port below (usually `http://127.0.0.1:8080`).
|
Once the bot is started in trade / dry-run mode (with `freqtrade trade`) - the UI will be available under the configured port below (usually `http://127.0.0.1:8080`).
|
||||||
|
|
||||||
|
!!! info "Alpha release"
|
||||||
|
FreqUI is still considered an alpha release - if you encounter bugs or inconsistencies please open a [FreqUI issue](https://github.com/freqtrade/frequi/issues/new/choose).
|
||||||
|
|
||||||
!!! Note "developers"
|
!!! Note "developers"
|
||||||
Developers should not use this method, but instead use the method described in the [freqUI repository](https://github.com/freqtrade/frequi) to get the source-code of freqUI.
|
Developers should not use this method, but instead use the method described in the [freqUI repository](https://github.com/freqtrade/frequi) to get the source-code of freqUI.
|
||||||
|
|
||||||
@ -28,19 +31,13 @@ Sample configuration:
|
|||||||
"jwt_secret_key": "somethingrandom",
|
"jwt_secret_key": "somethingrandom",
|
||||||
"CORS_origins": [],
|
"CORS_origins": [],
|
||||||
"username": "Freqtrader",
|
"username": "Freqtrader",
|
||||||
"password": "SuperSecret1!",
|
"password": "SuperSecret1!"
|
||||||
"ws_token": "sercet_Ws_t0ken"
|
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Danger "Security warning"
|
!!! Danger "Security warning"
|
||||||
By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet and choose a strong, unique password, since others will potentially be able to control your bot.
|
By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet and choose a strong, unique password, since others will potentially be able to control your bot.
|
||||||
|
|
||||||
??? Note "API/UI Access on a remote servers"
|
|
||||||
If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot.
|
|
||||||
This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box).
|
|
||||||
Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet.
|
|
||||||
|
|
||||||
You can then access the API by going to `http://127.0.0.1:8080/api/v1/ping` in a browser to check if the API is running correctly.
|
You can then access the API by going to `http://127.0.0.1:8080/api/v1/ping` in a browser to check if the API is running correctly.
|
||||||
This should return the response:
|
This should return the response:
|
||||||
|
|
||||||
@ -81,7 +78,7 @@ If you run your bot using docker, you'll need to have the bot listen to incoming
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure that the following 2 lines are available in your docker-compose file:
|
Uncomment the following from your docker-compose file:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
ports:
|
ports:
|
||||||
@ -91,6 +88,7 @@ Make sure that the following 2 lines are available in your docker-compose file:
|
|||||||
!!! Danger "Security warning"
|
!!! Danger "Security warning"
|
||||||
By using `8080:8080` in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot.
|
By using `8080:8080` in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot.
|
||||||
|
|
||||||
|
|
||||||
## Rest API
|
## Rest API
|
||||||
|
|
||||||
### Consuming the API
|
### Consuming the API
|
||||||
@ -142,10 +140,9 @@ python3 scripts/rest_client.py --config rest_config.json <command> [optional par
|
|||||||
| `locks` | Displays currently locked pairs.
|
| `locks` | Displays currently locked pairs.
|
||||||
| `delete_lock <lock_id>` | Deletes (disables) the lock by id.
|
| `delete_lock <lock_id>` | Deletes (disables) the lock by id.
|
||||||
| `profit` | Display a summary of your profit/loss from close trades and some stats about your performance.
|
| `profit` | Display a summary of your profit/loss from close trades and some stats about your performance.
|
||||||
| `forceexit <trade_id>` | Instantly exits the given trade (Ignoring `minimum_roi`).
|
| `forcesell <trade_id>` | Instantly sells the given trade (Ignoring `minimum_roi`).
|
||||||
| `forceexit all` | Instantly exits all open trades (Ignoring `minimum_roi`).
|
| `forcesell all` | Instantly sells all open trades (Ignoring `minimum_roi`).
|
||||||
| `forceenter <pair> [rate]` | Instantly enters the given pair. Rate is optional. (`force_entry_enable` must be set to True)
|
| `forcebuy <pair> [rate]` | Instantly buys the given pair. Rate is optional. (`forcebuy_enable` must be set to True)
|
||||||
| `forceenter <pair> <side> [rate]` | Instantly longs or shorts the given pair. Rate is optional. (`force_entry_enable` must be set to True)
|
|
||||||
| `performance` | Show performance of each finished trade grouped by pair.
|
| `performance` | Show performance of each finished trade grouped by pair.
|
||||||
| `balance` | Show account balance per currency.
|
| `balance` | Show account balance per currency.
|
||||||
| `daily <n>` | Shows profit or loss per day, over the last n days (n defaults to 7).
|
| `daily <n>` | Shows profit or loss per day, over the last n days (n defaults to 7).
|
||||||
@ -160,8 +157,6 @@ python3 scripts/rest_client.py --config rest_config.json <command> [optional par
|
|||||||
| `strategy <strategy>` | Get specific Strategy content. **Alpha**
|
| `strategy <strategy>` | Get specific Strategy content. **Alpha**
|
||||||
| `available_pairs` | List available backtest data. **Alpha**
|
| `available_pairs` | List available backtest data. **Alpha**
|
||||||
| `version` | Show version.
|
| `version` | Show version.
|
||||||
| `sysinfo` | Show information about the system load.
|
|
||||||
| `health` | Show bot health (last bot loop).
|
|
||||||
|
|
||||||
!!! Warning "Alpha status"
|
!!! Warning "Alpha status"
|
||||||
Endpoints labeled with *Alpha status* above may change at any time without notice.
|
Endpoints labeled with *Alpha status* above may change at any time without notice.
|
||||||
@ -189,11 +184,6 @@ blacklist
|
|||||||
|
|
||||||
:param add: List of coins to add (example: "BNB/BTC")
|
:param add: List of coins to add (example: "BNB/BTC")
|
||||||
|
|
||||||
cancel_open_order
|
|
||||||
Cancel open order for trade.
|
|
||||||
|
|
||||||
:param trade_id: Cancels open orders for this trade.
|
|
||||||
|
|
||||||
count
|
count
|
||||||
Return the amount of open trades.
|
Return the amount of open trades.
|
||||||
|
|
||||||
@ -220,22 +210,10 @@ forcebuy
|
|||||||
:param pair: Pair to buy (ETH/BTC)
|
:param pair: Pair to buy (ETH/BTC)
|
||||||
:param price: Optional - price to buy
|
:param price: Optional - price to buy
|
||||||
|
|
||||||
forceenter
|
forcesell
|
||||||
Force entering a trade
|
Force-sell a trade.
|
||||||
|
|
||||||
:param pair: Pair to buy (ETH/BTC)
|
|
||||||
:param side: 'long' or 'short'
|
|
||||||
:param price: Optional - price to buy
|
|
||||||
|
|
||||||
forceexit
|
|
||||||
Force-exit a trade.
|
|
||||||
|
|
||||||
:param tradeid: Id of the trade (can be received via status command)
|
:param tradeid: Id of the trade (can be received via status command)
|
||||||
:param ordertype: Order type to use (must be market or limit)
|
|
||||||
:param amount: Amount to sell. Full sell if not given
|
|
||||||
|
|
||||||
health
|
|
||||||
Provides a quick health check of the running bot.
|
|
||||||
|
|
||||||
locks
|
locks
|
||||||
Return current locks
|
Return current locks
|
||||||
@ -276,6 +254,7 @@ reload_config
|
|||||||
Reload configuration.
|
Reload configuration.
|
||||||
|
|
||||||
show_config
|
show_config
|
||||||
|
|
||||||
Returns part of the configuration, relevant for trading operations.
|
Returns part of the configuration, relevant for trading operations.
|
||||||
|
|
||||||
start
|
start
|
||||||
@ -301,9 +280,6 @@ strategy
|
|||||||
|
|
||||||
:param strategy: Strategy class name
|
:param strategy: Strategy class name
|
||||||
|
|
||||||
sysinfo
|
|
||||||
Provides system information (CPU, RAM usage)
|
|
||||||
|
|
||||||
trade
|
trade
|
||||||
Return specific trade
|
Return specific trade
|
||||||
|
|
||||||
@ -320,119 +296,12 @@ version
|
|||||||
|
|
||||||
whitelist
|
whitelist
|
||||||
Show the current whitelist.
|
Show the current whitelist.
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Message WebSocket
|
|
||||||
|
|
||||||
The API Server includes a websocket endpoint for subscribing to RPC messages from the freqtrade Bot.
|
|
||||||
This can be used to consume real-time data from your bot, such as entry/exit fill messages, whitelist changes, populated indicators for pairs, and more.
|
|
||||||
|
|
||||||
This is also used to setup [Producer/Consumer mode](producer-consumer.md) in Freqtrade.
|
|
||||||
|
|
||||||
Assuming your rest API is set to `127.0.0.1` on port `8080`, the endpoint is available at `http://localhost:8080/api/v1/message/ws`.
|
|
||||||
|
|
||||||
To access the websocket endpoint, the `ws_token` is required as a query parameter in the endpoint URL.
|
|
||||||
|
|
||||||
To generate a safe `ws_token` you can run the following code:
|
|
||||||
|
|
||||||
``` python
|
|
||||||
>>> import secrets
|
|
||||||
>>> secrets.token_urlsafe(25)
|
|
||||||
'hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q'
|
|
||||||
```
|
|
||||||
|
|
||||||
You would then add that token under `ws_token` in your `api_server` config. Like so:
|
|
||||||
|
|
||||||
``` json
|
|
||||||
"api_server": {
|
|
||||||
"enabled": true,
|
|
||||||
"listen_ip_address": "127.0.0.1",
|
|
||||||
"listen_port": 8080,
|
|
||||||
"verbosity": "error",
|
|
||||||
"enable_openapi": false,
|
|
||||||
"jwt_secret_key": "somethingrandom",
|
|
||||||
"CORS_origins": [],
|
|
||||||
"username": "Freqtrader",
|
|
||||||
"password": "SuperSecret1!",
|
|
||||||
"ws_token": "hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q" // <-----
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now connect to the endpoint at `http://localhost:8080/api/v1/message/ws?token=hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q`.
|
|
||||||
|
|
||||||
!!! Danger "Reuse of example tokens"
|
|
||||||
Please do not use the above example token. To make sure you are secure, generate a completely new token.
|
|
||||||
|
|
||||||
#### Using the WebSocket
|
|
||||||
|
|
||||||
Once connected to the WebSocket, the bot will broadcast RPC messages to anyone who is subscribed to them. To subscribe to a list of messages, you must send a JSON request through the WebSocket like the one below. The `data` key must be a list of message type strings.
|
|
||||||
|
|
||||||
``` json
|
|
||||||
{
|
|
||||||
"type": "subscribe",
|
|
||||||
"data": ["whitelist", "analyzed_df"] // A list of string message types
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
For a list of message types, please refer to the RPCMessageType enum in `freqtrade/enums/rpcmessagetype.py`
|
|
||||||
|
|
||||||
Now anytime those types of RPC messages are sent in the bot, you will receive them through the WebSocket as long as the connection is active. They typically take the same form as the request:
|
|
||||||
|
|
||||||
``` json
|
|
||||||
{
|
|
||||||
"type": "analyzed_df",
|
|
||||||
"data": {
|
|
||||||
"key": ["NEO/BTC", "5m", "spot"],
|
|
||||||
"df": {}, // The dataframe
|
|
||||||
"la": "2022-09-08 22:14:41.457786+00:00"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Reverse Proxy setup
|
|
||||||
|
|
||||||
When using [Nginx](https://nginx.org/en/docs/), the following configuration is required for WebSockets to work (Note this configuration is incomplete, it's missing some information and can not be used as is):
|
|
||||||
|
|
||||||
Please make sure to replace `<freqtrade_listen_ip>` (and the subsequent port) with the IP and Port matching your configuration/setup.
|
|
||||||
|
|
||||||
```
|
|
||||||
http {
|
|
||||||
map $http_upgrade $connection_upgrade {
|
|
||||||
default upgrade;
|
|
||||||
'' close;
|
|
||||||
}
|
|
||||||
|
|
||||||
#...
|
|
||||||
|
|
||||||
server {
|
|
||||||
#...
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_pass http://<freqtrade_listen_ip>:8080;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection $connection_upgrade;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To properly configure your reverse proxy (securely), please consult it's documentation for proxying websockets.
|
|
||||||
|
|
||||||
- **Traefik**: Traefik supports websockets out of the box, see the [documentation](https://doc.traefik.io/traefik/)
|
|
||||||
- **Caddy**: Caddy v2 supports websockets out of the box, see the [documentation](https://caddyserver.com/docs/v2-upgrade#proxy)
|
|
||||||
|
|
||||||
!!! Tip "SSL certificates"
|
|
||||||
You can use tools like certbot to setup ssl certificates to access your bot's UI through encrypted connection by using any fo the above reverse proxies.
|
|
||||||
While this will protect your data in transit, we do not recommend to run the freqtrade API outside of your private network (VPN, SSH tunnel).
|
|
||||||
|
|
||||||
### OpenAPI interface
|
### OpenAPI interface
|
||||||
|
|
||||||
To enable the builtin openAPI interface (Swagger UI), specify `"enable_openapi": true` in the api_server configuration.
|
To enable the builtin openAPI interface (Swagger UI), specify `"enable_openapi": true` in the api_server configuration.
|
||||||
This will enable the Swagger UI at the `/docs` endpoint. By default, that's running at http://localhost:8080/docs - but it'll depend on your settings.
|
This will enable the Swagger UI at the `/docs` endpoint. By default, that's running at http://localhost:8080/docs/ - but it'll depend on your settings.
|
||||||
|
|
||||||
### Advanced API usage using JWT tokens
|
### Advanced API usage using JWT tokens
|
||||||
|
|
||||||
@ -461,15 +330,12 @@ Since the access token has a short timeout (15 min) - the `token/refresh` reques
|
|||||||
|
|
||||||
### CORS
|
### CORS
|
||||||
|
|
||||||
This whole section is only necessary in cross-origin cases (where you multiple bot API's running on `localhost:8081`, `localhost:8082`, ...), and want to combine them into one FreqUI instance.
|
All web-based front-ends are subject to [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) - Cross-Origin Resource Sharing.
|
||||||
|
Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems.
|
||||||
|
Also, the standard disallows `*` CORS policies for requests with credentials, so this setting must be set appropriately.
|
||||||
|
|
||||||
??? info "Technical explanation"
|
Users can configure this themselves via the `CORS_origins` configuration setting.
|
||||||
All web-based front-ends are subject to [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) - Cross-Origin Resource Sharing.
|
It consists of a list of allowed sites that are allowed to consume resources from the bot's API.
|
||||||
Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems.
|
|
||||||
Also, the standard disallows `*` CORS policies for requests with credentials, so this setting must be set appropriately.
|
|
||||||
|
|
||||||
Users can allow access from different origin URL's to the bot API via the `CORS_origins` configuration setting.
|
|
||||||
It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.
|
|
||||||
|
|
||||||
Assuming your application is deployed as `https://frequi.freqtrade.io/home/` - this would mean that the following configuration becomes necessary:
|
Assuming your application is deployed as `https://frequi.freqtrade.io/home/` - this would mean that the following configuration becomes necessary:
|
||||||
|
|
||||||
@ -482,19 +348,5 @@ Assuming your application is deployed as `https://frequi.freqtrade.io/home/` - t
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In the following (pretty common) case, FreqUI is accessible on `http://localhost:8080/trade` (this is what you see in your navbar when navigating to freqUI).
|
|
||||||
![freqUI url](assets/frequi_url.png)
|
|
||||||
|
|
||||||
The correct configuration for this case is `http://localhost:8080` - the main part of the URL including the port.
|
|
||||||
|
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
//...
|
|
||||||
"jwt_secret_key": "somethingrandom",
|
|
||||||
"CORS_origins": ["http://localhost:8080"],
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
We strongly recommend to also set `jwt_secret_key` to something random and known only to yourself to avoid unauthorized access to your bot.
|
We strongly recommend to also set `jwt_secret_key` to something random and known only to yourself to avoid unauthorized access to your bot.
|
||||||
|
@ -104,16 +104,16 @@ To mitigate this, you can try to match the first order on the opposite orderbook
|
|||||||
|
|
||||||
``` jsonc
|
``` jsonc
|
||||||
"order_types": {
|
"order_types": {
|
||||||
"entry": "limit",
|
"buy": "limit",
|
||||||
"exit": "limit"
|
"sell": "limit"
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
"entry_pricing": {
|
"bid_strategy": {
|
||||||
"price_side": "other",
|
"price_side": "ask",
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
"exit_pricing":{
|
"ask_strategy":{
|
||||||
"price_side": "other",
|
"price_side": "bid",
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
@ -13,12 +13,12 @@ Feel free to use a visual Database editor like SqliteBrowser if you feel more co
|
|||||||
sudo apt-get install sqlite3
|
sudo apt-get install sqlite3
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using sqlite3 via docker
|
### Using sqlite3 via docker-compose
|
||||||
|
|
||||||
The freqtrade docker image does contain sqlite3, so you can edit the database without having to install anything on the host system.
|
The freqtrade docker image does contain sqlite3, so you can edit the database without having to install anything on the host system.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
docker compose exec freqtrade /bin/bash
|
docker-compose exec freqtrade /bin/bash
|
||||||
sqlite3 <database-file>.sqlite
|
sqlite3 <database-file>.sqlite
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -49,14 +49,14 @@ sqlite3
|
|||||||
SELECT * FROM trades;
|
SELECT * FROM trades;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Fix trade still open after a manual exit on the exchange
|
## Fix trade still open after a manual sell on the exchange
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
Manually selling a pair on the exchange will not be detected by the bot and it will try to sell anyway. Whenever possible, /forceexit <tradeid> should be used to accomplish the same thing.
|
Manually selling a pair on the exchange will not be detected by the bot and it will try to sell anyway. Whenever possible, forcesell <tradeid> should be used to accomplish the same thing.
|
||||||
It is strongly advised to backup your database file before making any manual changes.
|
It is strongly advised to backup your database file before making any manual changes.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
This should not be necessary after /forceexit, as force_exit orders are closed automatically by the bot on the next iteration.
|
This should not be necessary after /forcesell, as forcesell orders are closed automatically by the bot on the next iteration.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
UPDATE trades
|
UPDATE trades
|
||||||
@ -65,7 +65,7 @@ SET is_open=0,
|
|||||||
close_rate=<close_rate>,
|
close_rate=<close_rate>,
|
||||||
close_profit = close_rate / open_rate - 1,
|
close_profit = close_rate / open_rate - 1,
|
||||||
close_profit_abs = (amount * <close_rate> * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),
|
close_profit_abs = (amount * <close_rate> * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),
|
||||||
exit_reason=<exit_reason>
|
sell_reason=<sell_reason>
|
||||||
WHERE id=<trade_ID_to_update>;
|
WHERE id=<trade_ID_to_update>;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ SET is_open=0,
|
|||||||
close_rate=0.19638016,
|
close_rate=0.19638016,
|
||||||
close_profit=0.0496,
|
close_profit=0.0496,
|
||||||
close_profit_abs = (amount * 0.19638016 * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),
|
close_profit_abs = (amount * 0.19638016 * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),
|
||||||
exit_reason='force_exit'
|
sell_reason='force_sell'
|
||||||
WHERE id=31;
|
WHERE id=31;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -89,12 +89,11 @@ WHERE id=31;
|
|||||||
|
|
||||||
If you'd still like to remove a trade from the database directly, you can use the below query.
|
If you'd still like to remove a trade from the database directly, you can use the below query.
|
||||||
|
|
||||||
!!! Danger
|
|
||||||
Some systems (Ubuntu) disable foreign keys in their sqlite3 packaging. When using sqlite - please ensure that foreign keys are on by running `PRAGMA foreign_keys = ON` before the above query.
|
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
DELETE FROM trades WHERE id = <tradeid>;
|
DELETE FROM trades WHERE id = <tradeid>;
|
||||||
|
```
|
||||||
|
|
||||||
|
```sql
|
||||||
DELETE FROM trades WHERE id = 31;
|
DELETE FROM trades WHERE id = 31;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -103,22 +102,15 @@ DELETE FROM trades WHERE id = 31;
|
|||||||
|
|
||||||
## Use a different database system
|
## Use a different database system
|
||||||
|
|
||||||
Freqtrade is using SQLAlchemy, which supports multiple different database systems. As such, a multitude of database systems should be supported.
|
|
||||||
Freqtrade does not depend or install any additional database driver. Please refer to the [SQLAlchemy docs](https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls) on installation instructions for the respective database systems.
|
|
||||||
|
|
||||||
The following systems have been tested and are known to work with freqtrade:
|
|
||||||
|
|
||||||
* sqlite (default)
|
|
||||||
* PostgreSQL)
|
|
||||||
* MariaDB
|
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
By using one of the below database systems, you acknowledge that you know how to manage such a system. The freqtrade team will not provide any support with setup or maintenance (or backups) of the below database systems.
|
By using one of the below database systems, you acknowledge that you know how to manage such a system. Freqtrade will not provide any support with setup or maintenance (or backups) of the below database systems.
|
||||||
|
|
||||||
### PostgreSQL
|
### PostgreSQL
|
||||||
|
|
||||||
|
Freqtrade supports PostgreSQL by using SQLAlchemy, which supports multiple different database systems.
|
||||||
|
|
||||||
Installation:
|
Installation:
|
||||||
`pip install psycopg2-binary`
|
`pip install psycopg2`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
`... --db-url postgresql+psycopg2://<username>:<password>@localhost:5432/<database>`
|
`... --db-url postgresql+psycopg2://<username>:<password>@localhost:5432/<database>`
|
||||||
|
107
docs/stoploss.md
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
The `stoploss` configuration parameter is loss as ratio that should trigger a sale.
|
The `stoploss` configuration parameter is loss as ratio 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.
|
For example, value `-0.10` will cause immediate sell if the profit dips below -10% for a given trade. This parameter is optional.
|
||||||
Stoploss calculations do include fees, so a stoploss of -10% is placed exactly 10% below the entry point.
|
|
||||||
|
|
||||||
Most of the strategy files already include the optimal `stoploss` value.
|
Most of the strategy files already include the optimal `stoploss` value.
|
||||||
|
|
||||||
@ -17,33 +16,21 @@ Those stoploss modes can be *on exchange* or *off exchange*.
|
|||||||
These modes can be configured with these values:
|
These modes can be configured with these values:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
'emergency_exit': 'market',
|
'emergencysell': 'market',
|
||||||
'stoploss_on_exchange': False
|
'stoploss_on_exchange': False
|
||||||
'stoploss_on_exchange_interval': 60,
|
'stoploss_on_exchange_interval': 60,
|
||||||
'stoploss_on_exchange_limit_ratio': 0.99
|
'stoploss_on_exchange_limit_ratio': 0.99
|
||||||
```
|
```
|
||||||
|
|
||||||
Stoploss on exchange is only supported for the following exchanges, and not all exchanges support both stop-limit and stop-market.
|
!!! Note
|
||||||
The Order-type will be ignored if only one mode is available.
|
Stoploss on exchange is only supported for Binance (stop-loss-limit), Kraken (stop-loss-market, stop-loss-limit) and FTX (stop limit and stop-market) as of now.
|
||||||
|
<ins>Do not set too low/tight stoploss value if using stop loss on exchange!</ins>
|
||||||
| Exchange | stop-loss type |
|
If set to low/tight then you have greater risk of missing fill on the order and stoploss will not work.
|
||||||
|----------|-------------|
|
|
||||||
| Binance | limit |
|
|
||||||
| Binance Futures | market, limit |
|
|
||||||
| Huobi | limit |
|
|
||||||
| kraken | market, limit |
|
|
||||||
| Gate | limit |
|
|
||||||
| Okx | limit |
|
|
||||||
| Kucoin | stop-limit, stop-market|
|
|
||||||
|
|
||||||
!!! Note "Tight stoploss"
|
|
||||||
<ins>Do not set too low/tight stoploss value when using stop loss on exchange!</ins>
|
|
||||||
If set to low/tight you will have greater risk of missing fill on the order and stoploss will not work.
|
|
||||||
|
|
||||||
### stoploss_on_exchange and stoploss_on_exchange_limit_ratio
|
### stoploss_on_exchange and stoploss_on_exchange_limit_ratio
|
||||||
|
|
||||||
Enable or Disable stop loss on exchange.
|
Enable or Disable stop loss on exchange.
|
||||||
If the stoploss is *on exchange* it means a stoploss limit order is placed on the exchange immediately after buy order fills. This will protect you against sudden crashes in market, as the order execution happens purely within the exchange, and has no potential network overhead.
|
If the stoploss is *on exchange* it means a stoploss limit order is placed on the exchange immediately after buy order happens successfully. This will protect you against sudden crashes in market as the order will be in the queue immediately and if market goes down then the order has more chance of being fulfilled.
|
||||||
|
|
||||||
If `stoploss_on_exchange` uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price.
|
If `stoploss_on_exchange` uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price.
|
||||||
`stoploss` defines the stop-price where the limit order is placed - and limit should be slightly below this.
|
`stoploss` defines the stop-price where the limit order is placed - and limit should be slightly below this.
|
||||||
@ -64,42 +51,30 @@ The bot cannot do these every 5 seconds (at each iteration), otherwise it would
|
|||||||
So this parameter will tell the bot how often it should update the stoploss order. The default value is 60 (1 minute).
|
So this parameter will tell the bot how often it should update the stoploss order. The default value is 60 (1 minute).
|
||||||
This same logic will reapply a stoploss order on the exchange should you cancel it accidentally.
|
This same logic will reapply a stoploss order on the exchange should you cancel it accidentally.
|
||||||
|
|
||||||
### stoploss_price_type
|
### forcesell
|
||||||
|
|
||||||
!!! Warning "Only applies to futures"
|
`forcesell` is an optional value, which defaults to the same value as `sell` and is used when sending a `/forcesell` command from Telegram or from the Rest API.
|
||||||
`stoploss_price_type` only applies to futures markets (on exchanges where it's available).
|
|
||||||
Freqtrade will perform a validation of this setting on startup, failing to start if an invalid setting for your exchange has been selected.
|
|
||||||
Supported price types are gonna differs between each exchanges. Please check with your exchange on which price types it supports.
|
|
||||||
|
|
||||||
Stoploss on exchange on futures markets can trigger on different price types.
|
### forcebuy
|
||||||
The naming for these prices in exchange terminology often varies, but is usually something around "last" (or "contract price" ), "mark" and "index".
|
|
||||||
|
|
||||||
Acceptable values for this setting are `"last"`, `"mark"` and `"index"` - which freqtrade will transfer automatically to the corresponding API type, and place the [stoploss on exchange](#stoploss_on_exchange-and-stoploss_on_exchange_limit_ratio) order correspondingly.
|
`forcebuy` is an optional value, which defaults to the same value as `buy` and is used when sending a `/forcebuy` command from Telegram or from the Rest API.
|
||||||
|
|
||||||
### force_exit
|
### emergencysell
|
||||||
|
|
||||||
`force_exit` is an optional value, which defaults to the same value as `exit` and is used when sending a `/forceexit` command from Telegram or from the Rest API.
|
`emergencysell` is an optional value, which defaults to `market` and is used when creating stop loss on exchange orders fails.
|
||||||
|
|
||||||
### force_entry
|
|
||||||
|
|
||||||
`force_entry` is an optional value, which defaults to the same value as `entry` and is used when sending a `/forceentry` command from Telegram or from the Rest API.
|
|
||||||
|
|
||||||
### emergency_exit
|
|
||||||
|
|
||||||
`emergency_exit` is an optional value, which defaults to `market` and is used when creating stop loss on exchange orders fails.
|
|
||||||
The below is the default which is used if not changed in strategy or configuration file.
|
The below is the default which is used if not changed in strategy or configuration file.
|
||||||
|
|
||||||
Example from strategy file:
|
Example from strategy file:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
order_types = {
|
order_types = {
|
||||||
"entry": "limit",
|
'buy': 'limit',
|
||||||
"exit": "limit",
|
'sell': 'limit',
|
||||||
"emergency_exit": "market",
|
'emergencysell': 'market',
|
||||||
"stoploss": "market",
|
'stoploss': 'market',
|
||||||
"stoploss_on_exchange": True,
|
'stoploss_on_exchange': True,
|
||||||
"stoploss_on_exchange_interval": 60,
|
'stoploss_on_exchange_interval': 60,
|
||||||
"stoploss_on_exchange_limit_ratio": 0.99
|
'stoploss_on_exchange_limit_ratio': 0.99
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -111,7 +86,7 @@ At this stage the bot contains the following stoploss support modes:
|
|||||||
2. Trailing stop loss.
|
2. Trailing stop loss.
|
||||||
3. Trailing stop loss, custom positive loss.
|
3. Trailing stop loss, custom positive loss.
|
||||||
4. Trailing stop loss only once the trade has reached a certain offset.
|
4. Trailing stop loss only once the trade has reached a certain offset.
|
||||||
5. [Custom stoploss function](strategy-callbacks.md#custom-stoploss)
|
5. [Custom stoploss function](strategy-advanced.md#custom-stoploss)
|
||||||
|
|
||||||
### Static Stop Loss
|
### Static Stop Loss
|
||||||
|
|
||||||
@ -154,7 +129,7 @@ In summary: The stoploss will be adjusted to be always be -10% of the highest ob
|
|||||||
|
|
||||||
### Trailing stop loss, custom positive loss
|
### Trailing stop loss, custom positive loss
|
||||||
|
|
||||||
You could also have a default stop loss when you are in the red with your buy (buy - fee), but once you hit a positive result (or an offset you define) the system will utilize a new stop loss, which can have a different value.
|
It is also possible to have a default stop loss, when you are in the red with your buy (buy - fee), but once you hit positive result the system will utilize a new stop loss, which can have a different value.
|
||||||
For example, your default stop loss is -10%, but once you have more than 0% profit (example 0.1%) a different trailing stoploss will be used.
|
For example, your default stop loss is -10%, but once you have more than 0% profit (example 0.1%) a different trailing stoploss will be used.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
@ -166,8 +141,6 @@ Both values require `trailing_stop` to be set to true and `trailing_stop_positiv
|
|||||||
stoploss = -0.10
|
stoploss = -0.10
|
||||||
trailing_stop = True
|
trailing_stop = True
|
||||||
trailing_stop_positive = 0.02
|
trailing_stop_positive = 0.02
|
||||||
trailing_stop_positive_offset = 0.0
|
|
||||||
trailing_only_offset_is_reached = False # Default - not necessary for this example
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For example, simplified math:
|
For example, simplified math:
|
||||||
@ -182,31 +155,11 @@ For example, simplified math:
|
|||||||
The 0.02 would translate to a -2% stop loss.
|
The 0.02 would translate to a -2% stop loss.
|
||||||
Before this, `stoploss` is used for the trailing stoploss.
|
Before this, `stoploss` is used for the trailing stoploss.
|
||||||
|
|
||||||
!!! Tip "Use an offset to change your stoploss"
|
|
||||||
Use `trailing_stop_positive_offset` to ensure that your new trailing stoploss will be in profit by setting `trailing_stop_positive_offset` higher than `trailing_stop_positive`. Your first new stoploss value will then already have locked in profits.
|
|
||||||
|
|
||||||
Example with simplified math:
|
|
||||||
|
|
||||||
``` python
|
|
||||||
stoploss = -0.10
|
|
||||||
trailing_stop = True
|
|
||||||
trailing_stop_positive = 0.02
|
|
||||||
trailing_stop_positive_offset = 0.03
|
|
||||||
```
|
|
||||||
|
|
||||||
* the bot buys an asset at a price of 100$
|
|
||||||
* the stop loss is defined at -10%, so the stop loss would get triggered once the asset drops below 90$
|
|
||||||
* assuming the asset now increases to 102$
|
|
||||||
* the stoploss will now be at 91.8$ - 10% below the highest observed rate
|
|
||||||
* assuming the asset now increases to 103.5$ (above the offset configured)
|
|
||||||
* the stop loss will now be -2% of 103.5$ = 101.43$
|
|
||||||
* now the asset drops in value to 102\$, the stop loss will still be 101.43$ and would trigger once price breaks below 101.43$
|
|
||||||
|
|
||||||
### Trailing stop loss only once the trade has reached a certain offset
|
### Trailing stop loss only once the trade has reached a certain offset
|
||||||
|
|
||||||
You can also keep a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.
|
It is also possible to use a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.
|
||||||
|
|
||||||
If `trailing_only_offset_is_reached = True` then the trailing stoploss is only activated once the offset is reached. Until then, the stoploss remains at the configured `stoploss`.
|
If `"trailing_only_offset_is_reached": true` then the trailing stoploss is only activated once the offset is reached. Until then, the stoploss remains at the configured `stoploss`.
|
||||||
This option can be used with or without `trailing_stop_positive`, but uses `trailing_stop_positive_offset` as offset.
|
This option can be used with or without `trailing_stop_positive`, but uses `trailing_stop_positive_offset` as offset.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@ -229,7 +182,7 @@ For example, simplified math:
|
|||||||
* the bot buys an asset at a price of 100$
|
* the bot buys an asset at a price of 100$
|
||||||
* the stop loss is defined at -10%
|
* the stop loss is defined at -10%
|
||||||
* the stop loss would get triggered once the asset drops below 90$
|
* the stop loss would get triggered once the asset drops below 90$
|
||||||
* stoploss will remain at 90$ unless asset increases to or above the configured offset
|
* stoploss will remain at 90$ unless asset increases to or above our configured offset
|
||||||
* assuming the asset now increases to 103$ (where we have the offset configured)
|
* assuming the asset now increases to 103$ (where we have the offset configured)
|
||||||
* the stop loss will now be -2% of 103$ = 100.94$
|
* the stop loss will now be -2% of 103$ = 100.94$
|
||||||
* now the asset drops in value to 101\$, the stop loss will still be 100.94$ and would trigger at 100.94$
|
* now the asset drops in value to 101\$, the stop loss will still be 100.94$ and would trigger at 100.94$
|
||||||
@ -237,18 +190,6 @@ For example, simplified math:
|
|||||||
!!! Tip
|
!!! Tip
|
||||||
Make sure to have this value (`trailing_stop_positive_offset`) lower than minimal ROI, otherwise minimal ROI will apply first and sell the trade.
|
Make sure to have this value (`trailing_stop_positive_offset`) lower than minimal ROI, otherwise minimal ROI will apply first and sell the trade.
|
||||||
|
|
||||||
## Stoploss and Leverage
|
|
||||||
|
|
||||||
Stoploss should be thought of as "risk on this trade" - so a stoploss of 10% on a 100$ trade means you are willing to lose 10$ (10%) on this trade - which would trigger if the price moves 10% to the downside.
|
|
||||||
|
|
||||||
When using leverage, the same principle is applied - with stoploss defining the risk on the trade (the amount you are willing to lose).
|
|
||||||
|
|
||||||
Therefore, a stoploss of 10% on a 10x trade would trigger on a 1% price move.
|
|
||||||
If your stake amount (own capital) was 100$ - this trade would be 1000$ at 10x (after leverage).
|
|
||||||
If price moves 1% - you've lost 10$ of your own capital - therfore stoploss will trigger in this case.
|
|
||||||
|
|
||||||
Make sure to be aware of this, and avoid using too tight stoploss (at 10x leverage, 10% risk may be too little to allow the trade to "breath" a little).
|
|
||||||
|
|
||||||
## Changing stoploss on open trades
|
## Changing stoploss on open trades
|
||||||
|
|
||||||
A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the `/reload_config` command (alternatively, completely stopping and restarting the bot also works).
|
A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the `/reload_config` command (alternatively, completely stopping and restarting the bot also works).
|
||||||
|
@ -49,13 +49,13 @@ from freqtrade.exchange import timeframe_to_prev_date
|
|||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
class AwesomeStrategy(IStrategy):
|
||||||
def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,
|
def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,
|
||||||
rate: float, time_in_force: str, exit_reason: str,
|
rate: float, time_in_force: str, sell_reason: str,
|
||||||
current_time: 'datetime', **kwargs) -> bool:
|
current_time: 'datetime', **kwargs) -> bool:
|
||||||
# Obtain pair dataframe.
|
# Obtain pair dataframe.
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||||
|
|
||||||
# Obtain last available candle. Do not use current_time to look up latest candle, because
|
# Obtain last available candle. Do not use current_time to look up latest candle, because
|
||||||
# current_time points to current incomplete candle whose data is not available.
|
# current_time points to curret incomplete candle whose data is not available.
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
# <...>
|
# <...>
|
||||||
|
|
||||||
@ -77,82 +77,457 @@ class AwesomeStrategy(IStrategy):
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
## Enter Tag
|
## Custom sell signal
|
||||||
|
|
||||||
When your strategy has multiple buy signals, you can name the signal that triggered.
|
It is possible to define custom sell signals, indicating that specified position should be sold. This is very useful when we need to customize sell conditions for each individual trade, or if you need the trade profit to take the sell decision.
|
||||||
Then you can access your buy signal on `custom_exit`
|
|
||||||
|
|
||||||
```python
|
For example you could implement a 1:2 risk-reward ROI with `custom_sell()`.
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(dataframe['rsi'] < 35) &
|
|
||||||
(dataframe['volume'] > 0)
|
|
||||||
),
|
|
||||||
['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')
|
|
||||||
|
|
||||||
return dataframe
|
Using custom_sell() signals in place of stoplosses though *is not recommended*. It is a inferior method to using `custom_stoploss()` in this regard - which also allows you to keep the stoploss on exchange.
|
||||||
|
|
||||||
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
|
||||||
current_profit: float, **kwargs):
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
if trade.enter_tag == 'buy_signal_rsi' and last_candle['rsi'] > 80:
|
|
||||||
return 'sell_signal_rsi'
|
|
||||||
return None
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
`enter_tag` is limited to 100 characters, remaining data will be truncated.
|
Returning a `string` or `True` from this method is equal to setting sell signal on a candle at specified time. This method is not called when sell signal is set already, or if sell signals are disabled (`use_sell_signal=False` or `sell_profit_only=True` while profit is below `sell_profit_offset`). `string` max length is 64 characters. Exceeding this limit will cause the message to be truncated to 64 characters.
|
||||||
|
|
||||||
!!! Warning
|
An example of how we can use different indicators depending on the current profit and also sell trades that were open longer than one day:
|
||||||
There is only one `enter_tag` column, which is used for both long and short trades.
|
|
||||||
As a consequence, this column must be treated as "last write wins" (it's just a dataframe column after all).
|
|
||||||
In fancy situations, where multiple signals collide (or if signals are deactivated again based on different conditions), this can lead to odd results with the wrong tag applied to an entry signal.
|
|
||||||
These results are a consequence of the strategy overwriting prior tags - where the last tag will "stick" and will be the one freqtrade will use.
|
|
||||||
|
|
||||||
## Exit tag
|
|
||||||
|
|
||||||
Similar to [Buy Tagging](#buy-tag), you can also specify a sell tag.
|
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
class AwesomeStrategy(IStrategy):
|
||||||
dataframe.loc[
|
def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
||||||
(
|
current_profit: float, **kwargs):
|
||||||
(dataframe['rsi'] > 70) &
|
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||||
(dataframe['volume'] > 0)
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
),
|
|
||||||
['exit_long', 'exit_tag']] = (1, 'exit_rsi')
|
|
||||||
|
|
||||||
return dataframe
|
# Above 20% profit, sell when rsi < 80
|
||||||
|
if current_profit > 0.2:
|
||||||
|
if last_candle['rsi'] < 80:
|
||||||
|
return 'rsi_below_80'
|
||||||
|
|
||||||
|
# Between 2% and 10%, sell if EMA-long above EMA-short
|
||||||
|
if 0.02 < current_profit < 0.1:
|
||||||
|
if last_candle['emalong'] > last_candle['emashort']:
|
||||||
|
return 'ema_long_below_80'
|
||||||
|
|
||||||
|
# Sell any positions at a loss if they are held for more than one day.
|
||||||
|
if current_profit < 0.0 and (current_time - trade.open_date_utc).days >= 1:
|
||||||
|
return 'unclog'
|
||||||
```
|
```
|
||||||
|
|
||||||
The provided exit-tag is then used as sell-reason - and shown as such in backtest results.
|
See [Dataframe access](#dataframe-access) for more information about dataframe use in strategy callbacks.
|
||||||
|
|
||||||
!!! Note
|
## Custom stoploss
|
||||||
`exit_reason` is limited to 100 characters, remaining data will be truncated.
|
|
||||||
|
|
||||||
## Strategy version
|
The stoploss price can only ever move upwards - if the stoploss value returned from `custom_stoploss` would result in a lower stoploss price than was previously set, it will be ignored. The traditional `stoploss` value serves as an absolute lower level and will be instated as the initial stoploss.
|
||||||
|
|
||||||
You can implement custom strategy versioning by using the "version" method, and returning the version you would like this strategy to have.
|
The usage of the custom stoploss method must be enabled by setting `use_custom_stoploss=True` on the strategy object.
|
||||||
|
The method must return a stoploss value (float / number) as a percentage of the current price.
|
||||||
|
E.g. If the `current_rate` is 200 USD, then returning `0.02` will set the stoploss price 2% lower, at 196 USD.
|
||||||
|
|
||||||
|
The absolute value of the return value is used (the sign is ignored), so returning `0.05` or `-0.05` have the same result, a stoploss 5% below the current price.
|
||||||
|
|
||||||
|
To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum reached price) you would use the following very simple method:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
def version(self) -> str:
|
# additional imports required
|
||||||
"""
|
from datetime import datetime
|
||||||
Returns version of the strategy.
|
from freqtrade.persistence import Trade
|
||||||
"""
|
|
||||||
return "1.1"
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
"""
|
||||||
|
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
||||||
|
e.g. returning -0.05 would create a stoploss 5% below current_rate.
|
||||||
|
The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.
|
||||||
|
|
||||||
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
|
When not implemented by a strategy, returns the initial stoploss value
|
||||||
|
Only called when use_custom_stoploss is set to True.
|
||||||
|
|
||||||
|
:param pair: Pair that's currently analyzed
|
||||||
|
:param trade: trade object.
|
||||||
|
:param current_time: datetime object, containing the current datetime
|
||||||
|
:param current_rate: Rate, calculated based on pricing settings in ask_strategy.
|
||||||
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
||||||
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
|
:return float: New stoploss value, relative to the current rate
|
||||||
|
"""
|
||||||
|
return -0.04
|
||||||
|
```
|
||||||
|
|
||||||
|
Stoploss on exchange works similar to `trailing_stop`, and the stoploss on exchange is updated as configured in `stoploss_on_exchange_interval` ([More details about stoploss on exchange](stoploss.md#stop-loss-on-exchange-freqtrade)).
|
||||||
|
|
||||||
|
!!! Note "Use of dates"
|
||||||
|
All time-based calculations should be done based on `current_time` - using `datetime.now()` or `datetime.utcnow()` is discouraged, as this will break backtesting support.
|
||||||
|
|
||||||
|
!!! Tip "Trailing stoploss"
|
||||||
|
It's recommended to disable `trailing_stop` when using custom stoploss values. Both can work in tandem, but you might encounter the trailing stop to move the price higher while your custom function would not want this, causing conflicting behavior.
|
||||||
|
|
||||||
|
### Custom stoploss examples
|
||||||
|
|
||||||
|
The next section will show some examples on what's possible with the custom stoploss function.
|
||||||
|
Of course, many more things are possible, and all examples can be combined at will.
|
||||||
|
|
||||||
|
#### Time based trailing stop
|
||||||
|
|
||||||
|
Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
|
||||||
|
# Make sure you have the longest interval first - these conditions are evaluated from top to bottom.
|
||||||
|
if current_time - timedelta(minutes=120) > trade.open_date_utc:
|
||||||
|
return -0.05
|
||||||
|
elif current_time - timedelta(minutes=60) > trade.open_date_utc:
|
||||||
|
return -0.10
|
||||||
|
return 1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Different stoploss per pair
|
||||||
|
|
||||||
|
Use a different stoploss depending on the pair.
|
||||||
|
In this example, we'll trail the highest price with 10% trailing stoploss for `ETH/BTC` and `XRP/BTC`, with 5% trailing stoploss for `LTC/BTC` and with 15% for all other pairs.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
|
||||||
|
if pair in ('ETH/BTC', 'XRP/BTC'):
|
||||||
|
return -0.10
|
||||||
|
elif pair in ('LTC/BTC'):
|
||||||
|
return -0.05
|
||||||
|
return -0.15
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Trailing stoploss with positive offset
|
||||||
|
|
||||||
|
Use the initial stoploss until the profit is above 4%, then use a trailing stoploss of 50% of the current profit with a minimum of 2.5% and a maximum of 5%.
|
||||||
|
|
||||||
|
Please note that the stoploss can only increase, values lower than the current stoploss are ignored.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
|
||||||
|
if current_profit < 0.04:
|
||||||
|
return -1 # return a value bigger than the inital stoploss to keep using the inital stoploss
|
||||||
|
|
||||||
|
# After reaching the desired offset, allow the stoploss to trail by half the profit
|
||||||
|
desired_stoploss = current_profit / 2
|
||||||
|
|
||||||
|
# Use a minimum of 2.5% and a maximum of 5%
|
||||||
|
return max(min(desired_stoploss, 0.05), 0.025)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Calculating stoploss relative to open price
|
||||||
|
|
||||||
|
Stoploss values returned from `custom_stoploss()` always specify a percentage relative to `current_rate`. In order to set a stoploss relative to the *open* price, we need to use `current_profit` to calculate what percentage relative to the `current_rate` will give you the same result as if the percentage was specified from the open price.
|
||||||
|
|
||||||
|
The helper function [`stoploss_from_open()`](strategy-customization.md#stoploss_from_open) can be used to convert from an open price relative stop, to a current price relative stop which can be returned from `custom_stoploss()`.
|
||||||
|
|
||||||
|
#### Stepped stoploss
|
||||||
|
|
||||||
|
Instead of continuously trailing behind the current price, this example sets fixed stoploss price levels based on the current profit.
|
||||||
|
|
||||||
|
* Use the regular stoploss until 20% profit is reached
|
||||||
|
* Once profit is > 20% - set stoploss to 7% above open price.
|
||||||
|
* Once profit is > 25% - set stoploss to 15% above open price.
|
||||||
|
* Once profit is > 40% - set stoploss to 25% above open price.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
from freqtrade.strategy import stoploss_from_open
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
|
||||||
|
# evaluate highest to lowest, so that highest possible stop is used
|
||||||
|
if current_profit > 0.40:
|
||||||
|
return stoploss_from_open(0.25, current_profit)
|
||||||
|
elif current_profit > 0.25:
|
||||||
|
return stoploss_from_open(0.15, current_profit)
|
||||||
|
elif current_profit > 0.20:
|
||||||
|
return stoploss_from_open(0.07, current_profit)
|
||||||
|
|
||||||
|
# return maximum stoploss value, keeping current stoploss price unchanged
|
||||||
|
return 1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Custom stoploss using an indicator from dataframe example
|
||||||
|
|
||||||
|
Absolute stoploss value may be derived from indicators stored in dataframe. Example uses parabolic SAR below the price as stoploss.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
# <...>
|
||||||
|
dataframe['sar'] = ta.SAR(dataframe)
|
||||||
|
|
||||||
|
use_custom_stoploss = True
|
||||||
|
|
||||||
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||||
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
||||||
|
|
||||||
|
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||||
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
|
|
||||||
|
# Use parabolic sar as absolute stoploss price
|
||||||
|
stoploss_price = last_candle['sar']
|
||||||
|
|
||||||
|
# Convert absolute price to percentage relative to current_rate
|
||||||
|
if stoploss_price < current_rate:
|
||||||
|
return (stoploss_price / current_rate) - 1
|
||||||
|
|
||||||
|
# return maximum stoploss value, keeping current stoploss price unchanged
|
||||||
|
return 1
|
||||||
|
```
|
||||||
|
|
||||||
|
See [Dataframe access](#dataframe-access) for more information about dataframe use in strategy callbacks.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Custom order timeout rules
|
||||||
|
|
||||||
|
Simple, time-based order-timeouts can be configured either via strategy or in the configuration in the `unfilledtimeout` section.
|
||||||
|
|
||||||
|
However, freqtrade also offers a custom callback for both order types, which allows you to decide based on custom criteria if an order did time out or not.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Unfilled order timeouts are not relevant during backtesting or hyperopt, and are only relevant during real (live) trading. Therefore these methods are only called in these circumstances.
|
||||||
|
|
||||||
|
### Custom order timeout example
|
||||||
|
|
||||||
|
A simple example, which applies different unfilled-timeouts depending on the price of the asset can be seen below.
|
||||||
|
It applies a tight timeout for higher priced assets, while allowing more time to fill on cheap coins.
|
||||||
|
|
||||||
|
The function must return either `True` (cancel order) or `False` (keep order alive).
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
# Set unfilledtimeout to 25 hours, since our maximum timeout from below is 24 hours.
|
||||||
|
unfilledtimeout = {
|
||||||
|
'buy': 60 * 25,
|
||||||
|
'sell': 60 * 25
|
||||||
|
}
|
||||||
|
|
||||||
|
def check_buy_timeout(self, pair: str, trade: 'Trade', order: dict, **kwargs) -> bool:
|
||||||
|
if trade.open_rate > 100 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(minutes=5):
|
||||||
|
return True
|
||||||
|
elif trade.open_rate > 10 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(minutes=3):
|
||||||
|
return True
|
||||||
|
elif trade.open_rate < 1 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(hours=24):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_sell_timeout(self, pair: str, trade: 'Trade', order: dict, **kwargs) -> bool:
|
||||||
|
if trade.open_rate > 100 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(minutes=5):
|
||||||
|
return True
|
||||||
|
elif trade.open_rate > 10 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(minutes=3):
|
||||||
|
return True
|
||||||
|
elif trade.open_rate < 1 and trade.open_date_utc < datetime.now(timezone.utc) - timedelta(hours=24):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
You should make sure to implement proper version control (like a git repository) alongside this, as freqtrade will not keep historic versions of your strategy, so it's up to the user to be able to eventually roll back to a prior version of the strategy.
|
For the above example, `unfilledtimeout` must be set to something bigger than 24h, otherwise that type of timeout will apply first.
|
||||||
|
|
||||||
|
### Custom order timeout example (using additional data)
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from datetime import datetime
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
# Set unfilledtimeout to 25 hours, since our maximum timeout from below is 24 hours.
|
||||||
|
unfilledtimeout = {
|
||||||
|
'buy': 60 * 25,
|
||||||
|
'sell': 60 * 25
|
||||||
|
}
|
||||||
|
|
||||||
|
def check_buy_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool:
|
||||||
|
ob = self.dp.orderbook(pair, 1)
|
||||||
|
current_price = ob['bids'][0][0]
|
||||||
|
# Cancel buy order if price is more than 2% above the order.
|
||||||
|
if current_price > order['price'] * 1.02:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_sell_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool:
|
||||||
|
ob = self.dp.orderbook(pair, 1)
|
||||||
|
current_price = ob['asks'][0][0]
|
||||||
|
# Cancel sell order if price is more than 2% below the order.
|
||||||
|
if current_price < order['price'] * 0.98:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Bot loop start callback
|
||||||
|
|
||||||
|
A simple callback which is called once at the start of every bot throttling iteration.
|
||||||
|
This can be used to perform calculations which are pair independent (apply to all pairs), loading of external data, etc.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
import requests
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
def bot_loop_start(self, **kwargs) -> None:
|
||||||
|
"""
|
||||||
|
Called at the start of the bot iteration (one loop).
|
||||||
|
Might be used to perform pair-independent tasks
|
||||||
|
(e.g. gather some remote resource for comparison)
|
||||||
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
|
"""
|
||||||
|
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||||
|
# Assign this to the class by using self.*
|
||||||
|
# can then be used by populate_* methods
|
||||||
|
self.remote_data = requests.get('https://some_remote_source.example.com')
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Bot order confirmation
|
||||||
|
|
||||||
|
### Trade entry (buy order) confirmation
|
||||||
|
|
||||||
|
`confirm_trade_entry()` can be used to abort a trade entry at the latest second (maybe because the price is not what we expect).
|
||||||
|
|
||||||
|
``` python
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
||||||
|
time_in_force: str, **kwargs) -> bool:
|
||||||
|
"""
|
||||||
|
Called right before placing a buy order.
|
||||||
|
Timing for this function is critical, so avoid doing heavy computations or
|
||||||
|
network requests in this method.
|
||||||
|
|
||||||
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
|
When not implemented by a strategy, returns True (always confirming).
|
||||||
|
|
||||||
|
:param pair: Pair that's about to be bought.
|
||||||
|
:param order_type: Order type (as configured in order_types). usually limit or market.
|
||||||
|
:param amount: Amount in target (quote) currency that's going to be traded.
|
||||||
|
:param rate: Rate that's going to be used when using limit orders
|
||||||
|
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
||||||
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
|
:return bool: When True is returned, then the buy-order is placed on the exchange.
|
||||||
|
False aborts the process
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Trade exit (sell order) confirmation
|
||||||
|
|
||||||
|
`confirm_trade_exit()` can be used to abort a trade exit (sell) at the latest second (maybe because the price is not what we expect).
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
|
||||||
|
class AwesomeStrategy(IStrategy):
|
||||||
|
|
||||||
|
# ... populate_* methods
|
||||||
|
|
||||||
|
def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,
|
||||||
|
rate: float, time_in_force: str, sell_reason: str, **kwargs) -> bool:
|
||||||
|
"""
|
||||||
|
Called right before placing a regular sell order.
|
||||||
|
Timing for this function is critical, so avoid doing heavy computations or
|
||||||
|
network requests in this method.
|
||||||
|
|
||||||
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
|
When not implemented by a strategy, returns True (always confirming).
|
||||||
|
|
||||||
|
:param pair: Pair that's about to be sold.
|
||||||
|
:param order_type: Order type (as configured in order_types). usually limit or market.
|
||||||
|
:param amount: Amount in quote currency.
|
||||||
|
:param rate: Rate that's going to be used when using limit orders
|
||||||
|
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
||||||
|
:param sell_reason: Sell reason.
|
||||||
|
Can be any of ['roi', 'stop_loss', 'stoploss_on_exchange', 'trailing_stop_loss',
|
||||||
|
'sell_signal', 'force_sell', 'emergency_sell']
|
||||||
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
|
:return bool: When True is returned, then the sell-order is placed on the exchange.
|
||||||
|
False aborts the process
|
||||||
|
"""
|
||||||
|
if sell_reason == 'force_sell' and trade.calc_profit_ratio(rate) < 0:
|
||||||
|
# Reject force-sells with negative profit
|
||||||
|
# This is just a sample, please adjust to your needs
|
||||||
|
# (this does not necessarily make sense, assuming you know when you're force-selling)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Derived strategies
|
## Derived strategies
|
||||||
|
|
||||||
The strategies can be derived from other strategies. This avoids duplication of your custom strategy code. You can use this technique to override small parts of your main strategy, leaving the rest untouched:
|
The strategies can be derived from other strategies. This avoids duplication of your custom strategy code. You can use this technique to override small parts of your main strategy, leaving the rest untouched:
|
||||||
|
|
||||||
``` python title="user_data/strategies/myawesomestrategy.py"
|
``` python
|
||||||
class MyAwesomeStrategy(IStrategy):
|
class MyAwesomeStrategy(IStrategy):
|
||||||
...
|
...
|
||||||
stoploss = 0.13
|
stoploss = 0.13
|
||||||
@ -161,10 +536,6 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
# should be in any custom strategy...
|
# should be in any custom strategy...
|
||||||
...
|
...
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
``` python title="user_data/strategies/MyAwesomeStrategy2.py"
|
|
||||||
from myawesomestrategy import MyAwesomeStrategy
|
|
||||||
class MyAwesomeStrategy2(MyAwesomeStrategy):
|
class MyAwesomeStrategy2(MyAwesomeStrategy):
|
||||||
# Override something
|
# Override something
|
||||||
stoploss = 0.08
|
stoploss = 0.08
|
||||||
@ -173,7 +544,16 @@ class MyAwesomeStrategy2(MyAwesomeStrategy):
|
|||||||
|
|
||||||
Both attributes and methods may be overridden, altering behavior of the original strategy in a way you need.
|
Both attributes and methods may be overridden, altering behavior of the original strategy in a way you need.
|
||||||
|
|
||||||
While keeping the subclass in the same file is technically possible, it can lead to some problems with hyperopt parameter files, we therefore recommend to use separate strategy files, and import the parent strategy as shown above.
|
!!! Note "Parent-strategy in different files"
|
||||||
|
If you have the parent-strategy in a different file, you'll need to add the following to the top of your "child"-file to ensure proper loading, otherwise freqtrade may not be able to load the parent strategy correctly.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
sys.path.append(str(Path(__file__).parent))
|
||||||
|
|
||||||
|
from myawesomestrategy import MyAwesomeStrategy
|
||||||
|
```
|
||||||
|
|
||||||
## Embedding Strategies
|
## Embedding Strategies
|
||||||
|
|
||||||
@ -200,35 +580,3 @@ The variable 'content', will contain the strategy file in a BASE64 encoded form.
|
|||||||
```
|
```
|
||||||
|
|
||||||
Please ensure that 'NameOfStrategy' is identical to the strategy name!
|
Please ensure that 'NameOfStrategy' is identical to the strategy name!
|
||||||
|
|
||||||
## Performance warning
|
|
||||||
|
|
||||||
When executing a strategy, one can sometimes be greeted by the following in the logs
|
|
||||||
|
|
||||||
> PerformanceWarning: DataFrame is highly fragmented.
|
|
||||||
|
|
||||||
This is a warning from [`pandas`](https://github.com/pandas-dev/pandas) and as the warning continues to say:
|
|
||||||
use `pd.concat(axis=1)`.
|
|
||||||
This can have slight performance implications, which are usually only visible during hyperopt (when optimizing an indicator).
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```python
|
|
||||||
for val in self.buy_ema_short.range:
|
|
||||||
dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)
|
|
||||||
```
|
|
||||||
|
|
||||||
should be rewritten to
|
|
||||||
|
|
||||||
```python
|
|
||||||
frames = [dataframe]
|
|
||||||
for val in self.buy_ema_short.range:
|
|
||||||
frames.append(DataFrame({
|
|
||||||
f'ema_short_{val}': ta.EMA(dataframe, timeperiod=val)
|
|
||||||
}))
|
|
||||||
|
|
||||||
# Append columns to existing dataframe
|
|
||||||
merged_frame = pd.concat(frames, axis=1)
|
|
||||||
```
|
|
||||||
|
|
||||||
Freqtrade does however also counter this by running `dataframe.copy()` on the dataframe right after the `populate_indicators()` method - so performance implications of this should be low to non-existant.
|
|
||||||
|
@ -1,876 +0,0 @@
|
|||||||
# Strategy Callbacks
|
|
||||||
|
|
||||||
While the main strategy functions (`populate_indicators()`, `populate_entry_trend()`, `populate_exit_trend()`) should be used in a vectorized way, and are only called [once during backtesting](bot-basics.md#backtesting-hyperopt-execution-logic), callbacks are called "whenever needed".
|
|
||||||
|
|
||||||
As such, you should avoid doing heavy calculations in callbacks to avoid delays during operations.
|
|
||||||
Depending on the callback used, they may be called when entering / exiting a trade, or throughout the duration of a trade.
|
|
||||||
|
|
||||||
Currently available callbacks:
|
|
||||||
|
|
||||||
* [`bot_start()`](#bot-start)
|
|
||||||
* [`bot_loop_start()`](#bot-loop-start)
|
|
||||||
* [`custom_stake_amount()`](#stake-size-management)
|
|
||||||
* [`custom_exit()`](#custom-exit-signal)
|
|
||||||
* [`custom_stoploss()`](#custom-stoploss)
|
|
||||||
* [`custom_entry_price()` and `custom_exit_price()`](#custom-order-price-rules)
|
|
||||||
* [`check_entry_timeout()` and `check_exit_timeout()`](#custom-order-timeout-rules)
|
|
||||||
* [`confirm_trade_entry()`](#trade-entry-buy-order-confirmation)
|
|
||||||
* [`confirm_trade_exit()`](#trade-exit-sell-order-confirmation)
|
|
||||||
* [`adjust_trade_position()`](#adjust-trade-position)
|
|
||||||
* [`adjust_entry_price()`](#adjust-entry-price)
|
|
||||||
* [`leverage()`](#leverage-callback)
|
|
||||||
|
|
||||||
!!! Tip "Callback calling sequence"
|
|
||||||
You can find the callback calling sequence in [bot-basics](bot-basics.md#bot-execution-logic)
|
|
||||||
|
|
||||||
## Bot start
|
|
||||||
|
|
||||||
A simple callback which is called once when the strategy is loaded.
|
|
||||||
This can be used to perform actions that must only be performed once and runs after dataprovider and wallet are set
|
|
||||||
|
|
||||||
``` python
|
|
||||||
import requests
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def bot_start(self, **kwargs) -> None:
|
|
||||||
"""
|
|
||||||
Called only once after bot instantiation.
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
"""
|
|
||||||
if self.config['runmode'].value in ('live', 'dry_run'):
|
|
||||||
# Assign this to the class by using self.*
|
|
||||||
# can then be used by populate_* methods
|
|
||||||
self.cust_remote_data = requests.get('https://some_remote_source.example.com')
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
During hyperopt, this runs only once at startup.
|
|
||||||
|
|
||||||
## Bot loop start
|
|
||||||
|
|
||||||
A simple callback which is called once at the start of every bot throttling iteration in dry/live mode (roughly every 5
|
|
||||||
seconds, unless configured differently) or once per candle in backtest/hyperopt mode.
|
|
||||||
This can be used to perform calculations which are pair independent (apply to all pairs), loading of external data, etc.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
import requests
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def bot_loop_start(self, current_time: datetime, **kwargs) -> None:
|
|
||||||
"""
|
|
||||||
Called at the start of the bot iteration (one loop).
|
|
||||||
Might be used to perform pair-independent tasks
|
|
||||||
(e.g. gather some remote resource for comparison)
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
"""
|
|
||||||
if self.config['runmode'].value in ('live', 'dry_run'):
|
|
||||||
# Assign this to the class by using self.*
|
|
||||||
# can then be used by populate_* methods
|
|
||||||
self.remote_data = requests.get('https://some_remote_source.example.com')
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Stake size management
|
|
||||||
|
|
||||||
Called before entering a trade, makes it possible to manage your position size when placing a new trade.
|
|
||||||
|
|
||||||
```python
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,
|
|
||||||
proposed_stake: float, min_stake: Optional[float], max_stake: float,
|
|
||||||
leverage: float, entry_tag: Optional[str], side: str,
|
|
||||||
**kwargs) -> float:
|
|
||||||
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
|
|
||||||
current_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
|
|
||||||
if current_candle['fastk_rsi_1h'] > current_candle['fastd_rsi_1h']:
|
|
||||||
if self.config['stake_amount'] == 'unlimited':
|
|
||||||
# Use entire available wallet during favorable conditions when in compounding mode.
|
|
||||||
return max_stake
|
|
||||||
else:
|
|
||||||
# Compound profits during favorable conditions instead of using a static stake.
|
|
||||||
return self.wallets.get_total_stake_amount() / self.config['max_open_trades']
|
|
||||||
|
|
||||||
# Use default stake amount.
|
|
||||||
return proposed_stake
|
|
||||||
```
|
|
||||||
|
|
||||||
Freqtrade will fall back to the `proposed_stake` value should your code raise an exception. The exception itself will be logged.
|
|
||||||
|
|
||||||
!!! Tip
|
|
||||||
You do not _have_ to ensure that `min_stake <= returned_value <= max_stake`. Trades will succeed as the returned value will be clamped to supported range and this action will be logged.
|
|
||||||
|
|
||||||
!!! Tip
|
|
||||||
Returning `0` or `None` will prevent trades from being placed.
|
|
||||||
|
|
||||||
## Custom exit signal
|
|
||||||
|
|
||||||
Called for open trade every throttling iteration (roughly every 5 seconds) until a trade is closed.
|
|
||||||
|
|
||||||
Allows to define custom exit signals, indicating that specified position should be sold. This is very useful when we need to customize exit conditions for each individual trade, or if you need trade data to make an exit decision.
|
|
||||||
|
|
||||||
For example you could implement a 1:2 risk-reward ROI with `custom_exit()`.
|
|
||||||
|
|
||||||
Using `custom_exit()` signals in place of stoploss though *is not recommended*. It is a inferior method to using `custom_stoploss()` in this regard - which also allows you to keep the stoploss on exchange.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Returning a (none-empty) `string` or `True` from this method is equal to setting exit signal on a candle at specified time. This method is not called when exit signal is set already, or if exit signals are disabled (`use_exit_signal=False`). `string` max length is 64 characters. Exceeding this limit will cause the message to be truncated to 64 characters.
|
|
||||||
`custom_exit()` will ignore `exit_profit_only`, and will always be called unless `use_exit_signal=False`, even if there is a new enter signal.
|
|
||||||
|
|
||||||
An example of how we can use different indicators depending on the current profit and also exit trades that were open longer than one day:
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
|
||||||
current_profit: float, **kwargs):
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
|
|
||||||
# Above 20% profit, sell when rsi < 80
|
|
||||||
if current_profit > 0.2:
|
|
||||||
if last_candle['rsi'] < 80:
|
|
||||||
return 'rsi_below_80'
|
|
||||||
|
|
||||||
# Between 2% and 10%, sell if EMA-long above EMA-short
|
|
||||||
if 0.02 < current_profit < 0.1:
|
|
||||||
if last_candle['emalong'] > last_candle['emashort']:
|
|
||||||
return 'ema_long_below_80'
|
|
||||||
|
|
||||||
# Sell any positions at a loss if they are held for more than one day.
|
|
||||||
if current_profit < 0.0 and (current_time - trade.open_date_utc).days >= 1:
|
|
||||||
return 'unclog'
|
|
||||||
```
|
|
||||||
|
|
||||||
See [Dataframe access](strategy-advanced.md#dataframe-access) for more information about dataframe use in strategy callbacks.
|
|
||||||
|
|
||||||
## Custom stoploss
|
|
||||||
|
|
||||||
Called for open trade every iteration (roughly every 5 seconds) until a trade is closed.
|
|
||||||
|
|
||||||
The usage of the custom stoploss method must be enabled by setting `use_custom_stoploss=True` on the strategy object.
|
|
||||||
|
|
||||||
The stoploss price can only ever move upwards - if the stoploss value returned from `custom_stoploss` would result in a lower stoploss price than was previously set, it will be ignored. The traditional `stoploss` value serves as an absolute lower level and will be instated as the initial stoploss (before this method is called for the first time for a trade), and is still mandatory.
|
|
||||||
|
|
||||||
The method must return a stoploss value (float / number) as a percentage of the current price.
|
|
||||||
E.g. If the `current_rate` is 200 USD, then returning `0.02` will set the stoploss price 2% lower, at 196 USD.
|
|
||||||
During backtesting, `current_rate` (and `current_profit`) are provided against the candle's high (or low for short trades) - while the resulting stoploss is evaluated against the candle's low (or high for short trades).
|
|
||||||
|
|
||||||
The absolute value of the return value is used (the sign is ignored), so returning `0.05` or `-0.05` have the same result, a stoploss 5% below the current price.
|
|
||||||
|
|
||||||
To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum reached price) you would use the following very simple method:
|
|
||||||
|
|
||||||
``` python
|
|
||||||
# additional imports required
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
"""
|
|
||||||
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
|
||||||
e.g. returning -0.05 would create a stoploss 5% below current_rate.
|
|
||||||
The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.
|
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
||||||
|
|
||||||
When not implemented by a strategy, returns the initial stoploss value
|
|
||||||
Only called when use_custom_stoploss is set to True.
|
|
||||||
|
|
||||||
:param pair: Pair that's currently analyzed
|
|
||||||
:param trade: trade object.
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
|
||||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
:return float: New stoploss value, relative to the current rate
|
|
||||||
"""
|
|
||||||
return -0.04
|
|
||||||
```
|
|
||||||
|
|
||||||
Stoploss on exchange works similar to `trailing_stop`, and the stoploss on exchange is updated as configured in `stoploss_on_exchange_interval` ([More details about stoploss on exchange](stoploss.md#stop-loss-on-exchange-freqtrade)).
|
|
||||||
|
|
||||||
!!! Note "Use of dates"
|
|
||||||
All time-based calculations should be done based on `current_time` - using `datetime.now()` or `datetime.utcnow()` is discouraged, as this will break backtesting support.
|
|
||||||
|
|
||||||
!!! Tip "Trailing stoploss"
|
|
||||||
It's recommended to disable `trailing_stop` when using custom stoploss values. Both can work in tandem, but you might encounter the trailing stop to move the price higher while your custom function would not want this, causing conflicting behavior.
|
|
||||||
|
|
||||||
### Custom stoploss examples
|
|
||||||
|
|
||||||
The next section will show some examples on what's possible with the custom stoploss function.
|
|
||||||
Of course, many more things are possible, and all examples can be combined at will.
|
|
||||||
|
|
||||||
#### Time based trailing stop
|
|
||||||
|
|
||||||
Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
|
|
||||||
# Make sure you have the longest interval first - these conditions are evaluated from top to bottom.
|
|
||||||
if current_time - timedelta(minutes=120) > trade.open_date_utc:
|
|
||||||
return -0.05
|
|
||||||
elif current_time - timedelta(minutes=60) > trade.open_date_utc:
|
|
||||||
return -0.10
|
|
||||||
return 1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Different stoploss per pair
|
|
||||||
|
|
||||||
Use a different stoploss depending on the pair.
|
|
||||||
In this example, we'll trail the highest price with 10% trailing stoploss for `ETH/BTC` and `XRP/BTC`, with 5% trailing stoploss for `LTC/BTC` and with 15% for all other pairs.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
|
|
||||||
if pair in ('ETH/BTC', 'XRP/BTC'):
|
|
||||||
return -0.10
|
|
||||||
elif pair in ('LTC/BTC'):
|
|
||||||
return -0.05
|
|
||||||
return -0.15
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Trailing stoploss with positive offset
|
|
||||||
|
|
||||||
Use the initial stoploss until the profit is above 4%, then use a trailing stoploss of 50% of the current profit with a minimum of 2.5% and a maximum of 5%.
|
|
||||||
|
|
||||||
Please note that the stoploss can only increase, values lower than the current stoploss are ignored.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
|
|
||||||
if current_profit < 0.04:
|
|
||||||
return -1 # return a value bigger than the initial stoploss to keep using the initial stoploss
|
|
||||||
|
|
||||||
# After reaching the desired offset, allow the stoploss to trail by half the profit
|
|
||||||
desired_stoploss = current_profit / 2
|
|
||||||
|
|
||||||
# Use a minimum of 2.5% and a maximum of 5%
|
|
||||||
return max(min(desired_stoploss, 0.05), 0.025)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Stepped stoploss
|
|
||||||
|
|
||||||
Instead of continuously trailing behind the current price, this example sets fixed stoploss price levels based on the current profit.
|
|
||||||
|
|
||||||
* Use the regular stoploss until 20% profit is reached
|
|
||||||
* Once profit is > 20% - set stoploss to 7% above open price.
|
|
||||||
* Once profit is > 25% - set stoploss to 15% above open price.
|
|
||||||
* Once profit is > 40% - set stoploss to 25% above open price.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
from freqtrade.strategy import stoploss_from_open
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
|
|
||||||
# evaluate highest to lowest, so that highest possible stop is used
|
|
||||||
if current_profit > 0.40:
|
|
||||||
return stoploss_from_open(0.25, current_profit, is_short=trade.is_short, leverage=trade.leverage)
|
|
||||||
elif current_profit > 0.25:
|
|
||||||
return stoploss_from_open(0.15, current_profit, is_short=trade.is_short, leverage=trade.leverage)
|
|
||||||
elif current_profit > 0.20:
|
|
||||||
return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)
|
|
||||||
|
|
||||||
# return maximum stoploss value, keeping current stoploss price unchanged
|
|
||||||
return 1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Custom stoploss using an indicator from dataframe example
|
|
||||||
|
|
||||||
Absolute stoploss value may be derived from indicators stored in dataframe. Example uses parabolic SAR below the price as stoploss.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
# <...>
|
|
||||||
dataframe['sar'] = ta.SAR(dataframe)
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
|
|
||||||
# Use parabolic sar as absolute stoploss price
|
|
||||||
stoploss_price = last_candle['sar']
|
|
||||||
|
|
||||||
# Convert absolute price to percentage relative to current_rate
|
|
||||||
if stoploss_price < current_rate:
|
|
||||||
return (stoploss_price / current_rate) - 1
|
|
||||||
|
|
||||||
# return maximum stoploss value, keeping current stoploss price unchanged
|
|
||||||
return 1
|
|
||||||
```
|
|
||||||
|
|
||||||
See [Dataframe access](strategy-advanced.md#dataframe-access) for more information about dataframe use in strategy callbacks.
|
|
||||||
|
|
||||||
### Common helpers for stoploss calculations
|
|
||||||
|
|
||||||
#### Stoploss relative to open price
|
|
||||||
|
|
||||||
Stoploss values returned from `custom_stoploss()` always specify a percentage relative to `current_rate`. In order to set a stoploss relative to the *open* price, we need to use `current_profit` to calculate what percentage relative to the `current_rate` will give you the same result as if the percentage was specified from the open price.
|
|
||||||
|
|
||||||
The helper function [`stoploss_from_open()`](strategy-customization.md#stoploss_from_open) can be used to convert from an open price relative stop, to a current price relative stop which can be returned from `custom_stoploss()`.
|
|
||||||
|
|
||||||
#### Stoploss percentage from absolute price
|
|
||||||
|
|
||||||
Stoploss values returned from `custom_stoploss()` always specify a percentage relative to `current_rate`. In order to set a stoploss at specified absolute price level, we need to use `stop_rate` to calculate what percentage relative to the `current_rate` will give you the same result as if the percentage was specified from the open price.
|
|
||||||
|
|
||||||
The helper function [`stoploss_from_absolute()`](strategy-customization.md#stoploss_from_absolute) can be used to convert from an absolute price, to a current price relative stop which can be returned from `custom_stoploss()`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Custom order price rules
|
|
||||||
|
|
||||||
By default, freqtrade use the orderbook to automatically set an order price([Relevant documentation](configuration.md#prices-used-for-orders)), you also have the option to create custom order prices based on your strategy.
|
|
||||||
|
|
||||||
You can use this feature by creating a `custom_entry_price()` function in your strategy file to customize entry prices and `custom_exit_price()` for exits.
|
|
||||||
|
|
||||||
Each of these methods are called right before placing an order on the exchange.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
If your custom pricing function return None or an invalid value, price will fall back to `proposed_rate`, which is based on the regular pricing configuration.
|
|
||||||
|
|
||||||
### Custom order entry and exit price example
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def custom_entry_price(self, pair: str, current_time: datetime, proposed_rate: float,
|
|
||||||
entry_tag: Optional[str], side: str, **kwargs) -> float:
|
|
||||||
|
|
||||||
dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,
|
|
||||||
timeframe=self.timeframe)
|
|
||||||
new_entryprice = dataframe['bollinger_10_lowerband'].iat[-1]
|
|
||||||
|
|
||||||
return new_entryprice
|
|
||||||
|
|
||||||
def custom_exit_price(self, pair: str, trade: Trade,
|
|
||||||
current_time: datetime, proposed_rate: float,
|
|
||||||
current_profit: float, exit_tag: Optional[str], **kwargs) -> float:
|
|
||||||
|
|
||||||
dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,
|
|
||||||
timeframe=self.timeframe)
|
|
||||||
new_exitprice = dataframe['bollinger_10_upperband'].iat[-1]
|
|
||||||
|
|
||||||
return new_exitprice
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Modifying entry and exit prices will only work for limit orders. Depending on the price chosen, this can result in a lot of unfilled orders. By default the maximum allowed distance between the current price and the custom price is 2%, this value can be changed in config with the `custom_price_max_distance_ratio` parameter.
|
|
||||||
**Example**:
|
|
||||||
If the new_entryprice is 97, the proposed_rate is 100 and the `custom_price_max_distance_ratio` is set to 2%, The retained valid custom entry price will be 98, which is 2% below the current (proposed) rate.
|
|
||||||
|
|
||||||
!!! Warning "Backtesting"
|
|
||||||
Custom prices are supported in backtesting (starting with 2021.12), and orders will fill if the price falls within the candle's low/high range.
|
|
||||||
Orders that don't fill immediately are subject to regular timeout handling, which happens once per (detail) candle.
|
|
||||||
`custom_exit_price()` is only called for sells of type exit_signal, Custom exit and partial exits. All other exit-types will use regular backtesting prices.
|
|
||||||
|
|
||||||
## Custom order timeout rules
|
|
||||||
|
|
||||||
Simple, time-based order-timeouts can be configured either via strategy or in the configuration in the `unfilledtimeout` section.
|
|
||||||
|
|
||||||
However, freqtrade also offers a custom callback for both order types, which allows you to decide based on custom criteria if an order did time out or not.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Backtesting fills orders if their price falls within the candle's low/high range.
|
|
||||||
The below callbacks will be called once per (detail) candle for orders that don't fill immediately (which use custom pricing).
|
|
||||||
|
|
||||||
### Custom order timeout example
|
|
||||||
|
|
||||||
Called for every open order until that order is either filled or cancelled.
|
|
||||||
`check_entry_timeout()` is called for trade entries, while `check_exit_timeout()` is called for trade exit orders.
|
|
||||||
|
|
||||||
A simple example, which applies different unfilled-timeouts depending on the price of the asset can be seen below.
|
|
||||||
It applies a tight timeout for higher priced assets, while allowing more time to fill on cheap coins.
|
|
||||||
|
|
||||||
The function must return either `True` (cancel order) or `False` (keep order alive).
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from freqtrade.persistence import Trade, Order
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
# Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.
|
|
||||||
unfilledtimeout = {
|
|
||||||
'entry': 60 * 25,
|
|
||||||
'exit': 60 * 25
|
|
||||||
}
|
|
||||||
|
|
||||||
def check_entry_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|
||||||
current_time: datetime, **kwargs) -> bool:
|
|
||||||
if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):
|
|
||||||
return True
|
|
||||||
elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):
|
|
||||||
return True
|
|
||||||
elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def check_exit_timeout(self, pair: str, trade: Trade, order: 'Order',
|
|
||||||
current_time: datetime, **kwargs) -> bool:
|
|
||||||
if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):
|
|
||||||
return True
|
|
||||||
elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):
|
|
||||||
return True
|
|
||||||
elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
For the above example, `unfilledtimeout` must be set to something bigger than 24h, otherwise that type of timeout will apply first.
|
|
||||||
|
|
||||||
### Custom order timeout example (using additional data)
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade, Order
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
# Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.
|
|
||||||
unfilledtimeout = {
|
|
||||||
'entry': 60 * 25,
|
|
||||||
'exit': 60 * 25
|
|
||||||
}
|
|
||||||
|
|
||||||
def check_entry_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|
||||||
current_time: datetime, **kwargs) -> bool:
|
|
||||||
ob = self.dp.orderbook(pair, 1)
|
|
||||||
current_price = ob['bids'][0][0]
|
|
||||||
# Cancel buy order if price is more than 2% above the order.
|
|
||||||
if current_price > order.price * 1.02:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|
||||||
current_time: datetime, **kwargs) -> bool:
|
|
||||||
ob = self.dp.orderbook(pair, 1)
|
|
||||||
current_price = ob['asks'][0][0]
|
|
||||||
# Cancel sell order if price is more than 2% below the order.
|
|
||||||
if current_price < order.price * 0.98:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bot order confirmation
|
|
||||||
|
|
||||||
Confirm trade entry / exits.
|
|
||||||
This are the last methods that will be called before an order is placed.
|
|
||||||
|
|
||||||
### Trade entry (buy order) confirmation
|
|
||||||
|
|
||||||
`confirm_trade_entry()` can be used to abort a trade entry at the latest second (maybe because the price is not what we expect).
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
|
||||||
time_in_force: str, current_time: datetime, entry_tag: Optional[str],
|
|
||||||
side: str, **kwargs) -> bool:
|
|
||||||
"""
|
|
||||||
Called right before placing a entry order.
|
|
||||||
Timing for this function is critical, so avoid doing heavy computations or
|
|
||||||
network requests in this method.
|
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
||||||
|
|
||||||
When not implemented by a strategy, returns True (always confirming).
|
|
||||||
|
|
||||||
:param pair: Pair that's about to be bought/shorted.
|
|
||||||
:param order_type: Order type (as configured in order_types). usually limit or market.
|
|
||||||
:param amount: Amount in target (base) currency that's going to be traded.
|
|
||||||
:param rate: Rate that's going to be used when using limit orders
|
|
||||||
or current rate for market orders.
|
|
||||||
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
|
||||||
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
:return bool: When True is returned, then the buy-order is placed on the exchange.
|
|
||||||
False aborts the process
|
|
||||||
"""
|
|
||||||
return True
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Trade exit (sell order) confirmation
|
|
||||||
|
|
||||||
`confirm_trade_exit()` can be used to abort a trade exit (sell) at the latest second (maybe because the price is not what we expect).
|
|
||||||
|
|
||||||
`confirm_trade_exit()` may be called multiple times within one iteration for the same trade if different exit-reasons apply.
|
|
||||||
The exit-reasons (if applicable) will be in the following sequence:
|
|
||||||
|
|
||||||
* `exit_signal` / `custom_exit`
|
|
||||||
* `stop_loss`
|
|
||||||
* `roi`
|
|
||||||
* `trailing_stop_loss`
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,
|
|
||||||
rate: float, time_in_force: str, exit_reason: str,
|
|
||||||
current_time: datetime, **kwargs) -> bool:
|
|
||||||
"""
|
|
||||||
Called right before placing a regular exit order.
|
|
||||||
Timing for this function is critical, so avoid doing heavy computations or
|
|
||||||
network requests in this method.
|
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
||||||
|
|
||||||
When not implemented by a strategy, returns True (always confirming).
|
|
||||||
|
|
||||||
:param pair: Pair for trade that's about to be exited.
|
|
||||||
:param trade: trade object.
|
|
||||||
:param order_type: Order type (as configured in order_types). usually limit or market.
|
|
||||||
:param amount: Amount in base currency.
|
|
||||||
:param rate: Rate that's going to be used when using limit orders
|
|
||||||
or current rate for market orders.
|
|
||||||
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
|
||||||
:param exit_reason: Exit reason.
|
|
||||||
Can be any of ['roi', 'stop_loss', 'stoploss_on_exchange', 'trailing_stop_loss',
|
|
||||||
'exit_signal', 'force_exit', 'emergency_exit']
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
:return bool: When True, then the exit-order is placed on the exchange.
|
|
||||||
False aborts the process
|
|
||||||
"""
|
|
||||||
if exit_reason == 'force_exit' and trade.calc_profit_ratio(rate) < 0:
|
|
||||||
# Reject force-sells with negative profit
|
|
||||||
# This is just a sample, please adjust to your needs
|
|
||||||
# (this does not necessarily make sense, assuming you know when you're force-selling)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
`confirm_trade_exit()` can prevent stoploss exits, causing significant losses as this would ignore stoploss exits.
|
|
||||||
`confirm_trade_exit()` will not be called for Liquidations - as liquidations are forced by the exchange, and therefore cannot be rejected.
|
|
||||||
|
|
||||||
## Adjust trade position
|
|
||||||
|
|
||||||
The `position_adjustment_enable` strategy property enables the usage of `adjust_trade_position()` callback in the strategy.
|
|
||||||
For performance reasons, it's disabled by default and freqtrade will show a warning message on startup if enabled.
|
|
||||||
`adjust_trade_position()` can be used to perform additional orders, for example to manage risk with DCA (Dollar Cost Averaging) or to increase or decrease positions.
|
|
||||||
|
|
||||||
`max_entry_position_adjustment` property is used to limit the number of additional buys per trade (on top of the first buy) that the bot can execute. By default, the value is -1 which means the bot have no limit on number of adjustment buys.
|
|
||||||
|
|
||||||
The strategy is expected to return a stake_amount (in stake currency) between `min_stake` and `max_stake` if and when an additional buy order should be made (position is increased).
|
|
||||||
If there are not enough funds in the wallet (the return value is above `max_stake`) then the signal will be ignored.
|
|
||||||
Additional orders also result in additional fees and those orders don't count towards `max_open_trades`.
|
|
||||||
|
|
||||||
This callback is **not** called when there is an open order (either buy or sell) waiting for execution.
|
|
||||||
|
|
||||||
`adjust_trade_position()` is called very frequently for the duration of a trade, so you must keep your implementation as performant as possible.
|
|
||||||
|
|
||||||
Additional Buys are ignored once you have reached the maximum amount of extra buys that you have set on `max_entry_position_adjustment`, but the callback is called anyway looking for partial exits.
|
|
||||||
|
|
||||||
Position adjustments will always be applied in the direction of the trade, so a positive value will always increase your position (negative values will decrease your position), no matter if it's a long or short trade. Modifications to leverage are not possible, and the stake-amount is assumed to be before applying leverage.
|
|
||||||
|
|
||||||
!!! Note "About stake size"
|
|
||||||
Using fixed stake size means it will be the amount used for the first order, just like without position adjustment.
|
|
||||||
If you wish to buy additional orders with DCA, then make sure to leave enough funds in the wallet for that.
|
|
||||||
Using 'unlimited' stake amount with DCA orders requires you to also implement the `custom_stake_amount()` callback to avoid allocating all funds to the initial order.
|
|
||||||
|
|
||||||
!!! Warning
|
|
||||||
Stoploss is still calculated from the initial opening price, not averaged price.
|
|
||||||
Regular stoploss rules still apply (cannot move down).
|
|
||||||
|
|
||||||
While `/stopentry` command stops the bot from entering new trades, the position adjustment feature will continue buying new orders on existing trades.
|
|
||||||
|
|
||||||
!!! Warning "Backtesting"
|
|
||||||
During backtesting this callback is called for each candle in `timeframe` or `timeframe_detail`, so run-time performance will be affected.
|
|
||||||
This can also cause deviating results between live and backtesting, since backtesting can adjust the trade only once per candle, whereas live could adjust the trade multiple times per candle.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
|
|
||||||
|
|
||||||
class DigDeeperStrategy(IStrategy):
|
|
||||||
|
|
||||||
position_adjustment_enable = True
|
|
||||||
|
|
||||||
# Attempts to handle large drops with DCA. High stoploss is required.
|
|
||||||
stoploss = -0.30
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
# Example specific variables
|
|
||||||
max_entry_position_adjustment = 3
|
|
||||||
# This number is explained a bit further down
|
|
||||||
max_dca_multiplier = 5.5
|
|
||||||
|
|
||||||
# This is called when placing the initial order (opening trade)
|
|
||||||
def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,
|
|
||||||
proposed_stake: float, min_stake: Optional[float], max_stake: float,
|
|
||||||
leverage: float, entry_tag: Optional[str], side: str,
|
|
||||||
**kwargs) -> float:
|
|
||||||
|
|
||||||
# We need to leave most of the funds for possible further DCA orders
|
|
||||||
# This also applies to fixed stakes
|
|
||||||
return proposed_stake / self.max_dca_multiplier
|
|
||||||
|
|
||||||
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float,
|
|
||||||
min_stake: Optional[float], max_stake: float,
|
|
||||||
current_entry_rate: float, current_exit_rate: float,
|
|
||||||
current_entry_profit: float, current_exit_profit: float,
|
|
||||||
**kwargs) -> Optional[float]:
|
|
||||||
"""
|
|
||||||
Custom trade adjustment logic, returning the stake amount that a trade should be
|
|
||||||
increased or decreased.
|
|
||||||
This means extra buy or sell orders with additional fees.
|
|
||||||
Only called when `position_adjustment_enable` is set to True.
|
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
||||||
|
|
||||||
When not implemented by a strategy, returns None
|
|
||||||
|
|
||||||
:param trade: trade object.
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param current_rate: Current buy rate.
|
|
||||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
|
||||||
:param min_stake: Minimal stake size allowed by exchange (for both entries and exits)
|
|
||||||
:param max_stake: Maximum stake allowed (either through balance, or by exchange limits).
|
|
||||||
:param current_entry_rate: Current rate using entry pricing.
|
|
||||||
:param current_exit_rate: Current rate using exit pricing.
|
|
||||||
:param current_entry_profit: Current profit using entry pricing.
|
|
||||||
:param current_exit_profit: Current profit using exit pricing.
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
:return float: Stake amount to adjust your trade,
|
|
||||||
Positive values to increase position, Negative values to decrease position.
|
|
||||||
Return None for no action.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if current_profit > 0.05 and trade.nr_of_successful_exits == 0:
|
|
||||||
# Take half of the profit at +5%
|
|
||||||
return -(trade.stake_amount / 2)
|
|
||||||
|
|
||||||
if current_profit > -0.05:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Obtain pair dataframe (just to show how to access it)
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
|
||||||
# Only buy when not actively falling price.
|
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
previous_candle = dataframe.iloc[-2].squeeze()
|
|
||||||
if last_candle['close'] < previous_candle['close']:
|
|
||||||
return None
|
|
||||||
|
|
||||||
filled_entries = trade.select_filled_orders(trade.entry_side)
|
|
||||||
count_of_entries = trade.nr_of_successful_entries
|
|
||||||
# Allow up to 3 additional increasingly larger buys (4 in total)
|
|
||||||
# Initial buy is 1x
|
|
||||||
# If that falls to -5% profit, we buy 1.25x more, average profit should increase to roughly -2.2%
|
|
||||||
# If that falls down to -5% again, we buy 1.5x more
|
|
||||||
# If that falls once again down to -5%, we buy 1.75x more
|
|
||||||
# Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake.
|
|
||||||
# That is why max_dca_multiplier is 5.5
|
|
||||||
# Hope you have a deep wallet!
|
|
||||||
try:
|
|
||||||
# This returns first order stake size
|
|
||||||
stake_amount = filled_entries[0].cost
|
|
||||||
# This then calculates current safety order size
|
|
||||||
stake_amount = stake_amount * (1 + (count_of_entries * 0.25))
|
|
||||||
return stake_amount
|
|
||||||
except Exception as exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Position adjust calculations
|
|
||||||
|
|
||||||
* Entry rates are calculated using weighted averages.
|
|
||||||
* Exits will not influence the average entry rate.
|
|
||||||
* Partial exit relative profit is relative to the average entry price at this point.
|
|
||||||
* Final exit relative profit is calculated based on the total invested capital. (See example below)
|
|
||||||
|
|
||||||
??? example "Calculation example"
|
|
||||||
*This example assumes 0 fees for simplicity, and a long position on an imaginary coin.*
|
|
||||||
|
|
||||||
* Buy 100@8\$
|
|
||||||
* Buy 100@9\$ -> Avg price: 8.5\$
|
|
||||||
* Sell 100@10\$ -> Avg price: 8.5\$, realized profit 150\$, 17.65%
|
|
||||||
* Buy 150@11\$ -> Avg price: 10\$, realized profit 150\$, 17.65%
|
|
||||||
* Sell 100@12\$ -> Avg price: 10\$, total realized profit 350\$, 20%
|
|
||||||
* Sell 150@14\$ -> Avg price: 10\$, total realized profit 950\$, 40% <- *This will be the last "Exit" message*
|
|
||||||
|
|
||||||
The total profit for this trade was 950$ on a 3350$ investment (`100@8$ + 100@9$ + 150@11$`). As such - the final relative profit is 28.35% (`950 / 3350`).
|
|
||||||
|
|
||||||
## Adjust Entry Price
|
|
||||||
|
|
||||||
The `adjust_entry_price()` callback may be used by strategy developer to refresh/replace limit orders upon arrival of new candles.
|
|
||||||
Be aware that `custom_entry_price()` is still the one dictating initial entry limit order price target at the time of entry trigger.
|
|
||||||
|
|
||||||
Orders can be cancelled out of this callback by returning `None`.
|
|
||||||
|
|
||||||
Returning `current_order_rate` will keep the order on the exchange "as is".
|
|
||||||
Returning any other price will cancel the existing order, and replace it with a new order.
|
|
||||||
|
|
||||||
The trade open-date (`trade.open_date_utc`) will remain at the time of the very first order placed.
|
|
||||||
Please make sure to be aware of this - and eventually adjust your logic in other callbacks to account for this, and use the date of the first filled order instead.
|
|
||||||
|
|
||||||
!!! Warning "Regular timeout"
|
|
||||||
Entry `unfilledtimeout` mechanism (as well as `check_entry_timeout()`) takes precedence over this.
|
|
||||||
Entry Orders that are cancelled via the above methods will not have this callback called. Be sure to update timeout values to match your expectations.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# ... populate_* methods
|
|
||||||
|
|
||||||
def adjust_entry_price(self, trade: Trade, order: Optional[Order], pair: str,
|
|
||||||
current_time: datetime, proposed_rate: float, current_order_rate: float,
|
|
||||||
entry_tag: Optional[str], side: str, **kwargs) -> float:
|
|
||||||
"""
|
|
||||||
Entry price re-adjustment logic, returning the user desired limit price.
|
|
||||||
This only executes when a order was already placed, still open (unfilled fully or partially)
|
|
||||||
and not timed out on subsequent candles after entry trigger.
|
|
||||||
|
|
||||||
When not implemented by a strategy, returns current_order_rate as default.
|
|
||||||
If current_order_rate is returned then the existing order is maintained.
|
|
||||||
If None is returned then order gets canceled but not replaced by a new one.
|
|
||||||
|
|
||||||
:param pair: Pair that's currently analyzed
|
|
||||||
:param trade: Trade object.
|
|
||||||
:param order: Order object
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param proposed_rate: Rate, calculated based on pricing settings in entry_pricing.
|
|
||||||
:param current_order_rate: Rate of the existing order in place.
|
|
||||||
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
|
||||||
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
||||||
:return float: New entry price value if provided
|
|
||||||
|
|
||||||
"""
|
|
||||||
# Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.
|
|
||||||
if pair == 'BTC/USDT' and entry_tag == 'long_sma200' and side == 'long' and (current_time - timedelta(minutes=10)) > trade.open_date_utc:
|
|
||||||
# just cancel the order if it has been filled more than half of the amount
|
|
||||||
if order.filled > order.remaining:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
|
|
||||||
current_candle = dataframe.iloc[-1].squeeze()
|
|
||||||
# desired price
|
|
||||||
return current_candle['sma_200']
|
|
||||||
# default: maintain existing order
|
|
||||||
return current_order_rate
|
|
||||||
```
|
|
||||||
|
|
||||||
## Leverage Callback
|
|
||||||
|
|
||||||
When trading in markets that allow leverage, this method must return the desired Leverage (Defaults to 1 -> No leverage).
|
|
||||||
|
|
||||||
Assuming a capital of 500USDT, a trade with leverage=3 would result in a position with 500 x 3 = 1500 USDT.
|
|
||||||
|
|
||||||
Values that are above `max_leverage` will be adjusted to `max_leverage`.
|
|
||||||
For markets / exchanges that don't support leverage, this method is ignored.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
|
||||||
proposed_leverage: float, max_leverage: float, entry_tag: Optional[str], side: str,
|
|
||||||
**kwargs) -> float:
|
|
||||||
"""
|
|
||||||
Customize leverage for each new trade. This method is only called in futures mode.
|
|
||||||
|
|
||||||
:param pair: Pair that's currently analyzed
|
|
||||||
:param current_time: datetime object, containing the current datetime
|
|
||||||
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
|
||||||
:param proposed_leverage: A leverage proposed by the bot.
|
|
||||||
:param max_leverage: Max leverage allowed on this pair
|
|
||||||
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
|
||||||
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
|
||||||
:return: A leverage amount, which is between 1.0 and max_leverage.
|
|
||||||
"""
|
|
||||||
return 1.0
|
|
||||||
```
|
|
||||||
|
|
||||||
All profit calculations include leverage. Stoploss / ROI also include leverage in their calculation.
|
|
||||||
Defining a stoploss of 10% at 10x leverage would trigger the stoploss with a 1% move to the downside.
|
|
@ -4,30 +4,40 @@ This page explains how to customize your strategies, add new indicators and set
|
|||||||
|
|
||||||
Please familiarize yourself with [Freqtrade basics](bot-basics.md) first, which provides overall info on how the bot operates.
|
Please familiarize yourself with [Freqtrade basics](bot-basics.md) first, which provides overall info on how the bot operates.
|
||||||
|
|
||||||
|
## Install a custom strategy file
|
||||||
|
|
||||||
|
This is very simple. Copy paste your strategy file into the directory `user_data/strategies`.
|
||||||
|
|
||||||
|
Let assume you have a class called `AwesomeStrategy` in the file `AwesomeStrategy.py`:
|
||||||
|
|
||||||
|
1. Move your file into `user_data/strategies` (you should have `user_data/strategies/AwesomeStrategy.py`
|
||||||
|
2. Start the bot with the param `--strategy AwesomeStrategy` (the parameter is the class name)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
freqtrade trade --strategy AwesomeStrategy
|
||||||
|
```
|
||||||
|
|
||||||
## Develop your own strategy
|
## Develop your own strategy
|
||||||
|
|
||||||
The bot includes a default strategy file.
|
The bot includes a default strategy file.
|
||||||
Also, several other strategies are available in the [strategy repository](https://github.com/freqtrade/freqtrade-strategies).
|
Also, several other strategies are available in the [strategy repository](https://github.com/freqtrade/freqtrade-strategies).
|
||||||
|
|
||||||
You will however most likely have your own idea for a strategy.
|
You will however most likely have your own idea for a strategy.
|
||||||
This document intends to help you convert your strategy idea into your own strategy.
|
This document intends to help you develop one for yourself.
|
||||||
|
|
||||||
To get started, use `freqtrade new-strategy --strategy AwesomeStrategy` (you can obviously use your own naming for your strategy).
|
To get started, use `freqtrade new-strategy --strategy AwesomeStrategy`.
|
||||||
This will create a new strategy file from a template, which will be located under `user_data/strategies/AwesomeStrategy.py`.
|
This will create a new strategy file from a template, which will be located under `user_data/strategies/AwesomeStrategy.py`.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
This is just a template file, which will most likely not be profitable out of the box.
|
This is just a template file, which will most likely not be profitable out of the box.
|
||||||
|
|
||||||
??? Hint "Different template levels"
|
|
||||||
`freqtrade new-strategy` has an additional parameter, `--template`, which controls the amount of pre-build information you get in the created strategy. Use `--template minimal` to get an empty strategy without any indicator examples, or `--template advanced` to get a template with most callbacks defined.
|
|
||||||
|
|
||||||
### Anatomy of a strategy
|
### Anatomy of a strategy
|
||||||
|
|
||||||
A strategy file contains all the information needed to build a good strategy:
|
A strategy file contains all the information needed to build a good strategy:
|
||||||
|
|
||||||
- Indicators
|
- Indicators
|
||||||
- Entry strategy rules
|
- Buy strategy rules
|
||||||
- Exit strategy rules
|
- Sell strategy rules
|
||||||
- Minimal ROI recommended
|
- Minimal ROI recommended
|
||||||
- Stoploss strongly recommended
|
- Stoploss strongly recommended
|
||||||
|
|
||||||
@ -35,7 +45,7 @@ The bot also include a sample strategy called `SampleStrategy` you can update: `
|
|||||||
You can test it with the parameter: `--strategy SampleStrategy`
|
You can test it with the parameter: `--strategy SampleStrategy`
|
||||||
|
|
||||||
Additionally, there is an attribute called `INTERFACE_VERSION`, which defines the version of the strategy interface the bot should use.
|
Additionally, there is an attribute called `INTERFACE_VERSION`, which defines the version of the strategy interface the bot should use.
|
||||||
The current version is 3 - which is also the default when it's not set explicitly in the strategy.
|
The current version is 2 - which is also the default when it's not set explicitly in the strategy.
|
||||||
|
|
||||||
Future versions will require this to be set.
|
Future versions will require this to be set.
|
||||||
|
|
||||||
@ -57,51 +67,11 @@ file as reference.**
|
|||||||
needs to take care to avoid having the strategy utilize data from the future.
|
needs to take care to avoid having the strategy utilize data from the future.
|
||||||
Some common patterns for this are listed in the [Common Mistakes](#common-mistakes-when-developing-strategies) section of this document.
|
Some common patterns for this are listed in the [Common Mistakes](#common-mistakes-when-developing-strategies) section of this document.
|
||||||
|
|
||||||
### Dataframe
|
|
||||||
|
|
||||||
Freqtrade uses [pandas](https://pandas.pydata.org/) to store/provide the candlestick (OHLCV) data.
|
|
||||||
Pandas is a great library developed for processing large amounts of data.
|
|
||||||
|
|
||||||
Each row in a dataframe corresponds to one candle on a chart, with the latest candle always being the last in the dataframe (sorted by date).
|
|
||||||
|
|
||||||
``` output
|
|
||||||
> dataframe.head()
|
|
||||||
date open high low close volume
|
|
||||||
0 2021-11-09 23:25:00+00:00 67279.67 67321.84 67255.01 67300.97 44.62253
|
|
||||||
1 2021-11-09 23:30:00+00:00 67300.97 67301.34 67183.03 67187.01 61.38076
|
|
||||||
2 2021-11-09 23:35:00+00:00 67187.02 67187.02 67031.93 67123.81 113.42728
|
|
||||||
3 2021-11-09 23:40:00+00:00 67123.80 67222.40 67080.33 67160.48 78.96008
|
|
||||||
4 2021-11-09 23:45:00+00:00 67160.48 67160.48 66901.26 66943.37 111.39292
|
|
||||||
```
|
|
||||||
|
|
||||||
Pandas provides fast ways to calculate metrics. To benefit from this speed, it's advised to not use loops, but use vectorized methods instead.
|
|
||||||
|
|
||||||
Vectorized operations perform calculations across the whole range of data and are therefore, compared to looping through each row, a lot faster when calculating indicators.
|
|
||||||
|
|
||||||
As a dataframe is a table, simple python comparisons like the following will not work
|
|
||||||
|
|
||||||
``` python
|
|
||||||
if dataframe['rsi'] > 30:
|
|
||||||
dataframe['enter_long'] = 1
|
|
||||||
```
|
|
||||||
|
|
||||||
The above section will fail with `The truth value of a Series is ambiguous. [...]`.
|
|
||||||
|
|
||||||
This must instead be written in a pandas-compatible way, so the operation is performed across the whole dataframe.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
dataframe.loc[
|
|
||||||
(dataframe['rsi'] > 30)
|
|
||||||
, 'enter_long'] = 1
|
|
||||||
```
|
|
||||||
|
|
||||||
With this section, you have a new column in your dataframe, which has `1` assigned whenever RSI is above 30.
|
|
||||||
|
|
||||||
### Customize Indicators
|
### Customize Indicators
|
||||||
|
|
||||||
Buy and sell signals need indicators. You can add more indicators by extending the list contained in the method `populate_indicators()` from your strategy file.
|
Buy and sell strategies need indicators. You can add more indicators by extending the list contained in the method `populate_indicators()` from your strategy file.
|
||||||
|
|
||||||
You should only add the indicators used in either `populate_entry_trend()`, `populate_exit_trend()`, or to populate another indicator, otherwise performance may suffer.
|
You should only add the indicators used in either `populate_buy_trend()`, `populate_sell_trend()`, or to populate another indicator, otherwise performance may suffer.
|
||||||
|
|
||||||
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
||||||
|
|
||||||
@ -152,21 +122,11 @@ def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame
|
|||||||
Look into the [user_data/strategies/sample_strategy.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_strategy.py).
|
Look into the [user_data/strategies/sample_strategy.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_strategy.py).
|
||||||
Then uncomment indicators you need.
|
Then uncomment indicators you need.
|
||||||
|
|
||||||
#### Indicator libraries
|
|
||||||
|
|
||||||
Out of the box, freqtrade installs the following technical libraries:
|
|
||||||
|
|
||||||
* [ta-lib](http://mrjbq7.github.io/ta-lib/)
|
|
||||||
* [pandas-ta](https://twopirllc.github.io/pandas-ta/)
|
|
||||||
* [technical](https://github.com/freqtrade/technical/)
|
|
||||||
|
|
||||||
Additional technical libraries can be installed as necessary, or custom indicators may be written / invented by the strategy author.
|
|
||||||
|
|
||||||
### Strategy startup period
|
### Strategy startup period
|
||||||
|
|
||||||
Most indicators have an instable startup period, in which they are either not available (NaN), or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this instable period should be.
|
Most indicators have an instable startup period, in which they are either not available, or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this instable period should be.
|
||||||
To account for this, the strategy can be assigned the `startup_candle_count` attribute.
|
To account for this, the strategy can be assigned the `startup_candle_count` attribute.
|
||||||
This should be set to the maximum number of candles that the strategy requires to calculate stable indicators. In the case where a user includes higher timeframes with informative pairs, the `startup_candle_count` does not necessarily change. The value is the maximum period (in candles) that any of the informatives timeframes need to compute stable indicators.
|
This should be set to the maximum number of candles that the strategy requires to calculate stable indicators.
|
||||||
|
|
||||||
In this example strategy, this should be set to 100 (`startup_candle_count = 100`), since the longest needed history is 100 candles.
|
In this example strategy, this should be set to 100 (`startup_candle_count = 100`), since the longest needed history is 100 candles.
|
||||||
|
|
||||||
@ -176,14 +136,8 @@ In this example strategy, this should be set to 100 (`startup_candle_count = 100
|
|||||||
|
|
||||||
By letting the bot know how much history is needed, backtest trades can start at the specified timerange during backtesting and hyperopt.
|
By letting the bot know how much history is needed, backtest trades can start at the specified timerange during backtesting and hyperopt.
|
||||||
|
|
||||||
!!! Warning "Using x calls to get OHLCV"
|
|
||||||
If you receive a warning like `WARNING - Using 3 calls to get OHLCV. This can result in slower operations for the bot. Please check if you really need 1500 candles for your strategy` - you should consider if you really need this much historic data for your signals.
|
|
||||||
Having this will cause Freqtrade to make multiple calls for the same pair, which will obviously be slower than one network request.
|
|
||||||
As a consequence, Freqtrade will take longer to refresh candles - and should therefore be avoided if possible.
|
|
||||||
This is capped to 5 total calls to avoid overloading the exchange, or make freqtrade too slow.
|
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
`startup_candle_count` should be below `ohlcv_candle_limit * 5` (which is 500 * 5 for most exchanges) - since only this amount of candles will be available during Dry-Run/Live Trade operations.
|
`startup_candle_count` should be below `ohlcv_candle_limit` (which is 500 for most exchanges) - since only this amount of candles will be available during Dry-Run/Live Trade operations.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
@ -199,18 +153,18 @@ If this data is available, indicators will be calculated with this extended time
|
|||||||
!!! Note
|
!!! Note
|
||||||
If data for the startup period is not available, then the timerange will be adjusted to account for this startup period - so Backtesting would start at 2019-01-01 08:30:00.
|
If data for the startup period is not available, then the timerange will be adjusted to account for this startup period - so Backtesting would start at 2019-01-01 08:30:00.
|
||||||
|
|
||||||
### Entry signal rules
|
### Buy signal rules
|
||||||
|
|
||||||
Edit the method `populate_entry_trend()` in your strategy file to update your entry strategy.
|
Edit the method `populate_buy_trend()` in your strategy file to update your buy strategy.
|
||||||
|
|
||||||
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
||||||
|
|
||||||
This method will also define a new column, `"enter_long"` (`"enter_short"` for shorts), which needs to contain 1 for entries, and 0 for "no action". `enter_long` is a mandatory column that must be set even if the strategy is shorting only.
|
This method will also define a new column, `"buy"`, which needs to contain 1 for buys, and 0 for "no action".
|
||||||
|
|
||||||
Sample from `user_data/strategies/sample_strategy.py`:
|
Sample from `user_data/strategies/sample_strategy.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Based on TA indicators, populates the buy signal for the given dataframe
|
Based on TA indicators, populates the buy signal for the given dataframe
|
||||||
:param dataframe: DataFrame populated with indicators
|
:param dataframe: DataFrame populated with indicators
|
||||||
@ -224,59 +178,29 @@ def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFram
|
|||||||
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
||||||
),
|
),
|
||||||
['enter_long', 'enter_tag']] = (1, 'rsi_cross')
|
'buy'] = 1
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
??? Note "Enter short trades"
|
|
||||||
Short-entries can be created by setting `enter_short` (corresponds to `enter_long` for long trades).
|
|
||||||
The `enter_tag` column remains identical.
|
|
||||||
Short-trades need to be supported by your exchange and market configuration!
|
|
||||||
Please make sure to set [`can_short`]() appropriately on your strategy if you intend to short.
|
|
||||||
|
|
||||||
```python
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_above(dataframe['rsi'], 30)) & # Signal: RSI crosses above 30
|
|
||||||
(dataframe['tema'] <= dataframe['bb_middleband']) & # Guard
|
|
||||||
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
||||||
),
|
|
||||||
['enter_long', 'enter_tag']] = (1, 'rsi_cross')
|
|
||||||
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_below(dataframe['rsi'], 70)) & # Signal: RSI crosses below 70
|
|
||||||
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard
|
|
||||||
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
||||||
),
|
|
||||||
['enter_short', 'enter_tag']] = (1, 'rsi_cross')
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
Buying requires sellers to buy from - therefore volume needs to be > 0 (`dataframe['volume'] > 0`) to make sure that the bot does not buy/sell in no-activity periods.
|
Buying requires sellers to buy from - therefore volume needs to be > 0 (`dataframe['volume'] > 0`) to make sure that the bot does not buy/sell in no-activity periods.
|
||||||
|
|
||||||
### Exit signal rules
|
### Sell signal rules
|
||||||
|
|
||||||
Edit the method `populate_exit_trend()` into your strategy file to update your exit strategy.
|
Edit the method `populate_sell_trend()` into your strategy file to update your sell strategy.
|
||||||
The exit-signal is only used for exits if `use_exit_signal` is set to true in the configuration.
|
Please note that the sell-signal is only used if `use_sell_signal` is set to true in the configuration.
|
||||||
`use_exit_signal` will not influence [signal collision rules](#colliding-signals) - which will still apply and can prevent entries.
|
|
||||||
|
|
||||||
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
It's important to always return the dataframe without removing/modifying the columns `"open", "high", "low", "close", "volume"`, otherwise these fields would contain something unexpected.
|
||||||
|
|
||||||
This method will also define a new column, `"exit_long"` (`"exit_short"` for shorts), which needs to contain 1 for exits, and 0 for "no action".
|
This method will also define a new column, `"sell"`, which needs to contain 1 for sells, and 0 for "no action".
|
||||||
|
|
||||||
Sample from `user_data/strategies/sample_strategy.py`:
|
Sample from `user_data/strategies/sample_strategy.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Based on TA indicators, populates the exit signal for the given dataframe
|
Based on TA indicators, populates the sell signal for the given dataframe
|
||||||
:param dataframe: DataFrame populated with indicators
|
:param dataframe: DataFrame populated with indicators
|
||||||
:param metadata: Additional information, like the currently traded pair
|
:param metadata: Additional information, like the currently traded pair
|
||||||
:return: DataFrame with buy column
|
:return: DataFrame with buy column
|
||||||
@ -288,39 +212,13 @@ def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame
|
|||||||
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
||||||
),
|
),
|
||||||
['exit_long', 'exit_tag']] = (1, 'rsi_too_high')
|
'sell'] = 1
|
||||||
return dataframe
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
??? Note "Exit short trades"
|
|
||||||
Short-exits can be created by setting `exit_short` (corresponds to `exit_long`).
|
|
||||||
The `exit_tag` column remains identical.
|
|
||||||
Short-trades need to be supported by your exchange and market configuration!
|
|
||||||
|
|
||||||
```python
|
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_above(dataframe['rsi'], 70)) & # Signal: RSI crosses above 70
|
|
||||||
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard
|
|
||||||
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
||||||
),
|
|
||||||
['exit_long', 'exit_tag']] = (1, 'rsi_too_high')
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(qtpylib.crossed_below(dataframe['rsi'], 30)) & # Signal: RSI crosses below 30
|
|
||||||
(dataframe['tema'] < dataframe['bb_middleband']) & # Guard
|
|
||||||
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
|
||||||
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
||||||
),
|
|
||||||
['exit_short', 'exit_tag']] = (1, 'rsi_too_low')
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
### Minimal ROI
|
### Minimal ROI
|
||||||
|
|
||||||
This dict defines the minimal Return On Investment (ROI) a trade should reach before exiting, independent from the exit signal.
|
This dict defines the minimal Return On Investment (ROI) a trade should reach before selling, independent from the sell signal.
|
||||||
|
|
||||||
It is of the following format, with the dict key (left side of the colon) being the minutes passed since the trade opened, and the value (right side of the colon) being the percentage.
|
It is of the following format, with the dict key (left side of the colon) being the minutes passed since the trade opened, and the value (right side of the colon) being the percentage.
|
||||||
|
|
||||||
@ -335,10 +233,10 @@ minimal_roi = {
|
|||||||
|
|
||||||
The above configuration would therefore mean:
|
The above configuration would therefore mean:
|
||||||
|
|
||||||
- Exit whenever 4% profit was reached
|
- Sell whenever 4% profit was reached
|
||||||
- Exit when 2% profit was reached (in effect after 20 minutes)
|
- Sell when 2% profit was reached (in effect after 20 minutes)
|
||||||
- Exit when 1% profit was reached (in effect after 30 minutes)
|
- Sell when 1% profit was reached (in effect after 30 minutes)
|
||||||
- Exit when trade is non-loosing (in effect after 40 minutes)
|
- Sell when trade is non-loosing (in effect after 40 minutes)
|
||||||
|
|
||||||
The calculation does include fees.
|
The calculation does include fees.
|
||||||
|
|
||||||
@ -350,7 +248,7 @@ minimal_roi = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
While technically not completely disabled, this would exit once the trade reaches 10000% Profit.
|
While technically not completely disabled, this would sell once the trade reaches 10000% Profit.
|
||||||
|
|
||||||
To use times based on candle duration (timeframe), the following snippet can be handy.
|
To use times based on candle duration (timeframe), the following snippet can be handy.
|
||||||
This will allow you to change the timeframe for the strategy, and ROI times will still be set as candles (e.g. after 3 candles ...)
|
This will allow you to change the timeframe for the strategy, and ROI times will still be set as candles (e.g. after 3 candles ...)
|
||||||
@ -363,9 +261,9 @@ class AwesomeStrategy(IStrategy):
|
|||||||
timeframe = "1d"
|
timeframe = "1d"
|
||||||
timeframe_mins = timeframe_to_minutes(timeframe)
|
timeframe_mins = timeframe_to_minutes(timeframe)
|
||||||
minimal_roi = {
|
minimal_roi = {
|
||||||
"0": 0.05, # 5% for the first 3 candles
|
"0": 0.05, # 5% for the first 3 candles
|
||||||
str(timeframe_mins * 3): 0.02, # 2% after 3 candles
|
str(timeframe_mins * 3)): 0.02, # 2% after 3 candles
|
||||||
str(timeframe_mins * 6): 0.01, # 1% After 6 candles
|
str(timeframe_mins * 6)): 0.01, # 1% After 6 candles
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -373,51 +271,38 @@ class AwesomeStrategy(IStrategy):
|
|||||||
|
|
||||||
Setting a stoploss is highly recommended to protect your capital from strong moves against you.
|
Setting a stoploss is highly recommended to protect your capital from strong moves against you.
|
||||||
|
|
||||||
Sample of setting a 10% stoploss:
|
Sample:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
stoploss = -0.10
|
stoploss = -0.10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This would signify a stoploss of -10%.
|
||||||
|
|
||||||
For the full documentation on stoploss features, look at the dedicated [stoploss page](stoploss.md).
|
For the full documentation on stoploss features, look at the dedicated [stoploss page](stoploss.md).
|
||||||
|
|
||||||
### Timeframe
|
If your exchange supports it, it's recommended to also set `"stoploss_on_exchange"` in the order_types dictionary, so your stoploss is on the exchange and cannot be missed due to network problems, high load or other reasons.
|
||||||
|
|
||||||
|
For more information on order_types please look [here](configuration.md#understand-order_types).
|
||||||
|
|
||||||
|
### Timeframe (formerly ticker interval)
|
||||||
|
|
||||||
This is the set of candles the bot should download and use for the analysis.
|
This is the set of candles the bot should download and use for the analysis.
|
||||||
Common values are `"1m"`, `"5m"`, `"15m"`, `"1h"`, however all values supported by your exchange should work.
|
Common values are `"1m"`, `"5m"`, `"15m"`, `"1h"`, however all values supported by your exchange should work.
|
||||||
|
|
||||||
Please note that the same entry/exit signals may work well with one timeframe, but not with the others.
|
Please note that the same buy/sell signals may work well with one timeframe, but not with the others.
|
||||||
|
|
||||||
This setting is accessible within the strategy methods as the `self.timeframe` attribute.
|
This setting is accessible within the strategy methods as the `self.timeframe` attribute.
|
||||||
|
|
||||||
### Can short
|
|
||||||
|
|
||||||
To use short signals in futures markets, you will have to let us know to do so by setting `can_short=True`.
|
|
||||||
Strategies which enable this will fail to load on spot markets.
|
|
||||||
Disabling of this will have short signals ignored (also in futures markets).
|
|
||||||
|
|
||||||
### Metadata dict
|
### Metadata dict
|
||||||
|
|
||||||
The metadata-dict (available for `populate_entry_trend`, `populate_exit_trend`, `populate_indicators`) contains additional information.
|
The metadata-dict (available for `populate_buy_trend`, `populate_sell_trend`, `populate_indicators`) contains additional information.
|
||||||
Currently this is `pair`, which can be accessed using `metadata['pair']` - and will return a pair in the format `XRP/BTC`.
|
Currently this is `pair`, which can be accessed using `metadata['pair']` - and will return a pair in the format `XRP/BTC`.
|
||||||
|
|
||||||
The Metadata-dict should not be modified and does not persist information across multiple calls.
|
The Metadata-dict should not be modified and does not persist information across multiple calls.
|
||||||
Instead, have a look at the [Storing information](strategy-advanced.md#Storing-information) section.
|
Instead, have a look at the section [Storing information](strategy-advanced.md#Storing-information)
|
||||||
|
|
||||||
## Strategy file loading
|
## Additional data (informative_pairs)
|
||||||
|
|
||||||
By default, freqtrade will attempt to load strategies from all `.py` files within `user_data/strategies`.
|
|
||||||
|
|
||||||
Assuming your strategy is called `AwesomeStrategy`, stored in the file `user_data/strategies/AwesomeStrategy.py`, then you can start freqtrade with `freqtrade trade --strategy AwesomeStrategy`.
|
|
||||||
Note that we're using the class-name, not the file name.
|
|
||||||
|
|
||||||
You can use `freqtrade list-strategies` to see a list of all strategies Freqtrade is able to load (all strategies in the correct folder).
|
|
||||||
It will also include a "status" field, highlighting potential problems.
|
|
||||||
|
|
||||||
??? Hint "Customize strategy directory"
|
|
||||||
You can use a different directory by using `--strategy-path user_data/otherPath`. This parameter is available to all commands that require a strategy.
|
|
||||||
|
|
||||||
## Informative Pairs
|
|
||||||
|
|
||||||
### Get data for non-tradeable pairs
|
### Get data for non-tradeable pairs
|
||||||
|
|
||||||
@ -444,152 +329,8 @@ A full sample can be found [in the DataProvider section](#complete-data-provider
|
|||||||
It is however better to use resampling to longer timeframes whenever possible
|
It is however better to use resampling to longer timeframes whenever possible
|
||||||
to avoid hammering the exchange with too many requests and risk being blocked.
|
to avoid hammering the exchange with too many requests and risk being blocked.
|
||||||
|
|
||||||
??? Note "Alternative candle types"
|
|
||||||
Informative_pairs can also provide a 3rd tuple element defining the candle type explicitly.
|
|
||||||
Availability of alternative candle-types will depend on the trading-mode and the exchange.
|
|
||||||
In general, spot pairs cannot be used in futures markets, and futures candles can't be used as informative pairs for spot bots.
|
|
||||||
Details about this may vary, if they do, this can be found in the exchange documentation.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
def informative_pairs(self):
|
|
||||||
return [
|
|
||||||
("ETH/USDT", "5m", ""), # Uses default candletype, depends on trading_mode (recommended)
|
|
||||||
("ETH/USDT", "5m", "spot"), # Forces usage of spot candles (only valid for bots running on spot markets).
|
|
||||||
("BTC/TUSD", "15m", "futures"), # Uses futures candles (only bots with `trading_mode=futures`)
|
|
||||||
("BTC/TUSD", "15m", "mark"), # Uses mark candles (only bots with `trading_mode=futures`)
|
|
||||||
]
|
|
||||||
```
|
|
||||||
***
|
***
|
||||||
|
|
||||||
### Informative pairs decorator (`@informative()`)
|
|
||||||
|
|
||||||
In most common case it is possible to easily define informative pairs by using a decorator. All decorated `populate_indicators_*` methods run in isolation,
|
|
||||||
not having access to data from other informative pairs, in the end all informative dataframes are merged and passed to main `populate_indicators()` method.
|
|
||||||
When hyperopting, use of hyperoptable parameter `.value` attribute is not supported. Please use `.range` attribute. See [optimizing an indicator parameter](hyperopt.md#optimizing-an-indicator-parameter)
|
|
||||||
for more information.
|
|
||||||
|
|
||||||
??? info "Full documentation"
|
|
||||||
``` python
|
|
||||||
def informative(timeframe: str, asset: str = '',
|
|
||||||
fmt: Optional[Union[str, Callable[[KwArg(str)], str]]] = None,
|
|
||||||
*,
|
|
||||||
candle_type: Optional[CandleType] = None,
|
|
||||||
ffill: bool = True) -> Callable[[PopulateIndicators], PopulateIndicators]:
|
|
||||||
"""
|
|
||||||
A decorator for populate_indicators_Nn(self, dataframe, metadata), allowing these functions to
|
|
||||||
define informative indicators.
|
|
||||||
|
|
||||||
Example usage:
|
|
||||||
|
|
||||||
@informative('1h')
|
|
||||||
def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
:param timeframe: Informative timeframe. Must always be equal or higher than strategy timeframe.
|
|
||||||
:param asset: Informative asset, for example BTC, BTC/USDT, ETH/BTC. Do not specify to use
|
|
||||||
current pair.
|
|
||||||
:param fmt: Column format (str) or column formatter (callable(name, asset, timeframe)). When not
|
|
||||||
specified, defaults to:
|
|
||||||
* {base}_{quote}_{column}_{timeframe} if asset is specified.
|
|
||||||
* {column}_{timeframe} if asset is not specified.
|
|
||||||
Format string supports these format variables:
|
|
||||||
* {asset} - full name of the asset, for example 'BTC/USDT'.
|
|
||||||
* {base} - base currency in lower case, for example 'eth'.
|
|
||||||
* {BASE} - same as {base}, except in upper case.
|
|
||||||
* {quote} - quote currency in lower case, for example 'usdt'.
|
|
||||||
* {QUOTE} - same as {quote}, except in upper case.
|
|
||||||
* {column} - name of dataframe column.
|
|
||||||
* {timeframe} - timeframe of informative dataframe.
|
|
||||||
:param ffill: ffill dataframe after merging informative pair.
|
|
||||||
:param candle_type: '', mark, index, premiumIndex, or funding_rate
|
|
||||||
"""
|
|
||||||
```
|
|
||||||
|
|
||||||
??? Example "Fast and easy way to define informative pairs"
|
|
||||||
|
|
||||||
Most of the time we do not need power and flexibility offered by `merge_informative_pair()`, therefore we can use a decorator to quickly define informative pairs.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
from freqtrade.strategy import IStrategy, informative
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
# This method is not required.
|
|
||||||
# def informative_pairs(self): ...
|
|
||||||
|
|
||||||
# Define informative upper timeframe for each pair. Decorators can be stacked on same
|
|
||||||
# method. Available in populate_indicators as 'rsi_30m' and 'rsi_1h'.
|
|
||||||
@informative('30m')
|
|
||||||
@informative('1h')
|
|
||||||
def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
# Define BTC/STAKE informative pair. Available in populate_indicators and other methods as
|
|
||||||
# 'btc_rsi_1h'. Current stake currency should be specified as {stake} format variable
|
|
||||||
# instead of hard-coding actual stake currency. Available in populate_indicators and other
|
|
||||||
# methods as 'btc_usdt_rsi_1h' (when stake currency is USDT).
|
|
||||||
@informative('1h', 'BTC/{stake}')
|
|
||||||
def populate_indicators_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
# Define BTC/ETH informative pair. You must specify quote currency if it is different from
|
|
||||||
# stake currency. Available in populate_indicators and other methods as 'eth_btc_rsi_1h'.
|
|
||||||
@informative('1h', 'ETH/BTC')
|
|
||||||
def populate_indicators_eth_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
# Define BTC/STAKE informative pair. A custom formatter may be specified for formatting
|
|
||||||
# column names. A callable `fmt(**kwargs) -> str` may be specified, to implement custom
|
|
||||||
# formatting. Available in populate_indicators and other methods as 'rsi_upper'.
|
|
||||||
@informative('1h', 'BTC/{stake}', '{column}')
|
|
||||||
def populate_indicators_btc_1h_2(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['rsi_upper'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
# Strategy timeframe indicators for current pair.
|
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
||||||
# Informative pairs are available in this method.
|
|
||||||
dataframe['rsi_less'] = dataframe['rsi'] < dataframe['rsi_1h']
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Do not use `@informative` decorator if you need to use data of one informative pair when generating another informative pair. Instead, define informative pairs
|
|
||||||
manually as described [in the DataProvider section](#complete-data-provider-sample).
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Use string formatting when accessing informative dataframes of other pairs. This will allow easily changing stake currency in config without having to adjust strategy code.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
stake = self.config['stake_currency']
|
|
||||||
dataframe.loc[
|
|
||||||
(
|
|
||||||
(dataframe[f'btc_{stake}_rsi_1h'] < 35)
|
|
||||||
&
|
|
||||||
(dataframe['volume'] > 0)
|
|
||||||
),
|
|
||||||
['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')
|
|
||||||
|
|
||||||
return dataframe
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively column renaming may be used to remove stake currency from column names: `@informative('1h', 'BTC/{stake}', fmt='{base}_{column}_{timeframe}')`.
|
|
||||||
|
|
||||||
!!! Warning "Duplicate method names"
|
|
||||||
Methods tagged with `@informative()` decorator must always have unique names! Re-using same name (for example when copy-pasting already defined informative method)
|
|
||||||
will overwrite previously defined method and not produce any errors due to limitations of Python programming language. In such cases you will find that indicators
|
|
||||||
created in earlier-defined methods are not available in the dataframe. Carefully review method names and make sure they are unique!
|
|
||||||
|
|
||||||
## Additional data (DataProvider)
|
## Additional data (DataProvider)
|
||||||
|
|
||||||
The strategy provides access to the `DataProvider`. This allows you to get additional data to use in your strategy.
|
The strategy provides access to the `DataProvider`. This allows you to get additional data to use in your strategy.
|
||||||
@ -620,8 +361,9 @@ Please always check the mode of operation to select the correct method to get da
|
|||||||
### *available_pairs*
|
### *available_pairs*
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
for pair, timeframe in self.dp.available_pairs:
|
if self.dp:
|
||||||
print(f"available {pair}, {timeframe}")
|
for pair, timeframe in self.dp.available_pairs:
|
||||||
|
print(f"available {pair}, {timeframe}")
|
||||||
```
|
```
|
||||||
|
|
||||||
### *current_whitelist()*
|
### *current_whitelist()*
|
||||||
@ -632,9 +374,9 @@ The strategy might look something like this:
|
|||||||
|
|
||||||
*Scan through the top 10 pairs by volume using the `VolumePairList` every 5 minutes and use a 14 day RSI to buy and sell.*
|
*Scan through the top 10 pairs by volume using the `VolumePairList` every 5 minutes and use a 14 day RSI to buy and sell.*
|
||||||
|
|
||||||
Due to the limited available data, it's very difficult to resample `5m` candles into daily candles for use in a 14 day RSI. Most exchanges limit us to just 500-1000 candles which effectively gives us around 1.74 daily candles. We need 14 days at least!
|
Due to the limited available data, it's very difficult to resample our `5m` candles into daily candles for use in a 14 day RSI. Most exchanges limit us to just 500 candles which effectively gives us around 1.74 daily candles. We need 14 days at least!
|
||||||
|
|
||||||
Since we can't resample the data we will have to use an informative pair; and since the whitelist will be dynamic we don't know which pair(s) to use.
|
Since we can't resample our data we will have to use an informative pair; and since our whitelist will be dynamic we don't know which pair(s) to use.
|
||||||
|
|
||||||
This is where calling `self.dp.current_whitelist()` comes in handy.
|
This is where calling `self.dp.current_whitelist()` comes in handy.
|
||||||
|
|
||||||
@ -648,22 +390,20 @@ This is where calling `self.dp.current_whitelist()` comes in handy.
|
|||||||
return informative_pairs
|
return informative_pairs
|
||||||
```
|
```
|
||||||
|
|
||||||
??? Note "Plotting with current_whitelist"
|
|
||||||
Current whitelist is not supported for `plot-dataframe`, as this command is usually used by providing an explicit pairlist - and would therefore make the return values of this method misleading.
|
|
||||||
|
|
||||||
### *get_pair_dataframe(pair, timeframe)*
|
### *get_pair_dataframe(pair, timeframe)*
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
# fetch live / historical candle (OHLCV) data for the first informative pair
|
# fetch live / historical candle (OHLCV) data for the first informative pair
|
||||||
inf_pair, inf_timeframe = self.informative_pairs()[0]
|
if self.dp:
|
||||||
informative = self.dp.get_pair_dataframe(pair=inf_pair,
|
inf_pair, inf_timeframe = self.informative_pairs()[0]
|
||||||
timeframe=inf_timeframe)
|
informative = self.dp.get_pair_dataframe(pair=inf_pair,
|
||||||
|
timeframe=inf_timeframe)
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Warning "Warning about backtesting"
|
!!! Warning "Warning about backtesting"
|
||||||
In backtesting, `dp.get_pair_dataframe()` behavior differs depending on where it's called.
|
Be careful when using dataprovider in backtesting. `historic_ohlcv()` (and `get_pair_dataframe()`
|
||||||
Within `populate_*()` methods, `dp.get_pair_dataframe()` returns the full timerange. Please make sure to not "look into the future" to avoid surprises when running in dry/live mode.
|
for the backtesting runmode) provides the full time-range in one go,
|
||||||
Within [callbacks](strategy-callbacks.md), you'll get the full timerange up to the current (simulated) candle.
|
so please be aware of it and make sure to not "look into the future" to avoid surprises when running in dry/live mode.
|
||||||
|
|
||||||
### *get_analyzed_dataframe(pair, timeframe)*
|
### *get_analyzed_dataframe(pair, timeframe)*
|
||||||
|
|
||||||
@ -672,22 +412,24 @@ It can also be used in specific callbacks to get the signal that caused the acti
|
|||||||
|
|
||||||
``` python
|
``` python
|
||||||
# fetch current dataframe
|
# fetch current dataframe
|
||||||
dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=metadata['pair'],
|
if self.dp:
|
||||||
timeframe=self.timeframe)
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
||||||
|
dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=metadata['pair'],
|
||||||
|
timeframe=self.timeframe)
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Note "No data available"
|
!!! Note "No data available"
|
||||||
Returns an empty dataframe if the requested pair was not cached.
|
Returns an empty dataframe if the requested pair was not cached.
|
||||||
You can check for this with `if dataframe.empty:` and handle this case accordingly.
|
|
||||||
This should not happen when using whitelisted pairs.
|
This should not happen when using whitelisted pairs.
|
||||||
|
|
||||||
### *orderbook(pair, maximum)*
|
### *orderbook(pair, maximum)*
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
if self.dp.runmode.value in ('live', 'dry_run'):
|
if self.dp:
|
||||||
ob = self.dp.orderbook(metadata['pair'], 1)
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
||||||
dataframe['best_bid'] = ob['bids'][0][0]
|
ob = self.dp.orderbook(metadata['pair'], 1)
|
||||||
dataframe['best_ask'] = ob['asks'][0][0]
|
dataframe['best_bid'] = ob['bids'][0][0]
|
||||||
|
dataframe['best_ask'] = ob['asks'][0][0]
|
||||||
```
|
```
|
||||||
|
|
||||||
The orderbook structure is aligned with the order structure from [ccxt](https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure), so the result will look as follows:
|
The orderbook structure is aligned with the order structure from [ccxt](https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure), so the result will look as follows:
|
||||||
@ -716,38 +458,22 @@ Therefore, using `ob['bids'][0][0]` as demonstrated above will result in using t
|
|||||||
### *ticker(pair)*
|
### *ticker(pair)*
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
if self.dp.runmode.value in ('live', 'dry_run'):
|
if self.dp:
|
||||||
ticker = self.dp.ticker(metadata['pair'])
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
||||||
dataframe['last_price'] = ticker['last']
|
ticker = self.dp.ticker(metadata['pair'])
|
||||||
dataframe['volume24h'] = ticker['quoteVolume']
|
dataframe['last_price'] = ticker['last']
|
||||||
dataframe['vwap'] = ticker['vwap']
|
dataframe['volume24h'] = ticker['quoteVolume']
|
||||||
|
dataframe['vwap'] = ticker['vwap']
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
Although the ticker data structure is a part of the ccxt Unified Interface, the values returned by this method can
|
Although the ticker data structure is a part of the ccxt Unified Interface, the values returned by this method can
|
||||||
vary for different exchanges. For instance, many exchanges do not return `vwap` values, some exchanges
|
vary for different exchanges. For instance, many exchanges do not return `vwap` values, the FTX exchange
|
||||||
does not always fills in the `last` field (so it can be None), etc. So you need to carefully verify the ticker
|
does not always fills in the `last` field (so it can be None), etc. So you need to carefully verify the ticker
|
||||||
data returned from the exchange and add appropriate error handling / defaults.
|
data returned from the exchange and add appropriate error handling / defaults.
|
||||||
|
|
||||||
!!! Warning "Warning about backtesting"
|
!!! Warning "Warning about backtesting"
|
||||||
This method will always return up-to-date values - so usage during backtesting / hyperopt without runmode checks will lead to wrong results.
|
This method will always return up-to-date values - so usage during backtesting / hyperopt will lead to wrong results.
|
||||||
|
|
||||||
### Send Notification
|
|
||||||
|
|
||||||
The dataprovider `.send_msg()` function allows you to send custom notifications from your strategy.
|
|
||||||
Identical notifications will only be sent once per candle, unless the 2nd argument (`always_send`) is set to True.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
self.dp.send_msg(f"{metadata['pair']} just got hot!")
|
|
||||||
|
|
||||||
# Force send this notification, avoid caching (Please read warning below!)
|
|
||||||
self.dp.send_msg(f"{metadata['pair']} just got hot!", always_send=True)
|
|
||||||
```
|
|
||||||
|
|
||||||
Notifications will only be sent in trading modes (Live/Dry-run) - so this method can be called without conditions for backtesting.
|
|
||||||
|
|
||||||
!!! Warning "Spamming"
|
|
||||||
You can spam yourself pretty good by setting `always_send=True` in this method. Use this with great care and only in conditions you know will not happen throughout a candle to avoid a message every 5 seconds.
|
|
||||||
|
|
||||||
### Complete Data-provider sample
|
### Complete Data-provider sample
|
||||||
|
|
||||||
@ -800,7 +526,7 @@ class SampleStrategy(IStrategy):
|
|||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
@ -808,7 +534,7 @@ class SampleStrategy(IStrategy):
|
|||||||
(dataframe['rsi_1d'] < 30) & # Ensure daily RSI is < 30
|
(dataframe['rsi_1d'] < 30) & # Ensure daily RSI is < 30
|
||||||
(dataframe['volume'] > 0) # Ensure this candle had volume (important for backtesting)
|
(dataframe['volume'] > 0) # Ensure this candle had volume (important for backtesting)
|
||||||
),
|
),
|
||||||
['enter_long', 'enter_tag']] = (1, 'rsi_cross')
|
'buy'] = 1
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -827,8 +553,6 @@ Options:
|
|||||||
- Merge the dataframe without lookahead bias
|
- Merge the dataframe without lookahead bias
|
||||||
- Forward-fill (optional)
|
- Forward-fill (optional)
|
||||||
|
|
||||||
For a full sample, please refer to the [complete data provider example](#complete-data-provider-sample) below.
|
|
||||||
|
|
||||||
All columns of the informative dataframe will be available on the returning dataframe in a renamed fashion:
|
All columns of the informative dataframe will be available on the returning dataframe in a renamed fashion:
|
||||||
|
|
||||||
!!! Example "Column renaming"
|
!!! Example "Column renaming"
|
||||||
@ -881,15 +605,13 @@ All columns of the informative dataframe will be available on the returning data
|
|||||||
|
|
||||||
### *stoploss_from_open()*
|
### *stoploss_from_open()*
|
||||||
|
|
||||||
Stoploss values returned from `custom_stoploss` must specify a percentage relative to `current_rate`, but sometimes you may want to specify a stoploss relative to the entry point instead. `stoploss_from_open()` is a helper function to calculate a stoploss value that can be returned from `custom_stoploss` which will be equivalent to the desired trade profit above the entry point.
|
Stoploss values returned from `custom_stoploss` must specify a percentage relative to `current_rate`, but sometimes you may want to specify a stoploss relative to the open price instead. `stoploss_from_open()` is a helper function to calculate a stoploss value that can be returned from `custom_stoploss` which will be equivalent to the desired percentage above the open price.
|
||||||
|
|
||||||
??? Example "Returning a stoploss relative to the open price from the custom stoploss function"
|
??? Example "Returning a stoploss relative to the open price from the custom stoploss function"
|
||||||
|
|
||||||
Say the open price was $100, and `current_price` is $121 (`current_profit` will be `0.21`).
|
Say the open price was $100, and `current_price` is $121 (`current_profit` will be `0.21`).
|
||||||
|
|
||||||
If we want a stop price at 7% above the open price we can call `stoploss_from_open(0.07, current_profit, False)` which will return `0.1157024793`. 11.57% below $121 is $107, which is the same as 7% above $100.
|
If we want a stop price at 7% above the open price we can call `stoploss_from_open(0.07, current_profit)` which will return `0.1157024793`. 11.57% below $121 is $107, which is the same as 7% above $100.
|
||||||
|
|
||||||
This function will consider leverage - so at 10x leverage, the actual stoploss would be 0.7% above $100 (0.7% * 10x = 7%).
|
|
||||||
|
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
@ -909,7 +631,7 @@ Stoploss values returned from `custom_stoploss` must specify a percentage relati
|
|||||||
|
|
||||||
# once the profit has risen above 10%, keep the stoploss at 7% above the open price
|
# once the profit has risen above 10%, keep the stoploss at 7% above the open price
|
||||||
if current_profit > 0.10:
|
if current_profit > 0.10:
|
||||||
return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)
|
return stoploss_from_open(0.07, current_profit)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -917,53 +639,15 @@ Stoploss values returned from `custom_stoploss` must specify a percentage relati
|
|||||||
|
|
||||||
Full examples can be found in the [Custom stoploss](strategy-advanced.md#custom-stoploss) section of the Documentation.
|
Full examples can be found in the [Custom stoploss](strategy-advanced.md#custom-stoploss) section of the Documentation.
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Providing invalid input to `stoploss_from_open()` may produce "CustomStoploss function did not return valid stoploss" warnings.
|
|
||||||
This may happen if `current_profit` parameter is below specified `open_relative_stop`. Such situations may arise when closing trade
|
|
||||||
is blocked by `confirm_trade_exit()` method. Warnings can be solved by never blocking stop loss sells by checking `exit_reason` in
|
|
||||||
`confirm_trade_exit()`, or by using `return stoploss_from_open(...) or 1` idiom, which will request to not change stop loss when
|
|
||||||
`current_profit < open_relative_stop`.
|
|
||||||
|
|
||||||
### *stoploss_from_absolute()*
|
|
||||||
|
|
||||||
In some situations it may be confusing to deal with stops relative to current rate. Instead, you may define a stoploss level using an absolute price.
|
|
||||||
|
|
||||||
??? Example "Returning a stoploss using absolute price from the custom stoploss function"
|
|
||||||
|
|
||||||
If we want to trail a stop price at 2xATR below current price we can call `stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate, is_short=trade.is_short)`.
|
|
||||||
|
|
||||||
``` python
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
from freqtrade.strategy import IStrategy, stoploss_from_absolute
|
|
||||||
|
|
||||||
class AwesomeStrategy(IStrategy):
|
|
||||||
|
|
||||||
use_custom_stoploss = True
|
|
||||||
|
|
||||||
def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
||||||
dataframe['atr'] = ta.ATR(dataframe, timeperiod=14)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
|
|
||||||
current_rate: float, current_profit: float, **kwargs) -> float:
|
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
|
||||||
candle = dataframe.iloc[-1].squeeze()
|
|
||||||
return stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate, is_short=trade.is_short)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Additional data (Wallets)
|
## Additional data (Wallets)
|
||||||
|
|
||||||
The strategy provides access to the `wallets` object. This contains the current balances on the exchange.
|
The strategy provides access to the `Wallets` object. This contains the current balances on the exchange.
|
||||||
|
|
||||||
!!! Note "Backtesting / Hyperopt"
|
!!! Note
|
||||||
Wallets behaves differently depending on the function it's called.
|
Wallets is not available during backtesting / hyperopt.
|
||||||
Within `populate_*()` methods, it'll return the full wallet as configured.
|
|
||||||
Within [callbacks](strategy-callbacks.md), you'll get the wallet state corresponding to the actual simulated wallet at that point in the simulation process.
|
|
||||||
|
|
||||||
Please always check if `wallets` is available to avoid failures during backtesting.
|
Please always check if `Wallets` is available to avoid failures during backtesting.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
if self.wallets:
|
if self.wallets:
|
||||||
@ -993,18 +677,38 @@ from freqtrade.persistence import Trade
|
|||||||
The following example queries for the current pair and trades from today, however other filters can easily be added.
|
The following example queries for the current pair and trades from today, however other filters can easily be added.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
trades = Trade.get_trades_proxy(pair=metadata['pair'],
|
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||||
open_date=datetime.now(timezone.utc) - timedelta(days=1),
|
trades = Trade.get_trades([Trade.pair == metadata['pair'],
|
||||||
is_open=False,
|
Trade.open_date > datetime.utcnow() - timedelta(days=1),
|
||||||
]).order_by(Trade.close_date).all()
|
Trade.is_open.is_(False),
|
||||||
# Summarize profit for this pair.
|
]).order_by(Trade.close_date).all()
|
||||||
curdayprofit = sum(trade.close_profit for trade in trades)
|
# Summarize profit for this pair.
|
||||||
|
curdayprofit = sum(trade.close_profit for trade in trades)
|
||||||
```
|
```
|
||||||
|
|
||||||
For a full list of available methods, please consult the [Trade object](trade-object.md) documentation.
|
Get amount of stake_currency currently invested in Trades:
|
||||||
|
|
||||||
|
``` python
|
||||||
|
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||||
|
total_stakes = Trade.total_open_trades_stakes()
|
||||||
|
```
|
||||||
|
|
||||||
|
Retrieve performance per pair.
|
||||||
|
Returns a List of dicts per pair.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||||
|
performance = Trade.get_overall_performance()
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample return value: ETH/BTC had 5 trades, with a total profit of 1.5% (ratio of 0.015).
|
||||||
|
|
||||||
|
``` json
|
||||||
|
{'pair': "ETH/BTC", 'profit': 0.015, 'count': 5}
|
||||||
|
```
|
||||||
|
|
||||||
!!! Warning
|
!!! Warning
|
||||||
Trade history is not available in `populate_*` methods during backtesting or hyperopt, and will result in empty results.
|
Trade history is not available during backtesting or hyperopt.
|
||||||
|
|
||||||
## Prevent trades from happening for a specific pair
|
## Prevent trades from happening for a specific pair
|
||||||
|
|
||||||
@ -1019,8 +723,7 @@ Sometimes it may be desired to lock a pair after certain events happen (e.g. mul
|
|||||||
Freqtrade has an easy method to do this from within the strategy, by calling `self.lock_pair(pair, until, [reason])`.
|
Freqtrade has an easy method to do this from within the strategy, by calling `self.lock_pair(pair, until, [reason])`.
|
||||||
`until` must be a datetime object in the future, after which trading will be re-enabled for that pair, while `reason` is an optional string detailing why the pair was locked.
|
`until` must be a datetime object in the future, after which trading will be re-enabled for that pair, while `reason` is an optional string detailing why the pair was locked.
|
||||||
|
|
||||||
Locks can also be lifted manually, by calling `self.unlock_pair(pair)` or `self.unlock_reason(<reason>)` - providing reason the pair was locked with.
|
Locks can also be lifted manually, by calling `self.unlock_pair(pair)`.
|
||||||
`self.unlock_reason(<reason>)` will unlock all pairs currently locked with the provided reason.
|
|
||||||
|
|
||||||
To verify if a pair is currently locked, use `self.is_pair_locked(pair)`.
|
To verify if a pair is currently locked, use `self.is_pair_locked(pair)`.
|
||||||
|
|
||||||
@ -1040,10 +743,11 @@ from datetime import timedelta, datetime, timezone
|
|||||||
|
|
||||||
# Within populate indicators (or populate_buy):
|
# Within populate indicators (or populate_buy):
|
||||||
if self.config['runmode'].value in ('live', 'dry_run'):
|
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||||
# fetch closed trades for the last 2 days
|
# fetch closed trades for the last 2 days
|
||||||
trades = Trade.get_trades_proxy(
|
trades = Trade.get_trades([Trade.pair == metadata['pair'],
|
||||||
pair=metadata['pair'], is_open=False,
|
Trade.open_date > datetime.utcnow() - timedelta(days=2),
|
||||||
open_date=datetime.now(timezone.utc) - timedelta(days=2))
|
Trade.is_open.is_(False),
|
||||||
|
]).all()
|
||||||
# Analyze the conditions you'd like to lock the pair .... will probably be different for every strategy
|
# Analyze the conditions you'd like to lock the pair .... will probably be different for every strategy
|
||||||
sumprofit = sum(trade.close_profit for trade in trades)
|
sumprofit = sum(trade.close_profit for trade in trades)
|
||||||
if sumprofit < 0:
|
if sumprofit < 0:
|
||||||
@ -1053,16 +757,16 @@ if self.config['runmode'].value in ('live', 'dry_run'):
|
|||||||
|
|
||||||
## Print created dataframe
|
## Print created dataframe
|
||||||
|
|
||||||
To inspect the created dataframe, you can issue a print-statement in either `populate_entry_trend()` or `populate_exit_trend()`.
|
To inspect the created dataframe, you can issue a print-statement in either `populate_buy_trend()` or `populate_sell_trend()`.
|
||||||
You may also want to print the pair so it's clear what data is currently shown.
|
You may also want to print the pair so it's clear what data is currently shown.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
#>> whatever condition<<<
|
#>> whatever condition<<<
|
||||||
),
|
),
|
||||||
['enter_long', 'enter_tag']] = (1, 'somestring')
|
'buy'] = 1
|
||||||
|
|
||||||
# Print the Analyzed pair
|
# Print the Analyzed pair
|
||||||
print(f"result for {metadata['pair']}")
|
print(f"result for {metadata['pair']}")
|
||||||
@ -1077,8 +781,6 @@ Printing more than a few rows is also possible (simply use `print(dataframe)` i
|
|||||||
|
|
||||||
## Common mistakes when developing strategies
|
## Common mistakes when developing strategies
|
||||||
|
|
||||||
### Peeking into the future while backtesting
|
|
||||||
|
|
||||||
Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future.
|
Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future.
|
||||||
This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods, since they all use data which is not available during dry/live runs, so these strategies will perform well during backtesting, but will fail / perform badly in real conditions.
|
This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods, since they all use data which is not available during dry/live runs, so these strategies will perform well during backtesting, but will fail / perform badly in real conditions.
|
||||||
|
|
||||||
@ -1089,18 +791,9 @@ The following lists some common patterns which should be avoided to prevent frus
|
|||||||
- don't use `dataframe['volume'].mean()`. This uses the full DataFrame for backtesting, including data from the future. Use `dataframe['volume'].rolling(<window>).mean()` instead
|
- don't use `dataframe['volume'].mean()`. This uses the full DataFrame for backtesting, including data from the future. Use `dataframe['volume'].rolling(<window>).mean()` instead
|
||||||
- don't use `.resample('1h')`. This uses the left border of the interval, so moves data from an hour to the start of the hour. Use `.resample('1h', label='right')` instead.
|
- don't use `.resample('1h')`. This uses the left border of the interval, so moves data from an hour to the start of the hour. Use `.resample('1h', label='right')` instead.
|
||||||
|
|
||||||
### Colliding signals
|
|
||||||
|
|
||||||
When conflicting signals collide (e.g. both `'enter_long'` and `'exit_long'` are 1), freqtrade will do nothing and ignore the entry signal. This will avoid trades that enter, and exit immediately. Obviously, this can potentially lead to missed entries.
|
|
||||||
|
|
||||||
The following rules apply, and entry signals will be ignored if more than one of the 3 signals is set:
|
|
||||||
|
|
||||||
- `enter_long` -> `exit_long`, `enter_short`
|
|
||||||
- `enter_short` -> `exit_short`, `enter_long`
|
|
||||||
|
|
||||||
## Further strategy ideas
|
## Further strategy ideas
|
||||||
|
|
||||||
To get additional Ideas for strategies, head over to the [strategy repository](https://github.com/freqtrade/freqtrade-strategies). Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk.
|
To get additional Ideas for strategies, head over to our [strategy repository](https://github.com/freqtrade/freqtrade-strategies). Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk.
|
||||||
Feel free to use any of them as inspiration for your own strategies.
|
Feel free to use any of them as inspiration for your own strategies.
|
||||||
We're happy to accept Pull Requests containing new Strategies to that repo.
|
We're happy to accept Pull Requests containing new Strategies to that repo.
|
||||||
|
|
||||||
|