Compare commits

..

5 Commits

Author SHA1 Message Date
Matthias bae2f98e5f chore: bump pyarrow wheel for 3.13 2026-02-01 17:55:37 +01:00
Matthias e88e3617c7 chore: bump pi image to trixie 2026-02-01 17:54:02 +01:00
Matthias 7cd97d9cfd chore: simplify docker install 2026-02-01 17:54:02 +01:00
Matthias 12a9f0e1b1 chore: bump armhf dockerfile to python 3.13 2026-02-01 17:54:02 +01:00
Matthias 6bb78edd96 chore: add pyarrow 3.13 armv7 wheel 2026-02-01 17:54:01 +01:00
231 changed files with 42908 additions and 55337 deletions
+5 -13
View File
@@ -1,10 +1,8 @@
version: 2
updates:
- package-ecosystem: docker # zizmor: ignore[dependabot-cooldown] Docker does not support cooldowns at the moment.
# Docker does not support cooldowns at the moment.
# https://github.com/dependabot/dependabot-core/issues/14044
# cooldown:
# default-days: 7
- package-ecosystem: docker
cooldown:
default-days: 7
directories:
- "/"
- "/docker"
@@ -49,11 +47,7 @@ updates:
patterns:
- "scipy"
- "scipy-stubs"
gymnasium:
patterns:
- "gymnasium"
- "stable-baselines3"
- "sb3-contrib"
- package-ecosystem: "github-actions"
directory: "/"
cooldown:
@@ -67,7 +61,5 @@ updates:
groups:
actions:
patterns:
# Combine updates for github provided actions
- "actions/*"
docker:
patterns:
- "docker/*"
@@ -2,7 +2,7 @@ name: Binance Leverage tiers update
on:
schedule:
- cron: "25 2 * * 4"
- cron: "0 3 * * 4"
# on demand
workflow_dispatch:
@@ -24,15 +24,12 @@ jobs:
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
activate-environment: true
enable-cache: false
python-version: "3.14"
python-version: "3.12"
- name: Install ccxt
run: uv pip install $(grep -E "^ccxt==" requirements.txt) $(grep -E "^orjson==" requirements.txt)
run: pip install ccxt
- name: Run leverage tier update
env:
@@ -42,7 +39,7 @@ jobs:
run: python build_helpers/binance_update_lev_tiers.py
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
- uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
add-paths: freqtrade/exchange/binance_leverage_tiers.json
@@ -51,7 +48,7 @@ jobs:
Dependencies
branch: update/binance-leverage-tiers
title: Update Binance Leverage Tiers
commit-message: "chore: update binance leverage tiers"
commit-message: "chore: update pre-commit hooks"
committer: Freqtrade Bot <154552126+freqtrade-bot@users.noreply.github.com>
author: Freqtrade Bot <154552126+freqtrade-bot@users.noreply.github.com>
body: Update binance leverage tiers.
+73 -61
View File
@@ -32,8 +32,13 @@ jobs:
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
with:
activate-environment: true
enable-cache: true
@@ -50,6 +55,7 @@ jobs:
- name: Installation (python)
run: |
uv pip install --upgrade wheel
uv pip install -r requirements-dev.txt
uv pip install -e ft_client/
uv pip install -e .
@@ -68,11 +74,11 @@ jobs:
run: |
pytest --random-order --cov=freqtrade --cov=freqtrade_client --cov-config=.coveragerc
- uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
- uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-24.04')
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }} # zizmor: ignore[secrets-outside-env] Intentionally not using environment variable.
token: ${{ secrets.CODECOV_TOKEN }}
- name: Cleanup codecov dirty state files
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-24.04')
@@ -131,6 +137,10 @@ jobs:
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 --output-format=github
@@ -150,22 +160,19 @@ jobs:
run: |
$PSVersionTable
Get-PSRepository | Format-List *
if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
Register-PSRepository -Default
}
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module -Name Pester -RequiredVersion 5.7.1 -Confirm:$false -Force -SkipPublisherCheck
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name Pester -RequiredVersion 5.3.1 -Confirm:$false -Force -SkipPublisherCheck
$Error.clear()
Invoke-Pester -Path "tests" -CI
if ($Error.Length -gt 0) {exit 1}
- name: Discord notification
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
uses: rjstone/discord-webhook-notify@c2597273488aeda841dd1e891321952b51f7996f #v2.2.1
if: ${{ failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) }}
with:
color: '#FF0000' # red
title: Freqtrade CI failed on ${{ matrix.os }} with Python ${{ matrix.python-version }}!
webhook: ${{ secrets.DISCORD_WEBHOOK }} # zizmor: ignore[secrets-outside-env] Intentionally not using environment variable.
severity: error
details: Freqtrade CI failed on ${{ matrix.os }} with Python ${{ matrix.python-version }}!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
mypy-version-check:
name: "Mypy Version Check"
@@ -175,15 +182,14 @@ jobs:
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 #v6.1.0
with:
activate-environment: true
python-version: "3.13"
python-version: "3.12"
- name: pre-commit dependencies
run: |
uv pip install $(grep -E "^pyyaml==" requirements-dev.txt)
pip install pyaml
python build_helpers/pre_commit_update.py
pre-commit:
@@ -194,11 +200,9 @@ jobs:
with:
persist-credentials: false
- name: Set up Python 🐍
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: "3.13"
python-version: "3.12"
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
docs-check:
@@ -213,49 +217,51 @@ jobs:
run: |
./tests/test_docs.sh
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
activate-environment: true
python-version: "3.13"
python-version: "3.12"
- name: Documentation build
run: |
uv pip install -r docs/requirements-docs.txt
pip install -r docs/requirements-docs.txt
mkdocs build
- name: Discord notification
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
uses: rjstone/discord-webhook-notify@c2597273488aeda841dd1e891321952b51f7996f #v2.2.1
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
with:
color: '#FF0000' # red
title: Freqtrade doc test failed!
webhook: ${{ secrets.DISCORD_WEBHOOK }} # zizmor: ignore[secrets-outside-env] Intentionally not using environment variable.
severity: error
details: Freqtrade doc test failed!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
build-linux-online:
# Run pytest with "live" checks
name: "Online / live tests"
name: "Tests and Linting - Online tests"
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
with:
activate-environment: true
enable-cache: true
python-version: "${{ matrix.python-version }}"
python-version: "3.12"
cache-dependency-glob: "requirements**.txt"
cache-suffix: "3.12"
- name: Installation - *nix
run: |
uv pip install --upgrade wheel
uv pip install -r requirements-dev.txt
uv pip install -e ft_client/
uv pip install -e .
@@ -279,13 +285,22 @@ jobs:
if: github.event_name != 'schedule' && github.repository == 'freqtrade/freqtrade'
steps:
- name: Discord notification
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
- name: Check user permission
id: check
continue-on-error: true
uses: prince-chrismc/check-actor-permissions-action@d504e74ba31658f4cdf4fcfeb509d4c09736d88e # v3.0.2
with:
color: '#00FF00' # green
title: Test Completed!
webhook: ${{ secrets.DISCORD_WEBHOOK }} # zizmor: ignore[secrets-outside-env] Intentionally not using environment variable.
permission: "write"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Discord notification
uses: rjstone/discord-webhook-notify@c2597273488aeda841dd1e891321952b51f7996f #v2.2.1
if: steps.check.outputs.permitted == 'true' && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
with:
severity: info
details: Test Completed!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
build:
if: always()
@@ -297,9 +312,6 @@ jobs:
pre-commit,
]
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.13"]
steps:
@@ -312,19 +324,18 @@ jobs:
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
activate-environment: true
python-version: "${{ matrix.python-version }}"
python-version: "3.12"
- name: Build distribution
run: |
uv pip install $(grep -E "^build==" requirements-dev.txt)
pip install -U build
python -m build --sdist --wheel
- name: Upload artifacts 📦
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.1.0
with:
name: freqtrade-build
path: |
@@ -333,10 +344,11 @@ jobs:
- name: Build Client distribution
run: |
pip install -U build
python -m build --sdist --wheel ft_client
- name: Upload artifacts 📦
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.1.0
with:
name: freqtrade-client-build
path: |
@@ -360,14 +372,14 @@ jobs:
persist-credentials: false
- name: Download artifact 📦
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
pattern: freqtrade*-build
path: dist
merge-multiple: true
- name: Publish to PyPI (Test)
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
with:
repository-url: https://test.pypi.org/legacy/
@@ -389,14 +401,14 @@ jobs:
persist-credentials: false
- name: Download artifact 📦
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
pattern: freqtrade*-build
path: dist
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
docker-build:
@@ -410,9 +422,9 @@ jobs:
packages: write # Needed to push package versions
contents: read
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} # zizmor: ignore[secrets-outside-env] Intentionally not using environment variable.
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
packages-cleanup:
+5 -5
View File
@@ -26,15 +26,15 @@ jobs:
with:
persist-credentials: true
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
activate-environment: true
python-version: '3.13'
python-version: '3.12'
- name: Install dependencies
run: |
uv pip install -r docs/requirements-docs.txt
python -m pip install --upgrade pip
pip install -r docs/requirements-docs.txt
- name: Fetch gh-pages branch
run: |
+2 -2
View File
@@ -31,13 +31,13 @@ jobs:
with:
persist-credentials: false
- name: Login to GitHub Container Registry
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pre-build dev container image
uses: devcontainers/ci@b63b30de439b47a52267f241112c5b453b673db5 # v0.3.1900000449
uses: devcontainers/ci@8bf61b26e9c3a98f69cb6ce2f88d24ff59b785c6 # v0.3.19
with:
subFolder: .github
imageName: ghcr.io/${{ github.repository }}-devcontainer
+15 -18
View File
@@ -3,9 +3,9 @@ name: Docker Build and Deploy
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
DOCKER_PASSWORD:
required: true
DOCKERHUB_TOKEN:
DOCKER_USERNAME:
required: true
DISCORD_WEBHOOK:
required: false
@@ -35,8 +35,6 @@ jobs:
name: "Deploy Docker x64 and armv7l"
runs-on: ubuntu-22.04
if: github.repository == 'freqtrade/freqtrade'
environment:
name: docker
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -59,19 +57,19 @@ jobs:
uses: ./.github/actions/docker-tags
- name: Login to Docker Hub
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
with:
cache-image: false
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f #v3.12.0
- name: Available platforms
run: echo ${PLATFORMS}
@@ -170,8 +168,6 @@ jobs:
# Only run on 64bit machines
runs-on: [self-hosted, linux, ARM64]
if: github.repository == 'freqtrade/freqtrade'
environment:
name: docker
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -183,13 +179,13 @@ jobs:
uses: ./.github/actions/docker-tags
- name: Login to Docker Hub
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to github
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
@@ -310,8 +306,9 @@ jobs:
docker image prune -a --force --filter "until=24h"
- name: Discord notification
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
uses: rjstone/discord-webhook-notify@c2597273488aeda841dd1e891321952b51f7996f #v2.2.1
if: always() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) && (github.event_name != 'schedule')
with:
title: Deploy Succeeded!
webhook: ${{ secrets.DISCORD_WEBHOOK }}
severity: info
details: Deploy Succeeded!
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
+2 -5
View File
@@ -3,7 +3,6 @@ on:
push:
branches:
- stable
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
@@ -16,8 +15,6 @@ jobs:
dockerHubDescription:
name: "Update Docker Hub Description"
runs-on: ubuntu-latest
environment:
name: docker
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
@@ -26,6 +23,6 @@ jobs:
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: freqtradeorg/freqtrade
@@ -1,53 +0,0 @@
name: Pre-commit Types update
on:
pull_request:
branches:
- "develop"
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}"
cancel-in-progress: true
permissions: {}
jobs:
mypy-version-update:
name: "Pre-commit mypy type versions update"
runs-on: ubuntu-24.04
# Only run this job for pull requests created by dependabot[bot]
if: >
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.repository == github.event.pull_request.head.repo.full_name &&
github.event_name == 'pull_request' &&
startsWith(github.head_ref, 'dependabot/')
environment:
name: dependabot-pulls
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
token: ${{ secrets.REPO_SCOPED_TOKEN_DEP }}
ref: ${{ github.head_ref || github.ref }}
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
activate-environment: true
python-version: "3.13"
- name: Install PyYAML
run: |
- name: pre-commit dependencies
run: |
uv pip install $(grep -E "^pyyaml==" requirements-dev.txt)
python build_helpers/pre_commit_update.py --update
- uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7
with:
commit_message: "chore(deps): Apply pre-commit types update"
commit_user_name: Freqtrade Bot
commit_user_email: 154552126+freqtrade-bot@users.noreply.github.com
commit_author: Freqtrade Bot <154552126+freqtrade-bot@users.noreply.github.com>
+6 -10
View File
@@ -2,7 +2,7 @@ name: Pre-commit auto-update
on:
schedule:
- cron: "13 1 * * 2"
- cron: "0 3 * * 2"
# on demand
workflow_dispatch:
@@ -17,27 +17,23 @@ jobs:
auto-update:
name: Auto-update pre-commit hooks
runs-on: ubuntu-latest
environment:
name: develop
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install uv and Python 🐍
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
activate-environment: true
python-version: "3.13"
python-version: "3.12"
- name: Install pre-commit
run: uv pip install $(grep -E "^pre-commit==" requirements-dev.txt)
run: pip install pre-commit
- name: Run auto-update
run: pre-commit autoupdate
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
- uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
add-paths: .pre-commit-config.yaml
+1 -1
View File
@@ -31,4 +31,4 @@ jobs:
persist-credentials: false
- name: Run zizmor 🌈
uses: zizmorcore/zizmor-action@5f14fd08f7cf1cb1609c1e344975f152c7ee938d # v0.5.6
uses: zizmorcore/zizmor-action@135698455da5c3b3e55f73f4419e481ab68cdd95 # v0.4.1
+23 -10
View File
@@ -13,25 +13,38 @@ repos:
pass_filenames: false
additional_dependencies: ["python-rapidjson", "jsonschema"]
- repo: https://github.com/pycqa/flake8
rev: "7.3.0"
hooks:
- id: flake8
additional_dependencies: [Flake8-pyproject]
# stages: [push]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v2.1.0"
rev: "v1.19.1"
hooks:
- id: mypy
exclude: build_helpers
additional_dependencies:
- types-cachetools==7.0.0.20260518
- types-cachetools==6.2.0.20251022
- types-filelock==3.2.7
- types-requests==2.33.0.20260518
- types-tabulate==0.10.0.20260508
- types-python-dateutil==2.9.0.20260518
- scipy-stubs==1.17.1.4
- SQLAlchemy==2.0.49
- types-requests==2.32.4.20260107
- types-tabulate==0.9.0.20241207
- types-python-dateutil==2.9.0.20251115
- scipy-stubs==1.17.0.1
- SQLAlchemy==2.0.45
# stages: [push]
- repo: https://github.com/pycqa/isort
rev: "7.0.0"
hooks:
- id: isort
name: isort (python)
# stages: [push]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.15.13'
rev: 'v0.14.14'
hooks:
- id: ruff
- id: ruff-format
@@ -62,7 +75,7 @@ repos:
- id: strip-exif
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
@@ -70,6 +83,6 @@ repos:
# Ensure github actions remain safe
- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v1.24.1
rev: v1.22.0
hooks:
- id: zizmor
+3 -3
View File
@@ -12,8 +12,7 @@ Few pointers for contributions:
- Stick to english in both commit messages, PR descriptions and code comments and variable names.
- New features need to contain unit tests, must pass CI (run pre-commit and pytest to get an early feedback) and should be documented with the introduction PR.
- PR's can be declared as draft - signaling Work in Progress for Pull Requests (which are not finished). We'll still aim to provide feedback on draft PR's in a timely manner.
- If you're using AI for your PR, please both mention it in the PR description and do a thorough review of the generated code yourself.
The final responsibility for the code with the PR author, not with the AI, which also means that commits must be linked to your (human) account, not some generic AI account.
- If you're using AI for your PR, please both mention it in the PR description and do a thorough review of the generated code. The final responsibility for the code with the PR author, not with the AI.
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.
@@ -25,7 +24,8 @@ Best start by reading the [documentation](https://www.freqtrade.io/) to get a fe
### 1. Run unit tests
All unit tests must pass. If a unit test is broken, change your code to make it pass. It means you have introduced a regression.
All unit tests must pass. If a unit test is broken, change your code to
make it pass. It means you have introduced a regression.
#### Test the whole project
+5 -7
View File
@@ -1,4 +1,4 @@
FROM python:3.14.5-slim-trixie AS base
FROM python:3.13.11-slim-trixie AS base
# Setup env
ENV LANG=C.UTF-8
@@ -16,7 +16,8 @@ RUN mkdir /freqtrade \
&& useradd -u 1000 -G sudo -U -m -s /bin/bash ftuser \
&& chown ftuser:ftuser /freqtrade \
# Allow sudoers
&& echo "ftuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers
&& echo "ftuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers \
&& pip install --upgrade pip
WORKDIR /freqtrade
@@ -24,14 +25,11 @@ WORKDIR /freqtrade
FROM base AS python-deps
RUN apt-get update \
&& apt-get -y install build-essential libssl-dev git libffi-dev libgfortran5 pkg-config cmake gcc \
&& apt-get clean \
&& pip install --upgrade pip wheel
&& apt-get clean
# Install dependencies
COPY --chown=ftuser:ftuser requirements.txt requirements-hyperopt.txt /freqtrade/
USER ftuser
RUN pip install --user --no-cache-dir "numpy<3.0" \
&& pip install --user --no-cache-dir -r requirements-hyperopt.txt
RUN pip install --user --no-cache-dir -r requirements-hyperopt.txt
# Copy dependencies to runtime-image
FROM base AS runtime-image
+4 -6
View File
@@ -2,9 +2,8 @@
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/freqtrade/freqtrade/actions/workflows/ci.yml)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04864/status.svg)](https://doi.org/10.21105/joss.04864)
[![codecov](https://codecov.io/gh/freqtrade/freqtrade/branch/develop/graph/badge.svg?token=AD5BG3ATKI)](https://codecov.io/gh/freqtrade/freqtrade)
[![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)
[![Discord Server](https://img.shields.io/badge/Freqtrade_Discord-4E4E4E?logo=discord)](https://discord.gg/p7nuUNVfP7)
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.
@@ -25,7 +24,7 @@ hesitate to read the source code and understand the mechanism of this bot.
## Supported Exchange marketplaces
Please read the [exchange-specific notes](https://www.freqtrade.io/en/stable/exchanges/) to learn about special configurations that maybe needed for each exchange.
Please read the [exchange-specific notes](docs/exchanges.md) to learn about special configurations that maybe needed for each exchange.
### Supported Spot Exchanges
@@ -50,9 +49,8 @@ Please read the [exchange-specific notes](https://www.freqtrade.io/en/stable/exc
- [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX)
- [X] [OKX](https://okx.com/)
- [X] [Bybit](https://bybit.com/)
- [X] [Kraken](https://www.kraken.com/features/futures)
Please make sure to read the [exchange specific notes](https://www.freqtrade.io/en/stable/exchanges/), as well as the [trading with leverage](https://www.freqtrade.io/en/stable/leverage/) documentation before diving in.
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
@@ -144,7 +142,7 @@ options:
### 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/stable/telegram-usage/)
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/)
- `/start`: Starts the trader.
- `/stop`: Stops the trader.
+1 -1
View File
@@ -87,7 +87,7 @@ def extract_command_partials():
help_output = _get_help_output(subparser)
_write_partial_file(f"docs/commands/{command}.md", help_output)
else:
print(f" Warning: subcommand '{command}' not found in parser")
print(f" Warning: subcommand '{command}' not found in parser")
# freqtrade-client still uses subprocess as requested
print("Running for freqtrade-client")
+2 -42
View File
@@ -1,7 +1,5 @@
# File used in CI to ensure pre-commit dependencies are kept up-to-date.
import argparse
import re
import sys
from pathlib import Path
@@ -12,24 +10,6 @@ pre_commit_file = Path(".pre-commit-config.yaml")
require_dev = Path("requirements-dev.txt")
require = Path("requirements.txt")
parser = argparse.ArgumentParser()
parser.add_argument("--update", action="store_true")
args = parser.parse_args()
def replace_dependency_version(pre_commit_text: str, dependency: str) -> tuple[str, bool]:
"""
Regex-based replacement of a dependency version in the pre-commit config file.
using regex here ensures we only replace the version of the dependency while
keeping the overall file intact.
"""
package_name = dependency.split("==", 1)[0]
pattern = re.compile(rf"^(\s*-\s+){re.escape(package_name)}==.*$", re.MULTILINE)
updated_text, replacements = pattern.subn(rf"\1{dependency}", pre_commit_text, count=1)
return updated_text, replacements > 0 and updated_text != pre_commit_text
with require_dev.open("r") as rfile:
requirements = rfile.readlines()
@@ -43,18 +23,6 @@ supported = ("types-", "SQLAlchemy", "scipy-stubs")
# Only keep the first part of the line up to the first space
type_reqs = [r.strip("\n").split()[0] for r in requirements if r.startswith(supported)]
with pre_commit_file.open("r") as file:
pre_commit_text = file.read()
updated = False
for req in type_reqs:
pre_commit_text, req_updated = replace_dependency_version(pre_commit_text, req)
updated = updated or req_updated
if args.update and updated:
with pre_commit_file.open("w") as file:
file.write(pre_commit_text)
with pre_commit_file.open("r") as file:
f = yaml.load(file, Loader=yaml.SafeLoader)
@@ -72,20 +40,12 @@ for hook in hooks:
for req in type_reqs:
if req not in hooks:
errors.append(f"{req} is missing in pre-commit config file.")
if updated:
if args.update:
errors.append(".pre-commit-config.yaml was updated to match the requirements files.")
else:
errors.append(
".pre-commit-config.yaml is outdated. Run build_helpers/pre_commit_update.py --update."
)
errors.append(f"{req} is missing in pre-config file.")
if errors:
for e in errors:
print(e)
sys.exit(1 if not (args.update and updated) else 0)
sys.exit(1)
sys.exit(0)
+2 -10
View File
@@ -283,10 +283,6 @@
"month"
]
},
"skip_wallet_history_migration": {
"description": "Disable wallet history migration.",
"type": "boolean"
},
"hyperopt_path": {
"description": "Specify additional lookup path for Hyperopt Loss functions.",
"type": "string"
@@ -653,7 +649,6 @@
"ProducerPairList",
"RemotePairList",
"MarketCapPairList",
"CrossMarketPairList",
"AgeFilter",
"DelistFilter",
"FullTradesFilter",
@@ -1062,9 +1057,7 @@
},
"jwt_secret_key": {
"description": "Secret key for JWT authentication.",
"type": "string",
"default": "somethingRandomSomethingRandom123",
"minLength": 32
"type": "string"
},
"CORS_origins": {
"description": "List of allowed CORS origins.",
@@ -1087,8 +1080,7 @@
"listen_ip_address",
"listen_port",
"username",
"password",
"jwt_secret_key"
"password"
]
},
"db_url": {
+1 -1
View File
@@ -70,7 +70,7 @@
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "error",
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "freqtrader",
"password": "SuperSecurePassword"
+2 -2
View File
@@ -177,7 +177,7 @@
"listen_port": 8080,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "freqtrader",
"password": "SuperSecurePassword",
@@ -215,4 +215,4 @@
"reduce_df_footprint": false,
"dataformat_ohlcv": "feather",
"dataformat_trades": "feather"
}
}
+1 -1
View File
@@ -75,7 +75,7 @@
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "error",
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "freqtrader",
"password": "SuperSecurePassword"
+4 -4
View File
@@ -1,4 +1,4 @@
FROM python:3.11.15-slim-bookworm AS base
FROM python:3.13.11-slim-trixie AS base
# Setup env
ENV LANG=C.UTF-8
@@ -13,7 +13,7 @@ RUN mkdir /freqtrade \
&& apt-get update \
&& apt-get -y install sudo libatlas3-base libopenblas-dev curl sqlite3 libutf8proc-dev libsnappy-dev \
&& apt-get clean \
&& useradd -u 1000 -G sudo -U -m ftuser \
&& useradd -u 1000 -G sudo -U -m -s /bin/bash ftuser \
&& chown ftuser:ftuser /freqtrade \
# Allow sudoers
&& echo "ftuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers \
@@ -24,12 +24,12 @@ WORKDIR /freqtrade
# Install dependencies
FROM base AS python-deps
RUN apt-get update \
&& apt-get -y install build-essential libssl-dev libffi-dev libgfortran5 pkg-config cmake gcc \
&& apt-get -y install build-essential libssl-dev git libffi-dev libgfortran5 pkg-config cmake gcc \
&& apt-get clean \
&& echo "[global]\nextra-index-url=https://www.piwheels.org/simple" > /etc/pip.conf
# Install TA-lib
COPY build_helpers/* /tmp/
COPY build_helpers/*.whl /tmp/
# Install dependencies
COPY --chown=ftuser:ftuser requirements.txt /freqtrade/
+2 -2
View File
@@ -73,7 +73,7 @@ services:
volumes:
- "./user_data:/freqtrade/user_data"
# 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.
ports:
- "127.0.0.1:8080:8080"
@@ -100,7 +100,7 @@ services:
volumes:
- "./user_data:/freqtrade/user_data"
# 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.
ports:
- "127.0.0.1:8081:8080"
+162 -203
View File
@@ -160,131 +160,117 @@ The most important in the backtesting is to understand the result.
A backtesting result will look like that:
```
BACKTESTING REPORT
┏━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Pair ┃ Trades ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ LTC/USDT:USDT │ 16 │ 1.01 │ 56.882 │ 5.69 │ 16:16:00 │ 16 0 0 100 │
│ ETC/USDT:USDT │ 12 │ 0.7331.513 │ 3.15 │ 9:55:00 │ 11 0 1 91.7 │
│ ETH/USDT:USDT │ 8 │ 0.6918.659 │ 1.87 │ 1 day, 13:55:00 │ 7 0 1 87.5 │
│ XLM/USDT:USDT │ 10 │ 0.3 │ 10.694 │ 1.07 │ 12:08:00 │ 9 0 1 90.0 │
│ BTC/USDT:USDT │ 8 │ 0.22 │ 7.502 │ 0.75 │ 3 days, 1:24:00 │ 6 0 2 75.0 │
│ XRP/USDT:USDT │ 9 │ -0.13-6.837 │ -0.68 │ 21:18:00 │ 8 0 1 88.9 │
│ DOT/USDT:USDT │ 6 │ -0.39 │ -9.169 │ -0.92 │ 5:35:00 │ 4 0 2 66.7 │
│ ADA/USDT:USDT │ 8 │ -1.75 │ -52.089 │ -5.21 │ 11:38:00 │ 6 0 2 75.0 │
│ TOTAL │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │
└───────────────┴────────┴──────────────┴─────────────┴──────────────┴─────────────────┴────────────────────────┘
LEFT OPEN TRADES REPORT
┏━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Pair ┃ Trades ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ BTC/USDT:USDT │ 1 │ -4.14 │ -9.930 │ -0.99 │ 17 days, 8:00:00 │ 0 0 1 0 │
│ ETC/USDT:USDT │ 1 │ -4.24 │ -15.365 │ -1.54 │ 10:40:00 │ 0 0 1 0 │
│ DOT/USDT:USDT │ 1 │ -5.29 │ -19.166 │ -1.92 │ 11:30:00 │ 0 0 1 0 │
│ TOTAL │ 3 │ -4.56 │ -44.461 │ -4.45 │ 6 days, 2:03:00 │ 0 0 3 0 │
└───────────────┴────────┴──────────────┴─────────────┴──────────────┴──────────────────┴────────────────────────┘
ENTER TAG STATS
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Enter Tag ┃ Entries ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ OTHER │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │
│ TOTAL │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │
└───────────┴─────────┴──────────────┴─────────────┴──────────────┴──────────────┴────────────────────────┘
EXIT REASON STATS
┏━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Exit Reason ┃ Exits ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ roi │ 67 │ 1.06 │ 245.117 │ 24.51 │ 15:49:00 │ 67 0 0 100 │
│ exit_signal │ 4 │ -2.23 │ -31.226 │ -3.12 │ 1 day, 8:38:00 │ 0 0 4 0 │
│ force_exit │ 3 │ -4.56 │ -44.461 │ -4.45 │ 6 days, 2:03:00 │ 0 0 3 0 │
│ stop_loss │ 3 │ -10.14 │ -112.273 │ -11.23 │ 1 day, 3:05:00 │ 0 0 3 0 │
│ TOTAL │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │
└─────────────┴───────┴──────────────┴─────────────┴──────────────┴─────────────────┴────────────────────────┘
MIXED TAG STATS
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Enter Tag ┃ Exit Reason ┃ Trades ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ │ roi │ 67 │ 1.06 │ 245.117 │ 24.51 │ 15:49:00 │ 67 0 0 100 │
│ │ exit_signal │ 4 │ -2.23 │ -31.226 │ -3.12 │ 1 day, 8:38:00 │ 0 0 4 0 │
│ │ force_exit │ 3 │ -4.56 │ -44.461 │ -4.45 │ 6 days, 2:03:00 │ 0 0 3 0 │
│ │ stop_loss │ 3 │ -10.14 │ -112.273 │ -11.23 │ 1 day, 3:05:00 │ 0 0 3 0 │
│ TOTAL │ │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │
└───────────┴─────────────┴────────┴──────────────┴─────────────┴──────────────┴─────────────────┴────────────────────────┘
SUMMARY METRICS
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric ┃ Value
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Backtesting from │ 2025-07-01 00:00:00
│ Backtesting to │ 2025-08-01 00:00:00
│ Trading Mode │ Isolated Futures
│ Max open trades │ 3
│ Total/Daily Avg Trades │ 77 / 2.48
│ Starting balance │ 1000 USDT
│ Final balance │ 1057.157 USDT
│ Absolute profit │ 57.157 USDT
│ Total profit % │ 5.72%
│ CAGR % │ 92.41%
│ Sharpe (closed trades)3.89
│ Sortino (closed trades)2.57
│ Calmar (closed trades) │ 43.03
│ SQN │ 0.71
│ Profit factor │ 1.30
│ Expectancy (Ratio) │ 0.74 (0.04)
│ Avg. daily profit │ 1.844 USDT
│ Avg. stake amount │ 345.478 USDT
Market change │ 30.51%
Total trade volume53390.788 USDT
│ Long / Short trades │ 67 / 10
│ Long / Short profit % │ 9.19% / -3.48%
Long / Short profit USDT91.940 / -34.783
Best Pair │ LTC/USDT:USDT 5.69%
Worst Pair ADA/USDT:USDT -5.21%
Best trade │ XRP/USDT:USDT 2.00%
Worst trade │ ADA/USDT:USDT -10.17%
Best day │ 27.031 USDT
Worst day │ -47.826 USDT
Days win/draw/lose │ 20 / 6 / 5
│ Min/Max/Avg. Duration Winners │ 0d 00:35 / 5d 18:15 / 0d 15:49
│ Min/Max/Avg. Duration Losers │ 0d 10:40 / 17d 08:00 / 2d 17:00
Max Consecutive Wins / Loss │ 36 / 3
Rejected Entry signals │ 258
Entry/Exit Timeouts 0 / 0
Min/Max balance (closed trades) │ 1003.205 USDT / 1151.425 USDT │
│ Max % of account underwater │ 8.19%
│ Absolute drawdown │ 94.268 USDT (8.19%)
│ Drawdown duration │ 9 days 08:50:00
│ Profit at drawdown start │ 151.425 USDT
│ Profit at drawdown end │ 57.157 USDT
│ Drawdown start │ 2025-07-22 15:10:00
│ Drawdown end │ 2025-08-01 00:00:00
│ Wallet based Metrics │ │
│ Min/Max balance (wallet balance) │ 1000 USDT / 1151.425 USDT │
│ Min/Max balance dates (wallet balance) │ 2025-07-01 00:05:00 / 2025-07-22 15:15:00 │
│ Max % of account underwater (balance) │ 5.01% │
│ Absolute drawdown (wallet balance) │ 54.76 USDT (4.76%) │
│ Drawdown duration │ 7 days 20:35:00 │
│ Profit at drawdown start │ 151.425 USDT │
│ Profit at drawdown end │ 96.664 USDT │
│ Drawdown start │ 2025-07-22 15:15:00 │
│ Drawdown end │ 2025-07-30 11:50:00 │
│ Sharpe (daily wallet balance) │ 4.42 │
│ Sortino (daily wallet balance) │ 4.35 │
│ Calmar (daily wallet balance) │ 136.07 │
└────────────────────────────────────────┴───────────────────────────────────────────┘
BACKTESTING REPORT
┏━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Pair ┃ Trades ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ LTC/USDT:USDT │ 16 │ 1.0 │ 56.176 │ 5.62 │ 16:16:00 │ 16 0 0 100 │
│ ETC/USDT:USDT │ 12 │ 0.72 30.936 │ 3.09 │ 9:55:00 │ 11 0 1 91.7 │
│ ETH/USDT:USDT │ 8 │ 0.66 17.864 │ 1.79 │ 1 day, 13:55:00 │ 7 0 1 87.5 │
│ XLM/USDT:USDT │ 10 │ 0.31 11.054 │ 1.11 │ 12:08:00 │ 9 0 1 90.0 │
│ BTC/USDT:USDT │ 8 │ 0.21 7.289 │ 0.73 │ 3 days, 1:24:00 │ 6 0 2 75.0 │
│ XRP/USDT:USDT │ 9 │ -0.14 -7.261 │ -0.73 │ 21:18:00 │ 8 0 1 88.9 │
│ DOT/USDT:USDT │ 6 │ -0.4 │ -9.187 │ -0.92 │ 5:35:00 │ 4 0 2 66.7 │
│ ADA/USDT:USDT │ 8 │ -1.76 -52.098 │ -5.21 │ 11:38:00 │ 6 0 2 75.0 │
│ TOTAL │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │
└───────────────┴────────┴──────────────┴─────────────────┴──────────────┴─────────────────┴────────────────────────┘
LEFT OPEN TRADES REPORT
┏━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Pair ┃ Trades ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ BTC/USDT:USDT │ 1 │ -4.14 │ -9.930 │ -0.99 │ 17 days, 8:00:00 │ 0 0 1 0 │
│ ETC/USDT:USDT │ 1 │ -4.24 │ -15.365 │ -1.54 │ 10:40:00 │ 0 0 1 0 │
│ DOT/USDT:USDT │ 1 │ -5.29 │ -19.125 │ -1.91 │ 11:30:00 │ 0 0 1 0 │
│ TOTAL │ 3 │ -4.56 │ -44.420 │ -4.44 │ 6 days, 2:03:00 │ 0 0 3 0 │
└───────────────┴────────┴──────────────┴─────────────────┴──────────────┴──────────────────┴────────────────────────┘
ENTER TAG STATS
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Enter Tag ┃ Entries ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ OTHER │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │
│ TOTAL │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │
└───────────┴─────────┴──────────────┴─────────────────┴──────────────┴──────────────┴────────────────────────┘
EXIT REASON STATS
┏━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Exit Reason ┃ Exits ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ roi │ 67 │ 1.05 242.179 │ 24.22 │ 15:49:00 │ 67 0 0 100 │
│ exit_signal │ 4 │ -2.23 │ -31.217 │ -3.12 │ 1 day, 8:38:00 │ 0 0 4 0 │
│ force_exit │ 3 │ -4.56 │ -44.420 │ -4.44 │ 6 days, 2:03:00 │ 0 0 3 0 │
│ stop_loss │ 3 │ -10.14 │ -111.768 │ -11.18 │ 1 day, 3:05:00 │ 0 0 3 0 │
│ TOTAL │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │
└─────────────┴───────┴──────────────┴─────────────────┴──────────────┴─────────────────┴────────────────────────┘
MIXED TAG STATS
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Enter Tag ┃ Exit Reason ┃ Trades ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ │ roi │ 67 │ 1.05 242.179 │ 24.22 │ 15:49:00 │ 67 0 0 100 │
│ │ exit_signal │ 4 │ -2.23 │ -31.217 │ -3.12 │ 1 day, 8:38:00 │ 0 0 4 0 │
│ │ force_exit │ 3 │ -4.56 │ -44.420 │ -4.44 │ 6 days, 2:03:00 │ 0 0 3 0 │
│ │ stop_loss │ 3 │ -10.14 │ -111.768 │ -11.18 │ 1 day, 3:05:00 │ 0 0 3 0 │
│ TOTAL │ │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │
└───────────┴─────────────┴────────┴──────────────┴─────────────────┴──────────────┴─────────────────┴────────────────────────┘
SUMMARY METRICS
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric ┃ Value
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Backtesting from │ 2025-07-01 00:00:00 │
│ Backtesting to │ 2025-08-01 00:00:00 │
│ Trading Mode │ Isolated Futures │
│ Max open trades │ 3
│ Total/Daily Avg Trades │ 77 / 2.48 │
│ Starting balance │ 1000 USDT │
│ Final balance │ 1054.774 USDT
│ Absolute profit │ 54.774 USDT
│ Total profit % │ 5.48%
│ CAGR % │ 87.36%
│ Sortino 2.48
│ Sharpe 3.75
│ Calmar │ 40.99
│ SQN │ 0.69
│ Profit factor │ 1.29
│ Expectancy (Ratio) │ 0.71 (0.04) │
│ Avg. daily profit │ 1.767 USDT │
│ Avg. stake amount │ 345.016 USDT │
Total trade volume │ 53316.954 USDT
Long / Short trades │ 67 / 10
│ Long / Short profit % │ 8.94% / -3.47%
│ Long / Short profit USDT89.425 / -34.651
Best PairLTC/USDT:USDT 5.62%
Worst Pair │ ADA/USDT:USDT -5.21%
Best tradeETC/USDT:USDT 2.00%
Worst trade │ ADA/USDT:USDT -10.17%
Best day │ 26.91 USDT
Worst day │ -47.741 USDT
Days win/draw/lose │ 20 / 6 / 5
Min/Max/Avg. Duration Winners │ 0d 00:35 / 5d 18:15 / 0d 15:49
│ Min/Max/Avg. Duration Losers │ 0d 10:40 / 17d 08:00 / 2d 17:00
│ Max Consecutive Wins / Loss │ 36 / 3
Rejected Entry signals │ 258
Entry/Exit Timeouts │ 0 / 0
│ │
Min balance1003.168 USDT
│ Max balance 1149.421 USDT
│ Max % of account underwater │ 8.23%
│ Absolute drawdown │ 94.647 USDT (8.23%)
│ Drawdown duration │ 9 days 08:50:00 │
│ Profit at drawdown start │ 149.421 USDT │
│ Profit at drawdown end │ 54.774 USDT
│ Drawdown start │ 2025-07-22 15:10:00 │
│ Drawdown end │ 2025-08-01 00:00:00 │
Market change │ 30.51%
└───────────────────────────────┴─────────────────────────────────┘
Backtested 2025-07-01 00:00:00 -> 2025-08-01 00:00:00 | Max open trades : 3
STRATEGY SUMMARY
┏━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Strategy ┃ Trades ┃ Avg Profit % ┃ Tot Profit ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃ Drawdown ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ SampleStrategy │ 77 │ 0.2357.157 │ 5.72 │ 22:12:00 │ 67 0 10 87.0 │ 94.268 8.19% │
└────────────────┴────────┴──────────────┴─────────────┴──────────────┴──────────────┴────────────────────────┴────────────────┘
STRATEGY SUMMARY
┏━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━
┃ Strategy ┃ Trades ┃ Avg Profit % ┃ Tot Profit USDT ┃ Tot Profit % ┃ Avg Duration ┃ Win Draw Loss Win% ┃ Drawdown ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━
│ SampleStrategy │ 77 │ 0.22 54.774 │ 5.48 │ 22:12:00 │ 67 0 10 87.0 │ 94.647 USDT 8.23% │
└────────────────┴────────┴──────────────┴─────────────────┴──────────────┴──────────────┴────────────────────────┴────────────────────
```
### Backtesting report table
@@ -343,72 +329,54 @@ The last element of the backtest report is the summary metrics table.
It contains key metrics about the performance of your strategy on backtesting data.
```
SUMMARY METRICS
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric ┃ Value ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Backtesting from │ 2025-07-01 00:00:00
Backtesting to │ 2025-08-01 00:00:00
Trading Mode │ Isolated Futures
Max open trades 3
Total/Daily Avg Trades │ 77 / 2.48
Starting balance │ 1000 USDT
Final balance │ 1057.157 USDT
Absolute profit 57.157 USDT
Total profit % 5.72%
CAGR % │ 92.41%
│ Sharpe (closed trades) │ 3.89
Sortino (closed trades) │ 2.57
Calmar (closed trades)43.03
SQN 0.71
Profit factor │ 1.30
Expectancy (Ratio) │ 0.74 (0.04)
│ Avg. daily profit 1.844 USDT
Avg. stake amount │ 345.478 USDT
Market change 30.51%
Total trade volume53390.788 USDT
Long / Short trades67 / 10
Long / Short profit %9.19% / -3.48%
Long / Short profit USDT │ 91.940 / -34.783
Best Pair │ LTC/USDT:USDT 5.69%
Worst Pair │ ADA/USDT:USDT -5.21%
Best trade │ XRP/USDT:USDT 2.00%
Worst trade │ ADA/USDT:USDT -10.17%
Best day │ 27.031 USDT
Worst day │ -47.826 USDT
Days win/draw/lose20 / 6 / 5
│ Min/Max/Avg. Duration Winners │ 0d 00:35 / 5d 18:15 / 0d 15:49
│ Min/Max/Avg. Duration Losers │ 0d 10:40 / 17d 08:00 / 2d 17:00
│ Max Consecutive Wins / Loss │ 36 / 3
Rejected Entry signals │ 258
Entry/Exit Timeouts │ 0 / 0
Min/Max balance (closed trades) │ 1003.205 USDT / 1151.425 USDT
Max % of account underwater │ 8.19%
Absolute drawdown │ 94.268 USDT (8.19%)
Drawdown duration │ 9 days 08:50:00
│ Profit at drawdown start │ 151.425 USDT │
│ Profit at drawdown end │ 57.157 USDT │
│ Drawdown start │ 2025-07-22 15:10:00 │
│ Drawdown end │ 2025-08-01 00:00:00 │
│ │ │
│ Wallet based Metrics │ │
│ Min/Max balance (wallet balance) │ 1000 USDT / 1151.425 USDT │
│ Min/Max balance dates (wallet balance) │ 2025-07-01 00:05:00 / 2025-07-22 15:15:00 │
│ Max % of account underwater (balance) │ 5.01% │
│ Absolute drawdown (wallet balance) │ 54.76 USDT (4.76%) │
│ Drawdown duration │ 7 days 20:35:00 │
│ Profit at drawdown start │ 151.425 USDT │
│ Profit at drawdown end │ 96.664 USDT │
│ Drawdown start │ 2025-07-22 15:15:00 │
│ Drawdown end │ 2025-07-30 11:50:00 │
│ Sharpe (daily wallet balance) │ 4.42 │
│ Sortino (daily wallet balance) │ 4.35 │
│ Calmar (daily wallet balance) │ 136.07 │
└────────────────────────────────────────┴───────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric ┃ Value ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Backtesting from │ 2025-07-01 00:00:00 │
│ Backtesting to │ 2025-08-01 00:00:00 │
Trading Mode │ Isolated Futures
Max open trades │ 3
│ │
Total/Daily Avg Trades │ 72 / 2.32
Starting balance │ 1000 USDT
Final balance │ 1106.734 USDT
Absolute profit │ 106.734 USDT
Total profit %10.67%
CAGR % │ 230.04%
Sortino │ 4.99
│ Sharpe │ 8.00
Calmar │ 77.76
SQN 1.52
Profit factor1.79
Expectancy (Ratio) │ 1.48 (0.07)
Avg. daily profit │ 3.443 USDT
│ Avg. stake amount363.133 USDT
Total trade volume │ 52466.174 USDT
│ │
Best PairLTC/USDT:USDT 4.48%
Worst PairADA/USDT:USDT -1.78%
Best trade │ ETC/USDT:USDT 2.00%
Worst trade ADA/USDT:USDT -10.17%
Best day │ 23.535 USDT
Worst day-49.813 USDT
Days win/draw/lose │ 21 / 6 / 4
Min/Max/Avg. Duration Winners │ 0d 00:35 / 5d 18:15 / 0d 15:30
Min/Max/Avg. Duration Losers │ 0d 12:00 / 17d 08:00 / 3d 23:28
Max Consecutive Wins / Loss │ 58 / 4
Rejected Entry signals │ 254
Entry/Exit Timeouts │ 0 / 0
│ │
│ Min balance │ 1003.168 USDT
│ Max balance │ 1209 USDT
│ Max % of account underwater │ 8.46%
Absolute drawdown │ 102.266 USDT (8.46%)
Drawdown duration │ 9 days 08:50:00
Profit at drawdown start │ 209 USDT
Profit at drawdown end │ 106.734 USDT
Drawdown start │ 2025-07-22 15:10:00
Drawdown end │ 2025-08-01 00:00:00
Market change │ 30.51%
└───────────────────────────────┴─────────────────────────────────┘
```
- `Backtesting from` / `Backtesting to`: Backtesting range (usually defined with the `--timerange` option).
@@ -420,15 +388,14 @@ It contains key metrics about the performance of your strategy on backtesting da
- `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`.
- `CAGR %`: Compound annual growth rate.
- `Sharpe (closed trades)`: Annualized Sharpe ratio including only closed trades (ignoring open trades with profits or losses).
- `Sortino (closed trades)`: Annualized Sortino ratio including only closed trades (ignoring open trades with profits or losses).
- `Calmar (closed trades)`: Annualized Calmar ratio including only closed trades (ignoring open trades with profits or losses).
- `Sortino`: Annualized Sortino ratio.
- `Sharpe`: Annualized Sharpe ratio.
- `Calmar`: Annualized Calmar ratio.
- `SQN`: System Quality Number (SQN) - by Van Tharp.
- `Profit factor`: Sum of the profits of all winning trades divided by the sum of the losses of all losing trades.
- `Expectancy (Ratio)`: Expectancy ratio, which is the average profit or loss per trade. A negative expectancy ratio means that your strategy is not profitable.
- `Avg. daily profit`: Average profit per day, calculated as `(Total Profit / Backtest Days)`.
- `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount.
- `Market change`: Change of the market during the backtest period. Calculated as the average of all pairs' changes from the first to the last candle using the "close" column.
- `Total trade volume`: Volume generated on the exchange to reach the above profit.
- `Long / Short trades`: Split long/short trade counts (only shown when short trades were made).
- `Long / Short profit %`: Profit percentage for long and short trades (only shown when short trades were made).
@@ -442,21 +409,13 @@ It contains key metrics about the performance of your strategy on backtesting da
- `Max Consecutive Wins / Loss`: Maximum consecutive wins/losses in a row.
- `Rejected Entry signals`: Trade entry signals that could not be acted upon due to `max_open_trades` being reached.
- `Entry/Exit Timeouts`: Entry/exit orders which did not fill (only applicable if custom pricing is used).
- `Min/Max balance (closed trades)`: Lowest and Highest Wallet balance during the backtest period based on closed trades trades.
- `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. Calculated as the maximum of `(Max Balance - Current Balance) / (Max Balance)`.
- `Absolute drawdown`: Maximum absolute drawdown experienced, including percentage relative to the account calculated as `(Absolute Drawdown) / (DrawdownHigh + startingBalance)`..
- `Absolute drawdown (wallet balance)`: Maximum absolute drawdown experienced based on the unrealized balance, including percentage relative to the account calculated as `(Absolute Drawdown) / (DrawdownHigh + startingBalance)`.
- `Drawdown duration`: Duration of the largest drawdown period.
- `Profit at drawdown start` / `Profit at drawdown end`: Profit at the beginning and end of the largest drawdown period.
- `Drawdown start` / `Drawdown end`: Start and end datetime for the largest drawdown (can also be visualized via the `plot-dataframe` sub-command).
- `Min/Max balance (wallet balance)`: Lowest and Highest Wallet balance during the backtest period - including capital tied in open trades.
- `Min/Max balance dates (wallet balance)`: Dates when the minimum and maximum unrealized balance occurred.
- `Sharpe (wallet balance)` Annualized Sharpe ratio calculation including unrealized profits.
- `Sortino (wallet balance)` Annualized Sortino ratio calculation including unrealized profits.
- `Calmar (wallet balance)` Annualized Calmar ratio calculation including unrealized profits.
!!! Tip "Wallet based Metrics"
The metrics under the "Wallet based Metrics" section are calculated based on the unrealized balance, which includes the capital tied in open trades. This provides a more comprehensive view of the strategy's performance, as it accounts for both realized and unrealized profits and losses.
- `Market change`: Change of the market during the backtest period. Calculated as the average of all pairs' changes from the first to the last candle using the "close" column.
### Daily / Weekly / Monthly / Yearly breakdown
+9 -6
View File
@@ -64,15 +64,18 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line.
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
--export {none,trades,signals}
Export backtest results (default: trades).
--backtest-filename, --export-filename PATH
DEPRECATED: This option is deprecated for backtesting
and will be removed in a future release. Using a
custom filename for backtest results is no longer
supported. Use `--backtest-directory` to specify the
directory.
Use this filename for backtest results.Example:
`--backtest-
filename=backtest_results_2020-09-27_16-20-48.json`.
Assumes either `user_data/backtest_results/` or
`--export-directory` as base directory.
--backtest-directory, --export-directory PATH
Directory to use for backtest results. Example:
`--export-directory=user_data/backtest_results/`.
+4 -1
View File
@@ -62,7 +62,10 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line.
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
--export {none,trades,signals}
Export backtest results (default: trades).
--backtest-filename, --export-filename PATH
+4 -1
View File
@@ -10,7 +10,10 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line.
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
--strategy-path PATH Specify additional strategy lookup path.
--recursive-strategy-search
Recursively search for a strategy in the strategies
+5 -5
View File
@@ -191,7 +191,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| | **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. [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
| | **Pricing**
| `entry_pricing.price_side` | Select the side of the spread the bot should look at to get the entry rate. [More information below](#entry-price).<br> *Defaults to `"same"`.* <br> **Datatype:** String (either `ask`, `bid`, `same` or `other`).
@@ -229,7 +229,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `exchange.enable_ws` | Enable the usage of Websockets for the exchange. <br>[More information](#consuming-exchange-websockets).<br>*Defaults to `true`.* <br> **Datatype:** Boolean
| `exchange.markets_refresh_interval` | The interval in minutes in which markets are reloaded. <br>*Defaults to `60` minutes.* <br> **Datatype:** Positive Integer
| `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.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.only_from_ccxt` | Prevent data-download from data.binance.vision. Leaving this as false can greatly speed up downloads, but may be problematic if the site is not available.<br>*Defaults to `false`*<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
@@ -240,7 +240,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `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.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.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**
@@ -280,8 +280,8 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `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
| `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data. <br> *Defaults to `feather`*. <br> **Datatype:** String
| `dataformat_trades` | Data format to use to store historical trades data. <br> *Defaults to `feather`*. <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 backtesting/hyperopt and in FreqAI). <br> Default: `False`. <br> **Datatype:** Boolean.
| `log_config` | Dictionary containing the log config for python logging. [more info](advanced-setup.md#advanced-logging) <br> Default: `FtRichHandler` <br> **Datatype:** dict.
| `reduce_df_footprint` | Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage (and decreasing train/inference timing backtesting/hyperopt and in FreqAI). <br> **Datatype:** Boolean. <br> Default: `False`.
| `log_config` | Dictionary containing the log config for python logging. [more info](advanced-setup.md#advanced-logging) <br> **Datatype:** dict. <br> Default: `FtRichHandler`
### Parameters in the strategy
-2
View File
@@ -269,8 +269,6 @@ If `--convert` is also provided, the resample step will happen automatically and
!!! Note "Kraken user"
Kraken users should read [this](exchanges.md#historic-kraken-data) before starting to download data.
Kraken Futures uses standard OHLCV downloads and does not require `--dl-trades`.
Example call:
```bash
+24 -85
View File
@@ -217,32 +217,6 @@ freqtrade download-data --exchange kraken --dl-trades -p BTC/EUR BCH/EUR
Please pay attention that rateLimit configuration entry holds delay in milliseconds between requests, NOT requests/sec rate.
So, in order to mitigate Kraken API "Rate limit exceeded" exception, this configuration should be increased, NOT decreased.
## Kraken Futures
Kraken Futures uses the exchange id `krakenfutures` and supports isolated futures mode.
```jsonc
"exchange": {
"name": "krakenfutures",
"key": "your_exchange_key",
"secret": "your_exchange_secret"
},
"trading_mode": "futures",
"margin_mode": "isolated",
"stake_currency": "USD"
```
!!! Tip "Stoploss on Exchange"
Kraken Futures supports `stoploss_on_exchange` with both `limit` and `market` stop orders.
Use `order_types.stoploss_price_type` to select the trigger price source (`mark`, `last`, or `index`).
!!! Note "Collateral"
Kraken Futures is USD-settled. Use USD as your stake currency.
!!! Note "Flex (Multi-collateral) Accounts"
Kraken Futures flex accounts allow collateral in multiple currencies, while trading remains USD-settled.
Freqtrade derives the `USD` balance from Kraken margin fields, so keep `stake_currency` set to `USD`.
## 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:
@@ -265,7 +239,7 @@ Kucoin supports [time_in_force](configuration.md#understand-order_time_in_force)
### 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, 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.
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.
## HTX
@@ -345,14 +319,6 @@ API Keys for live futures trading must have the following permissions:
We do strongly recommend to limit all API keys to the IP you're going to use it from.
### Bybit Demo Mode
Bybit has a [demo mode](https://learn.bybit.com/en/bybit-guide/how-to-use-bybit-demo-trading) - which can be activated by setting `exchange.demo_trading` to `true` in the configuration.
Bybit uses live markets to simulate your trades (without market impact) - making it work very similar to freqtrade's dry-run mode.
You'll need to use separate API keys for demo trading, which you can create on bybit's demo page.
Demo mode is incompatible with dry-run.
## Bitmart
@@ -403,11 +369,6 @@ On startup, freqtrade will set the position mode to "One-way Mode" for the whole
!!! Tip "Stoploss on Exchange"
Hyperliquid supports `stoploss_on_exchange` and uses `stop-loss-limit` orders. It provides great advantages, so we recommend to benefit from it.
!!! Warning "Unified accounts"
Hyperliquid unified accounts are supported - though this relies freqtrade's assumption of "owning" the account, and being the only one trading on it (in this case, extended to both spot and futures).
We hence recommend the usage of subaccounts where possible, and to avoid manual trading on the same account while the bot is running.
Freqtrade will attempt to detect the account type on startup - changing the account type mid-trading is not supported and may lead to exceptions and errors.
Hyperliquid is a Decentralized Exchange (DEX). Decentralized exchanges work a bit different compared to normal exchanges. Instead of authenticating private API calls using an API key, private API calls need to be signed with the private key of your wallet (We recommend using an api Wallet for this, generated either on Hyperliquid or in your wallet of choice).
This needs to be configured like this:
@@ -438,51 +399,31 @@ Hyperliquid handles deposits and withdrawals on the Arbitrum One chain, a Layer
* Create a different software wallet, only transfer the funds you want to trade with to that wallet, and use that wallet to trade on Hyperliquid.
* If you have funds you don't want to use for trading (after making a profit for example), transfer them back to your hardware wallet.
### Hyperliquid Vault / Subaccount
!!! Warning "Vaults and Subaccounts"
Hyperliquid allows you to create either a vault or a subaccount.
To use these with Freqtrade, you will need to use the following configuration pattern:
``` json
"exchange": {
"name": "hyperliquid",
"walletAddress": "your_master_wallet_address", // Your master wallet address (not the API wallet address and not the vault/subaccount address).
"privateKey": "your_api_private_key", // API wallet private key (see https://app.hyperliquid.xyz/API). You'll only need the private key.
"ccxt_config": {
"options": {
"vaultAddress": "your_vault_address", // Optional, only if you want to use a vault ...
"subAccountAddress": "your_subaccount_address" // OR optional, only if you want to use a subaccount
}
},
// ...
}
```
Your balance and trades will now be used from your vault / subaccount - and no longer from your main account.
!!! Note
You can only use either a vault or a subaccount - not both at the same time.
### Hyperliquid Subaccount
Hyperliquid allows you to create subaccounts with sufficient previous trading volume.
To use subaccounts with Freqtrade, you will need to use the following configuration pattern:
``` json
"exchange": {
"name": "hyperliquid",
"walletAddress": "your_master_wallet_address", // Your master wallet address (not the API wallet or vault address - but not subaccount address).
"privateKey": "your_api_private_key", // API wallet private key (see https://app.hyperliquid.xyz/API). You'll only need the private key.
"ccxt_config": {
"options": {
"subAccountAddress": "your_subaccount_address" // Required if you want to use a subaccount.
}
},
// ...
}
```
Your balance and trades will now be used from your subaccount - and no longer from your main account.
### Hyperliquid Vault
Hyperliquid allows you to create vaults. To use vaults with Freqtrade, you will need to use the following configuration pattern:
``` json
"exchange": {
"name": "hyperliquid",
"walletAddress": "your_vault_address", // Your vault wallet address (Must also be added below in the ccxt_config.options.vaultAddress field)
"privateKey": "your_api_private_key", // API wallet private key (see https://app.hyperliquid.xyz/API). You'll only need the private key.
"ccxt_config": {
"options": {
"vaultAddress": "your_vault_address", // Optional, only if you want to use a vault ... (vault address must also be added to walletAdress)
}
},
// ...
}
```
Your balance and trades will now be used from your vault - and no longer from your main account.
### Historic Hyperliquid data
The Hyperliquid API does not provide historic data beyond the single call to fetch current data, so downloading data is not possible, as the downloaded data would not constitute proper historic data.
@@ -517,8 +458,6 @@ Replace `"dex_name_1"` and `"dex_name_2"` with the actual names of the HIP-3 DEX
!!! Note
HIP-3 DEXes share the same wallet and free amount of collateral as your main Hyperliquid account. Trades on different DEXes will affect your overall account balance and margin.
The pair name for HIP-3 pairs will be slightly different than non HIP-3 pairs. Please use `list-pairs` subcommand to get the correct pair naming for all pairs for the specified dexes.
## Bitvavo
If your account is required to use an operatorId, you can set it in the configuration file as follows:
@@ -582,5 +521,5 @@ For example, to test the order type `FOK` with Kraken, and modify candle limit t
!!! Warning
Please make sure to fully understand the impacts of these settings before modifying them.
Using `_ft_has_params` overrides may lead to unexpected behavior, and may even break your bot.
Using `_ft_has_params` overrides may lead to unexpected behavior, and may even break your bot.
We will not be able to provide support for issues caused by custom settings in `_ft_has_params`.
+2 -2
View File
@@ -2,7 +2,7 @@
## Supported Markets
Freqtrade supports spot trading, as well as futures trading for some selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges) for an up-to-date list of supported exchanges.
Freqtrade supports spot trading, as well as futures trading for some selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an up-to-date list of supported exchanges.
### Can my bot open short positions?
@@ -14,7 +14,7 @@ In spot markets, you can in some cases use leveraged spot tokens, which reflect
### Can my bot trade options or futures?
Futures trading is supported for selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges) for an up-to-date list of supported exchanges.
Futures trading is supported for selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an up-to-date list of supported exchanges.
## Beginner Tips & Tricks
-17
View File
@@ -46,23 +46,6 @@ On this page, you can also interact with the bot by starting and stopping it and
![FreqUI - trade view](assets/freqUI-trade-pane-dark.png#only-dark)
![FreqUI - trade view](assets/freqUI-trade-pane-light.png#only-light)
### Dashboard
The dashboard view provides an overview of the bot's performance and status.
If multiple bots are connected, the dashboard will show an overview of all connected bots, allowing you to easily switch between them or show just a subset of available bots.
#### Wallet Balance
New in freqtrade 2026.4: This shows the balance of the bot over time.
Compared to the "cumulative Profit" chart, this chart will show the actual balance of the bot over time, including unrealized profit and losses, as well as deposits and withdrawals.
Historic data has re-populated based on available exchange data - however is assumed to be best-effort and may not be 100% accurate.
More specifically, it won't cover deposits and withdrawals, and will assume a starting balance of current balance - profit/losses.
For clarity - a "Capture start" marker line is shown on the chart, which indicates the point at which the migration to the new wallet balance tracking system happened.
Only beyond this point, the wallet balance is expected to be accurate.
### Plot Configurator
FreqUI Plots can be configured either via a `plot_config` configuration object in the strategy (which can be loaded via "from strategy" button) or via the UI.
+1 -5
View File
@@ -166,7 +166,7 @@ Below are the values you can expect to include/use inside a typical strategy dat
| `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 `%%` (see details below). <br> **Datatype:** Depends on the feature created by the user.
| `df['%%*']` | Any dataframe column prepended with `%%` in `feature_engineering_*()` is treated as a training feature, just the same as the above `%` prepend. However, in this case, the features are returned back to the strategy for FreqUI/plot-dataframe plotting and monitoring in Dry/Live/Backtesting <br> **Datatype:** Depends on the feature created by the user. <br>*Please note* that features created in `feature_engineering_expand()` will have automatic FreqAI naming schemas depending on the expansions that you configured (i.e. `include_timeframes`, `include_corr_pairlist`, `indicators_periods_candles`, `include_shifted_candles`). So if you want to plot `%%-rsi` from `feature_engineering_expand_all()`, the final naming scheme for your plotting config would be: `%%-rsi-period_10_ETH/USDT:USDT_1h` for the `rsi` feature with `period=10`, `timeframe=1h`, and `pair=ETH/USDT:USDT` (the `:USDT` is added if you are using futures pairs). It is useful to simply add `print(dataframe.columns)` in your `populate_indicators()` after `self.freqai.start()` to see the full list of available features that are returned to the strategy for plotting purposes.
| `df['%%*']` | Any dataframe column prepended with `%%` in `feature_engineering_*()` is treated as a training feature, just the same as the above `%` prepend. However, in this case, the features are returned back to the strategy for FreqUI/plot-dataframe plotting and monitoring in Dry/Live/Backtesting <br> **Datatype:** Depends on the feature created by the user. Please note that features created in `feature_engineering_expand()` will have automatic FreqAI naming schemas depending on the expansions that you configured (i.e. `include_timeframes`, `include_corr_pairlist`, `indicators_periods_candles`, `include_shifted_candles`). So if you want to plot `%%-rsi` from `feature_engineering_expand_all()`, the final naming scheme for your plotting config would be: `%%-rsi-period_10_ETH/USDT:USDT_1h` for the `rsi` feature with `period=10`, `timeframe=1h`, and `pair=ETH/USDT:USDT` (the `:USDT` is added if you are using futures pairs). It is useful to simply add `print(dataframe.columns)` in your `populate_indicators()` after `self.freqai.start()` to see the full list of available features that are returned to the strategy for plotting purposes.
## Setting the `startup_candle_count`
@@ -260,10 +260,6 @@ freqtrade trade --config config_examples/config_freqai.example.json --strategy F
PyTorch dropped support for macOS x64 (intel based Apple devices) in version 2.3. Subsequently, freqtrade also dropped support for PyTorch on this platform.
!!! Danger "Security notice"
Loading saved models from disk can cause security issues if using remote model files (files you downloaded from the internet or received from an untrusted source) due to having the necessity to have `weights_only=False`, which can cause security problems.
As long as you only load models that you have trained yourself, there is no risk.
### Structure
#### Model
-1
View File
@@ -106,7 +106,6 @@ Mandatory parameters are marked as **Required** and have to be set in one of the
| `n_epochs` | The `n_epochs` parameter is a crucial setting in the PyTorch training loop that determines the number of times the entire training dataset will be used to update the model's parameters. An epoch represents one full pass through the entire training dataset. Overrides `n_steps`. Either `n_epochs` or `n_steps` must be set. <br><br> **Datatype:** int. optional. <br> Default: `10`.
| `n_steps` | An alternative way of setting `n_epochs` - the number of training iterations to run. Iteration here refer to the number of times we call `optimizer.step()`. Ignored if `n_epochs` is set. A simplified version of the function: <br><br> n_epochs = n_steps / (n_obs / batch_size) <br><br> The motivation here is that `n_steps` is easier to optimize and keep stable across different n_obs - the number of data points. <br> <br> **Datatype:** int. optional. <br> Default: `None`.
| `batch_size` | The size of the batches to use during training. <br><br> **Datatype:** int. <br> Default: `64`.
| `early_stopping_patience` | Number of epochs with no improvement in validation loss before training is stopped early. This helps prevent overfitting by halting training when the model stops improving. Set to `0` to disable early stopping. Requires a test/validation split (`test_size > 0`). <br><br> **Datatype:** int. <br> Default: `0` (disabled).
### Additional parameters
+1 -1
View File
@@ -45,7 +45,7 @@ where `ReinforcementLearner` will use the templated `ReinforcementLearner` from
More details about feature engineering available:
https://www.freqtrade.io/en/stable/freqai-feature-engineering
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"]
-4
View File
@@ -87,10 +87,6 @@ To save the models generated during a particular backtest so that you can start
To ensure that the model can be reused, freqAI will call your strategy with a dataframe of length 1.
If your strategy requires more data than this to generate the same features, you can't reuse backtest predictions for live deployment and need to update your `identifier` for each new backtest.
!!! Danger "Security notice"
Loading saved models from disk can cause security issues if using remote model files (files you downloaded from the internet or received from an untrusted source) due to having the necessity to have `weights_only=False`, which can cause security problems.
As long as you only load models that you have trained yourself, there is no risk.
### 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.
+1 -1
View File
@@ -7,7 +7,7 @@
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/stable/freqai/).
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:
+2 -2
View File
@@ -15,7 +15,7 @@ Assuming your application is deployed as `https://frequi.freqtrade.io/home/` - t
```jsonc
{
//...
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": ["https://frequi.freqtrade.io"],
//...
}
@@ -29,7 +29,7 @@ The correct configuration for this case is `http://localhost:8080` - the main pa
```jsonc
{
//...
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": ["http://localhost:8080"],
//...
}
-1
View File
@@ -15,7 +15,6 @@
| [Hyperliquid](exchanges.md#hyperliquid) | spot | | ❌ (not supported) |
| [Hyperliquid](exchanges.md#hyperliquid) | futures | isolated, cross | limit |
| [Kraken](exchanges.md#kraken) | spot | | market, limit |
| [Kraken](exchanges.md#kraken-futures) | futures | isolated | market, limit |
| [OKX](exchanges.md#okx) | spot | | limit |
| [OKX](exchanges.md#okx) | futures | isolated | limit |
| [Bitvavo](exchanges.md#bitvavo) | spot | | ❌ (not supported) |
+2 -11
View File
@@ -2,11 +2,11 @@
Pairlist Handlers define the list of pairs (pairlist) that the bot should trade. They are configured in the `pairlists` section of the configuration settings.
In your configuration, you can use Static Pairlist (defined by the [`StaticPairList`](#static-pair-list) Pairlist Handler) and Dynamic Pairlist (defined by the [`VolumePairList`](#volume-pair-list), [`CrossMarketPairList`](#crossmarketpairlist), [`MarketCapPairlist`](#marketcappairlist) and [`PercentChangePairList`](#percent-change-pair-list) Pairlist Handlers).
In your configuration, you can use Static Pairlist (defined by the [`StaticPairList`](#static-pair-list) Pairlist Handler) and Dynamic Pairlist (defined by the [`VolumePairList`](#volume-pair-list) and [`PercentChangePairList`](#percent-change-pair-list) Pairlist Handlers).
Additionally, [`AgeFilter`](#agefilter), [`DelistFilter`](#delistfilter), [`PrecisionFilter`](#precisionfilter), [`PriceFilter`](#pricefilter), [`ShuffleFilter`](#shufflefilter), [`SpreadFilter`](#spreadfilter) and [`VolatilityFilter`](#volatilityfilter) act as Pairlist Filters, removing certain pairs and/or moving their positions in the pairlist.
If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either `StaticPairList`, `VolumePairList`, `ProducerPairList`, `RemotePairList`, `MarketCapPairList`, `PercentChangePairList` or `CrossMarketPairList` as the starting Pairlist Handler.
If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either `StaticPairList`, `VolumePairList`, `ProducerPairList`, `RemotePairList`, `MarketCapPairList` or `PercentChangePairList` as the starting Pairlist Handler.
Inactive markets are always removed from the resulting pairlist. Explicitly blacklisted pairs (those in the `pair_blacklist` configuration setting) are also always removed from the resulting pairlist.
@@ -26,7 +26,6 @@ You may also use something like `.*DOWN/BTC` or `.*UP/BTC` to exclude leveraged
* [`ProducerPairList`](#producerpairlist)
* [`RemotePairList`](#remotepairlist)
* [`MarketCapPairList`](#marketcappairlist)
* [`CrossMarketPairList`](#crossmarketpairlist)
* [`AgeFilter`](#agefilter)
* [`DelistFilter`](#delistfilter)
* [`FullTradesFilter`](#fulltradesfilter)
@@ -304,8 +303,6 @@ The optional `mode` option specifies if the pairlist should be used as a `blackl
The optional `processing_mode` option in the RemotePairList configuration determines how the retrieved pairlist is processed. It can have two values: "filter" or "append". The default value is "filter".
The optional `number_assets` option in the RemotePairList configuration determines how many pairs will be returned if used in whitelist `mode`. By default, all pairs will be returned. In blacklist `mode`, this option will be ignored.
In "filter" mode, the retrieved pairlist is used as a filter. Only the pairs present in both the original pairlist and the retrieved pairlist are included in the final pairlist. Other pairs are filtered out.
In "append" mode, the retrieved pairlist is added to the original pairlist. All pairs from both lists are included in the final pairlist without any filtering.
@@ -405,12 +402,6 @@ Coins like 1000PEPE/USDT or KPEPE/USDT:USDT are detected on a best effort basis,
!!! Danger "Duplicate symbols in coingecko"
Coingecko often has duplicate symbols, where the same symbol is used for different coins. Freqtrade will use the symbol as is and try to search for it on the exchange. If the symbol exists - it will be used. Freqtrade will however not check if the _intended_ symbol is the one coingecko meant. This can sometimes lead to unexpected results, especially on low volume coins or with meme coin categories.
#### CrossMarketPairList
Generate or filter pairs based of their availability on the opposite market.
The `pairs_exist_on` setting defines whether the pairs should exists on both spot and futures market (`both_markets`) or only exist on the specified trading mode (`current_market_only`). By default, the plugin will be in `both_markets` setting, which means whitelisted pairs have to exists on both spot and futures markets.
#### 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).
+10 -22
View File
@@ -20,15 +20,15 @@ All protection end times are rounded up to the next candle to avoid sudden, unex
### Common settings to all Protections
| Parameter | Description |
| --------- | ---------- |
| `method` | Protection name to use. <br> **Datatype:** String, selected from [available Protections](#available-protections) |
| `stop_duration_candles` | For how many candles should the lock be set? <br> **Datatype:** Positive integer (in candles) |
| `stop_duration` | how many minutes should protections be locked. <br>Cannot be used together with `stop_duration_candles`. <br> **Datatype:** Float (in minutes) |
| `lookback_period_candles` | Only trades that completed within the last `lookback_period_candles` candles will be considered. This setting may be ignored by some Protections. <br> **Datatype:** Positive integer (in candles). |
| `lookback_period` | Only trades that completed after `current_time - lookback_period` will be considered. <br>Cannot be used together with `lookback_period_candles`. <br>This setting may be ignored by some Protections. <br> **Datatype:** Float (in minutes) |
| `trade_limit` | Number of trades required at minimum (not used by all Protections). <br> **Datatype:** Positive integer |
| `unlock_at` | Time when trading will be unlocked regularly (not used by all Protections). <br> **Datatype:** string <br>**Input Format:** "HH:MM" (24-hours) |
| Parameter| Description |
|------------|-------------|
| `method` | Protection name to use. <br> **Datatype:** String, selected from [available Protections](#available-protections)
| `stop_duration_candles` | For how many candles should the lock be set? <br> **Datatype:** Positive integer (in candles)
| `stop_duration` | how many minutes should protections be locked. <br>Cannot be used together with `stop_duration_candles`. <br> **Datatype:** Float (in minutes)
| `lookback_period_candles` | Only trades that completed within the last `lookback_period_candles` candles will be considered. This setting may be ignored by some Protections. <br> **Datatype:** Positive integer (in candles).
| `lookback_period` | Only trades that completed after `current_time - lookback_period` will be considered. <br>Cannot be used together with `lookback_period_candles`. <br>This setting may be ignored by some Protections. <br> **Datatype:** Float (in minutes)
| `trade_limit` | Number of trades required at minimum (not used by all Protections). <br> **Datatype:** Positive integer
| `unlock_at` | Time when trading will be unlocked regularly (not used by all Protections). <br> **Datatype:** string <br>**Input Format:** "HH:MM" (24-hours)
!!! Note "Durations"
Durations (`stop_duration*` and `lookback_period*` can be defined in either minutes or candles).
@@ -69,17 +69,7 @@ def protections(self):
#### MaxDrawdown
The `MaxDrawdown` protection evaluates trades that closed within the current `lookback_period` (or `lookback_period_candles`).
It supports 2 calculation modes:
- `calculation_mode: "ratios"` (default): Legacy approximation based on cumulative profit ratios.
- `calculation_mode: "equity"`: Standard peak-to-trough drawdown on the account equity curve, using starting balance and cumulative absolute profit.
With `calculation_mode: "ratios"`, drawdown is derived from cumulative trade profit ratios, not from the account equity curve. This is kept for backward compatibility and can differ from account-level drawdown when position sizing changes over time.
For new setups, `calculation_mode: "equity"` is recommended. Prefer `calculation_mode: "ratios"` only when you intentionally rely on legacy behavior, especially with fixed stake amount configurations where ratio-based behavior is easier to reason about.
If the observed drawdown exceeds `max_allowed_drawdown`, trading will stop for `stop_duration` after the last trade - assuming that the bot needs some time to let markets recover.
`MaxDrawdown` uses all trades within `lookback_period` in minutes (or in candles when using `lookback_period_candles`) to determine the maximum drawdown. If the drawdown is below `max_allowed_drawdown`, trading will stop for `stop_duration` in minutes (or in candles when using `stop_duration_candles`) after the last trade - assuming that the bot needs some time to let markets recover.
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.
@@ -89,7 +79,6 @@ def protections(self):
return [
{
"method": "MaxDrawdown",
"calculation_mode": "equity",
"lookback_period_candles": 48,
"trade_limit": 20,
"stop_duration_candles": 12,
@@ -171,7 +160,6 @@ class AwesomeStrategy(IStrategy)
},
{
"method": "MaxDrawdown",
"calculation_mode": "equity",
"lookback_period_candles": 48,
"trade_limit": 20,
"stop_duration_candles": 4,
+1 -4
View File
@@ -2,9 +2,7 @@
[![Freqtrade CI](https://github.com/freqtrade/freqtrade/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/freqtrade/freqtrade/actions/workflows/ci.yml)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04864/status.svg)](https://doi.org/10.21105/joss.04864)
[![codecov](https://codecov.io/gh/freqtrade/freqtrade/branch/develop/graph/badge.svg?token=AD5BG3ATKI)](https://codecov.io/gh/freqtrade/freqtrade)
[![Documentation](https://readthedocs.org/projects/freqtrade/badge/)](https://www.freqtrade.io)
[![Discord Server](https://img.shields.io/badge/Freqtrade_Discord-4E4E4E?logo=discord)](https://discord.gg/p7nuUNVfP7)
[![Coverage Status](https://coveralls.io/repos/github/freqtrade/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
<!-- GitHub action buttons -->
[:octicons-star-16: Star](https://github.com/freqtrade/freqtrade){ .md-button .md-button--sm }
@@ -62,7 +60,6 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual,
- [X] [Gate.io](https://www.gate.io/ref/6266643)
- [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX)
- [X] [OKX](https://okx.com/)
- [X] [Kraken](https://www.kraken.com/features/futures)
Please make sure to read the [exchange specific notes](exchanges.md), as well as the [trading with leverage](leverage.md) documentation before diving in.
+4 -4
View File
@@ -111,10 +111,10 @@ 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:
* `scatter` corresponding a scatter plot.
* `bar` corresponding to a bar plot.
* `scatter` corresponding to `plotly.graph_objects.Scatter` class (default).
* `bar` corresponding to `plotly.graph_objects.Bar` class.
Extra parameters to `plotly.graph_objects.*` constructor can be specified in `plotly` dict - these are only supported when using plotly as plotting library and will be ignored when using freq-ui.
Extra parameters to `plotly.graph_objects.*` constructor can be specified in `plotly` dict.
Sample configuration with inline comments explaining the process:
@@ -163,7 +163,7 @@ def plot_config(self):
```
??? Note "As attribute (former method)"
Assigning `plot_config` is also possible as Attribute (this used to be the default way).
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
+4 -4
View File
@@ -1,7 +1,7 @@
markdown==3.10.2
markdown==3.10
mkdocs==1.6.1
mkdocs-material==9.7.6
mkdocs-material==9.7.1
mdx_truly_sane_lists==1.3
pymdown-extensions==10.21.3
pymdown-extensions==10.20
jinja2==3.1.6
mike==2.2.0
mike==2.1.3
+12 -12
View File
@@ -17,7 +17,7 @@ Sample configuration:
"listen_port": 8080,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "Freqtrader",
"password": "SuperSecret1!",
@@ -56,7 +56,7 @@ secrets.token_hex()
!!! Danger "Password selection"
Please make sure to select a very strong, unique password to protect your bot from unauthorized access.
Also change `jwt_secret_key` to something random (no need to remember this, but it'll be used to encrypt your session, so it better be something unique!). This value should also be 32 characters or longer to be safe.
Also change `jwt_secret_key` to something random (no need to remember this, but it'll be used to encrypt your session, so it better be something unique!).
### Configuration with docker
@@ -202,20 +202,20 @@ All endpoints in the below table need to be prefixed with the base URL of the AP
| `/blacklist` | GET | Show the current blacklist.
| `/blacklist` | POST | Adds the specified pair to the blacklist.<br/>*Params:*<br/>- `blacklist` (`str`)
| `/blacklist` | DELETE | Deletes the specified list of pairs from the blacklist.<br/>*Params:*<br/>- `[pair,pair]` (`list[str]`)
| `/pair_candles` | GET | Returns dataframe for a pair / timeframe combination while the bot is running.
| `/pair_candles` | POST | Returns dataframe for a pair / timeframe combination while the bot is running, filtered by a provided list of columns to return.<br/>*Params:*<br/>- `<column_list>` (`list[str]`)
| `/pair_history` | GET | Returns an analyzed dataframe for a given timerange, analyzed by a given strategy.
| `/pair_history` | POST | Returns an analyzed dataframe for a given timerange, analyzed by a given strategy, filtered by a provided list of columns to return.<br/>*Params:*<br/>- `<column_list>` (`list[str]`)
| `/plot_config` | GET | Get plot config from the strategy (or nothing if not configured).
| `/strategies` | GET | List strategies in strategy directory.
| `/strategy/<strategy>` | GET | Get specific Strategy content by strategy class name.<br/>*Params:*<br/>- `<strategy>` (`str`)
| `/available_pairs` | GET | List available backtest data.
| `/pair_candles` | GET | Returns dataframe for a pair / timeframe combination while the bot is running. **Alpha**
| `/pair_candles` | POST | Returns dataframe for a pair / timeframe combination while the bot is running, filtered by a provided list of columns to return. **Alpha**<br/>*Params:*<br/>- `<column_list>` (`list[str]`)
| `/pair_history` | GET | Returns an analyzed dataframe for a given timerange, analyzed by a given strategy. **Alpha**
| `/pair_history` | POST | Returns an analyzed dataframe for a given timerange, analyzed by a given strategy, filtered by a provided list of columns to return. **Alpha**<br/>*Params:*<br/>- `<column_list>` (`list[str]`)
| `/plot_config` | GET | Get plot config from the strategy (or nothing if not configured). **Alpha**
| `/strategies` | GET | List strategies in strategy directory. **Alpha**
| `/strategy/<strategy>` | GET | Get specific Strategy content by strategy class name. **Alpha**<br/>*Params:*<br/>- `<strategy>` (`str`)
| `/available_pairs` | GET | List available backtest data. **Alpha**
| `/version` | GET | Show version.
| `/sysinfo` | GET | Show information about the system load.
| `/health` | GET | Show bot health (last bot loop).
!!! Warning "Alpha status"
Endpoints labeled with *Alpha status* or *Beta status* above may change at any time without notice.
Endpoints labeled with *Alpha status* above may change at any time without notice.
### Message WebSocket
@@ -245,7 +245,7 @@ You would then add that token under `ws_token` in your `api_server` config. Like
"listen_port": 8080,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "somethingRandomSomethingRandom123",
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "Freqtrader",
"password": "SuperSecret1!",
+2 -7
View File
@@ -104,7 +104,7 @@ WHERE id=31;
### Remove trade from the database
!!! Tip "Use RPC Methods to delete trades"
Consider using `/delete <tradeid>` via telegram or rest API. That's the recommended way to deleting trades, as it will also remove the corresponding orders and custom data, and it will also trigger the necessary events in the bot to keep everything in sync.
Consider using `/delete <tradeid>` via telegram or rest API. That's the recommended way to deleting trades.
If you'd still like to remove a trade from the database directly, you can use the below query.
@@ -113,14 +113,9 @@ If you'd still like to remove a trade from the database directly, you can use th
```sql
DELETE FROM trades WHERE id = <tradeid>;
DELETE FROM orders WHERE ft_trade_id = <tradeid>;
DELETE FROM trade_custom_data WHERE ft_trade_id = <tradeid>;
DELETE FROM trades WHERE id = 31;
DELETE FROM orders WHERE ft_trade_id = 31;
DELETE FROM trade_custom_data WHERE ft_trade_id = 31;
```
!!! Warning
This will remove the specified trade from the database. Please make sure you got the correct id and **NEVER** run this query without the `where` clause.
This will remove this trade from the database. Please make sure you got the correct id and **NEVER** run this query without the `where` clause.
+2 -19
View File
@@ -39,22 +39,6 @@ The Order-type will be ignored if only one mode is available.
In that case, the bot will fallback to using the `emergency_exit` order type to place a market order as placing the stoploss order failed.
Freqtrade currently does not implement a limitation to avoid this situation, so please ensure your stoploss values are within reasonable limits for your exchange or disable stoploss on exchange.
### Which order type is used for stoploss on exchange?
The order type used for stoploss on exchange is determined by the `stoploss` value and the exchange capabilities.
If your selected exchange supports both stop-limit and stop-market orders, then the `stoploss` value will determine which order type is used for stoploss on exchange.
If your exchange only supports one of the two order types, you must configure your `stoploss` value accordingly, otherwise the bot will fail to start.
### Which order type should i use for stoploss on exchange?
If we translate the two stoploss order types into human words - they would be something like this:
* **stoploss-market** -> "when stop triggers, get me the hell out of here at whatever price".
* **stoploss-limit** -> "when stop triggers, place a limit order x% below the stoploss price. I accept a loss of "stoploss + 1%" at worst - but if price jumps further - i accept to wait for price to get back down to me, potentially resulting in a much bigger loss than "stoploss + 1%".
As a consequence, we recommend using stoploss-market orders whenever possible, as the main point of a stoploss is to get you out of a position when the market is crashing, and in such situations, you'll want to exit the position immediately at the best available price, rather than risking a limit order not getting filled and potentially incurring even greater losses.
The choice is ultimately up to you, but please be aware of the risk of using stoploss-limit orders, especially in volatile markets.
### stoploss_on_exchange and stoploss_on_exchange_limit_ratio
Enable or Disable stop loss on exchange.
@@ -82,10 +66,9 @@ This same logic will reapply a stoploss order on the exchange should you cancel
### stoploss_price_type
!!! Warning "Only applies to futures"
`stoploss_price_type` only applies to futures markets (on exchanges where it's available).
`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.
In spot markets, this setting is ignored and not validated, as most exchanges only support one price type for stoploss orders on spot markets.
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.
The naming for these prices in exchange terminology often varies, but is usually something around "last" (or "contract price" ), "mark" and "index".
+1 -1
View File
@@ -33,7 +33,7 @@ class AwesomeStrategy(IStrategy):
trade_entry_type = trade.get_custom_data(key='entry_type')
if trade_entry_type is None:
trade_entry_type = 'breakout' if 'entry_1' in trade.enter_tag else 'dip'
elif len(fills) > 1:
elif fills > 1:
trade_entry_type = 'buy_up'
trade.set_custom_data(key='entry_type', value=trade_entry_type)
return super().bot_loop_start(**kwargs)
+7 -11
View File
@@ -225,7 +225,7 @@ class AwesomeStrategy(IStrategy):
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/stable/strategy-advanced/
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.
@@ -696,9 +696,6 @@ However, freqtrade also offers a custom callback for both order types, which all
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).
!!! Tip "Replacing orders"
If you'd like to replace an order with a different price instead of just cancelling it, you might want to look at [`adjust_order_price()`](#adjust-order-price) instead, which will allow you to both cancel the order, as well as replace it with a new price.
### Custom order timeout example
Called for every open order until that order is either filled or cancelled.
@@ -808,7 +805,7 @@ class AwesomeStrategy(IStrategy):
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/stable/strategy-advanced/
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
When not implemented by a strategy, returns True (always confirming).
@@ -856,7 +853,7 @@ class AwesomeStrategy(IStrategy):
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/stable/strategy-advanced/
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
When not implemented by a strategy, returns True (always confirming).
@@ -994,7 +991,7 @@ class DigDeeperStrategy(IStrategy):
This means extra entry or exit 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/stable/strategy-advanced/
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
When not implemented by a strategy, returns None
@@ -1121,7 +1118,7 @@ class AwesomeStrategy(IStrategy):
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.
For full documentation please go to https://www.freqtrade.io/en/stable/strategy-callbacks/
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-callbacks/
When not implemented by a strategy, returns current_order_rate as default.
If current_order_rate is returned then the existing order is maintained.
@@ -1306,8 +1303,7 @@ Currently two types of annotations are supported, `area` and `line`.
"z_level": 5, // z-level, higher values are drawn on top of lower values. Positions relative to the Chart elements need to be set in freqUI.
"label": "some label",
"size": 2, // Optional, line width in pixels. Defaults to 10
"shape": "circle", // Optional, can be "circle", "rect", "roundRect", "triangle", "pin", "arrow", "none".
"rotate": 0, // Optional, rotation of the shape/symbol in degrees. Defaults to 0
"symbol": "circle", // Optional, can be "circle", "rect", "roundRect", "triangle", "pin", "arrow", "none".
}
```
@@ -1389,7 +1385,7 @@ Entries will be validated, and won't be passed to the UI if they don't correspon
}
)
elif (start_dt.hour % 2) == 0:
price = dataframe.loc[dataframe["date"] == start_dt, "close"].mean()
price = dataframe.loc[dataframe["date"] == start_dt, ["close"]].mean()
annotations.append(
{
"type": "area",
-2
View File
@@ -910,8 +910,6 @@ if self.dp.runmode.value in ('live', 'dry_run'):
### *check_delisting(pair)*
Return Datetime of the pair delisting schedule if any, otherwise return None
```python
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs):
if self.dp.runmode.value in ('live', 'dry_run'):
+6 -6
View File
@@ -594,9 +594,9 @@ Features will now expand automatically. As such, the expansion loops, as well as
More details on how these config defined parameters accelerate feature engineering
in the documentation at:
https://www.freqtrade.io/en/stable/freqai-parameter-table/#feature-parameters
https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters
https://www.freqtrade.io/en/stable/freqai-feature-engineering/#defining-the-features
https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features
:param df: strategy dataframe which will receive the features
:param period: period of the indicator - usage example:
@@ -657,9 +657,9 @@ Basic features. Make sure to remove the `{pair}` part from your features.
More details on how these config defined parameters accelerate feature engineering
in the documentation at:
https://www.freqtrade.io/en/stable/freqai-parameter-table/#feature-parameters
https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters
https://www.freqtrade.io/en/stable/freqai-feature-engineering/#defining-the-features
https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features
:param df: strategy dataframe which will receive the features
dataframe["%-pct-change"] = dataframe["close"].pct_change()
@@ -690,7 +690,7 @@ Basic features. Make sure to remove the `{pair}` part from your features.
More details about feature engineering available:
https://www.freqtrade.io/en/stable/freqai-feature-engineering
https://www.freqtrade.io/en/latest/freqai-feature-engineering
:param df: strategy dataframe which will receive the features
usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
@@ -713,7 +713,7 @@ Targets now get their own, dedicated method.
More details about feature engineering available:
https://www.freqtrade.io/en/stable/freqai-feature-engineering
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"]
+1 -1
View File
@@ -416,6 +416,6 @@ Your original strategy will remain available in the `user_data/strategies_orig_u
!!! Warning "Conversion results"
Strategy updater will work on a "best effort" approach. Please do your due diligence and verify the results of the conversion.
We also recommend to run a python formatter (e.g. `ruff format`) to format results in a sane manner.
We also recommend to run a python formatter (e.g. `black`) to format results in a sane manner.
--8<-- "commands/strategy-updater.md"
+1 -1
View File
@@ -1,6 +1,6 @@
"""Freqtrade bot"""
__version__ = "2026.5-dev"
__version__ = "2026.2-dev"
if "dev" in __version__:
from pathlib import Path
+3 -9
View File
@@ -215,7 +215,9 @@ AVAILABLE_CLI_OPTIONS = {
"--strategy-list",
help="Provide a space-separated list of strategies to backtest. "
"Please note that timeframe needs to be set either in config "
"or via command line. ",
"or via command line. When using this together with `--export trades`, "
"the strategy-name is injected into the filename "
"(so `backtest-data.json` becomes `backtest-data-SampleStrategy.json`",
nargs="+",
),
"backtest_notes": Arg(
@@ -238,14 +240,6 @@ AVAILABLE_CLI_OPTIONS = {
"exportfilename": Arg(
"--backtest-filename",
"--export-filename",
fthelp={
"freqtrade backtesting": (
"DEPRECATED: This option is deprecated for backtesting and will be removed "
"in a future release. "
"Using a custom filename for backtest results is no longer supported. "
"Use `--backtest-directory` to specify the directory."
),
},
help="Use this filename for backtest results."
"Example: `--backtest-filename=backtest_results_2020-09-27_16-20-48.json`. "
"Assumes either `user_data/backtest_results/` or `--export-directory` as base directory.",
+1 -1
View File
@@ -223,7 +223,7 @@ def start_list_trades_data(args: dict[str, Any]) -> None:
end.strftime(DATETIME_PRINT_FORMAT),
str(length),
)
for pair, start, end, length in sorted(paircombs1, key=lambda x: x[0])
for pair, start, end, length in sorted(paircombs1, key=lambda x: (x[0]))
],
("Pair", "Type", "From", "To", "Trades"),
summary=title,
+37 -3
View File
@@ -8,10 +8,13 @@ logger = logging.getLogger(__name__)
def start_convert_db(args: dict[str, Any]) -> None:
from sqlalchemy import func, select
from sqlalchemy.orm import make_transient
from freqtrade.configuration.config_setup import setup_utils_configuration
from freqtrade.persistence import Trade, init_db
from freqtrade.persistence.db_migration import migrate_db
from freqtrade.persistence import Order, Trade, init_db
from freqtrade.persistence.migrations import set_sequence_ids
from freqtrade.persistence.pairlock import PairLock
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
@@ -19,4 +22,35 @@ def start_convert_db(args: dict[str, Any]) -> None:
session_target = Trade.session
init_db(config["db_url_from"])
logger.info("Starting db migration.")
migrate_db(session_target)
trade_count = 0
pairlock_count = 0
for trade in Trade.get_trades():
trade_count += 1
make_transient(trade)
for o in trade.orders:
make_transient(o)
session_target.add(trade)
session_target.commit()
for pairlock in PairLock.get_all_locks():
pairlock_count += 1
make_transient(pairlock)
session_target.add(pairlock)
session_target.commit()
# Update sequences
max_trade_id = session_target.scalar(select(func.max(Trade.id)))
max_order_id = session_target.scalar(select(func.max(Order.id)))
max_pairlock_id = session_target.scalar(select(func.max(PairLock.id)))
set_sequence_ids(
session_target.get_bind(),
trade_id=max_trade_id,
order_id=max_order_id,
pairlock_id=max_pairlock_id,
)
logger.info(f"Migrated {trade_count} Trades, and {pairlock_count} Pairlocks.")
+3 -10
View File
@@ -4,7 +4,7 @@ import sys
from typing import Any
from freqtrade.enums import RunMode
from freqtrade.exceptions import ConfigurationError, DependencyException, OperationalException
from freqtrade.exceptions import ConfigurationError, OperationalException
logger = logging.getLogger(__name__)
@@ -166,14 +166,7 @@ def start_list_strategies(args: dict[str, Any]) -> None:
strategy_objs = sorted(strategy_objs, key=lambda x: x["name"])
for obj in strategy_objs:
if obj["class"]:
try:
obj["hyperoptable"] = detect_all_parameters(obj["class"])
except DependencyException as e:
logger.warning(
f"Cannot detect hyperoptable parameters for strategy {obj['name']}. Reason: {e}"
)
obj["hyperoptable"] = {}
obj["hyperoptable"] = detect_all_parameters(obj["class"])
else:
obj["hyperoptable"] = {}
@@ -393,7 +386,7 @@ def start_show_trades(args: dict[str, Any]) -> None:
tfilter = []
if config.get("trade_ids"):
tfilter.append(Trade.id.in_(int(tid) for tid in config["trade_ids"]))
tfilter.append(Trade.id.in_(config["trade_ids"]))
trades = Trade.get_trades(tfilter).all()
logger.info(f"Printing {len(trades)} Trades: ")
+1 -14
View File
@@ -236,10 +236,6 @@ CONF_SCHEMA = {
"type": "string",
"enum": BACKTEST_CACHE_AGE,
},
"skip_wallet_history_migration": {
"description": "Disable wallet history migration.",
"type": "boolean",
},
# Hyperopt
"hyperopt_path": {
"description": "Specify additional lookup path for Hyperopt Loss functions.",
@@ -756,8 +752,6 @@ CONF_SCHEMA = {
"jwt_secret_key": {
"description": "Secret key for JWT authentication.",
"type": "string",
"default": "somethingRandomSomethingRandom123",
"minLength": 32,
},
"CORS_origins": {
"description": "List of allowed CORS origins.",
@@ -770,14 +764,7 @@ CONF_SCHEMA = {
"enum": ["error", "info"],
},
},
"required": [
"enabled",
"listen_ip_address",
"listen_port",
"username",
"password",
"jwt_secret_key",
],
"required": ["enabled", "listen_ip_address", "listen_port", "username", "password"],
},
# end of RPC section
"db_url": {
@@ -92,7 +92,6 @@ def validate_config_consistency(conf: dict[str, Any], *, preliminary: bool = Fal
_validate_consumers(conf)
validate_migrated_strategy_settings(conf)
_validate_orderflow(conf)
_validate_demo_trading(conf)
# validate configuration before returning
logger.info("Validating configuration ...")
@@ -414,11 +413,6 @@ def _validate_orderflow(conf: dict[str, Any]) -> None:
)
def _validate_demo_trading(conf: dict[str, Any]) -> None:
if conf.get("exchange", {}).get("demo_trading", False) and conf.get("dry_run", False):
raise ConfigurationError("Demo trading cannot be used together with dry_run.")
def _strategy_settings(conf: dict[str, Any]) -> None:
process_deprecated_setting(conf, None, "use_sell_signal", None, "use_exit_signal")
process_deprecated_setting(conf, None, "sell_profit_only", None, "exit_profit_only")
+18 -25
View File
@@ -221,30 +221,30 @@ class Configuration:
config, argname="exportfilename", logstring="Storing backtest results to {} ..."
)
config["exportfilename"] = Path(config["exportfilename"])
if config.get("exportfilename"):
if Path(config["exportfilename"]).is_dir():
logger.warning(
"DEPRECATED: Using `--export-filename` with directories is deprecated, "
"use `--backtest-directory` instead."
)
if config.get("exportdirectory") is None:
# Fallback - assign export-directory directly.
config["exportdirectory"] = config["exportfilename"]
elif config.get("runmode") == RunMode.BACKTEST:
logger.warning(
"DEPRECATED: Using `--export-filename` has no impact when backtesting. "
"Please use `--notes` to annotate backtest results and "
"`--backtest-directory` to specify the output directory. "
)
if config.get("exportdirectory") and Path(config["exportdirectory"]).is_dir():
logger.warning(
"DEPRECATED: Using `--export-filename` with directories is deprecated, "
"use `--backtest-directory` instead."
)
if config.get("exportdirectory") is None:
# Fallback - assign export-directory directly.
config["exportdirectory"] = config["exportfilename"]
if not config.get("exportdirectory"):
config["exportdirectory"] = config["user_data_dir"] / "backtest_results"
config["exportfilename"] = config.get("exportfilename", None)
if not config.get("exportfilename"):
config["exportfilename"] = None
if config.get("exportfilename"):
# ensure exportfilename is a Path object
config["exportfilename"] = Path(config["exportfilename"])
config["exportdirectory"] = Path(config["exportdirectory"])
if self.args.get("show_sensitive"):
logger.warning(
"Sensitive information will be shown in the upcoming output. "
"Please make sure to never share this output without redacting "
"the information yourself."
)
def _process_optimize_options(self, config: Config) -> None:
# This will override the strategy configuration
self._args_to_config(
@@ -312,13 +312,6 @@ class Configuration:
self._process_datadir_options(config)
if self.args.get("show_sensitive"):
logger.warning(
"Sensitive information will be shown in the upcoming output. "
"Please make sure to never share this output without redacting "
"the information yourself."
)
self._args_to_config(
config,
argname="strategy_list",
@@ -410,7 +403,7 @@ class Configuration:
("include_inactive", "Detected --include-inactive-pairs: {}"),
("no_parallel_download", "Detected --no-parallel-download: {}"),
("download_trades", "Detected --dl-trades: {}"),
("convert_trades", "Detected --convert: {} - Converting trade data to OHLCV."),
("convert_trades", "Detected --convert: {} - Converting Trade data to OHCV {}"),
("dataformat_ohlcv", 'Using "{}" to store OHLCV data.'),
("dataformat_trades", 'Using "{}" to store trades data.'),
("show_timerange", "Detected --show-timerange"),
-4
View File
@@ -61,7 +61,6 @@ AVAILABLE_PAIRLISTS = [
"ProducerPairList",
"RemotePairList",
"MarketCapPairList",
"CrossMarketPairList",
"AgeFilter",
"DelistFilter",
"FullTradesFilter",
@@ -240,6 +239,3 @@ IntOrInf = float
EntryExecuteMode = Literal["initial", "pos_adjust", "replace"]
# Prefixes for low-priced coins like 1000PEPE/USDDT:USDT or KPEPE/USDC (hyperliquid)
PairPrefixes = ["1000", "1000000", "1M", "K"]
-1
View File
@@ -7,7 +7,6 @@ from .bt_fileutils import (
get_backtest_market_change,
get_backtest_result,
get_backtest_resultlist,
get_backtest_wallet_change,
get_latest_backtest_filename,
get_latest_hyperopt_file,
get_latest_hyperopt_filename,
+4 -27
View File
@@ -10,6 +10,7 @@ from io import BytesIO, StringIO
from pathlib import Path
from typing import Any, Literal
import numpy as np
import pandas as pd
from freqtrade.constants import LAST_BT_RESULT_FN
@@ -307,31 +308,10 @@ def get_backtest_market_change(filename: Path, include_ts: bool = True) -> pd.Da
else:
df = pd.read_feather(filename)
if include_ts:
df.loc[:, "__date_ts"] = df.loc[:, "date"].dt.as_unit("ms").astype("int64")
df.loc[:, "__date_ts"] = df.loc[:, "date"].astype(np.int64) // 1000 // 1000
return df
def get_backtest_wallet_change(filename: Path, strategy_name: str) -> pd.DataFrame | None:
"""
Read backtest wallet change file.
:param filename: Path to the backtest result zip file
:param strategy_name: Name of the strategy to load
:return: DataFrame with wallet change data
"""
if filename.suffix != ".zip":
return None
try:
data = load_file_from_zip(filename, f"{filename.stem}_{strategy_name}_wallet.feather")
df = pd.read_feather(BytesIO(data))
df.loc[:, "__date_ts"] = df.loc[:, "date"].dt.as_unit("ms").astype("int64")
return df
except ValueError:
pass
return None
def find_existing_backtest_stats(
dirname: Path | str, run_ids: dict[str, str], min_backtest_date: datetime | None = None
) -> dict[str, Any]:
@@ -523,16 +503,13 @@ def load_backtest_analysis_data(
return None
def trade_list_to_dataframe(
trades: list[Trade] | list[LocalTrade], *, minified: bool = True
) -> pd.DataFrame:
def trade_list_to_dataframe(trades: list[Trade] | list[LocalTrade]) -> pd.DataFrame:
"""
Convert list of Trade objects to pandas Dataframe
:param trades: List of trade objects
:param minified: Whether to use minified version of trade JSON
:return: Dataframe with BT_DATA_COLUMNS
"""
df = pd.DataFrame.from_records([t.to_json(minified) for t in trades], columns=BT_DATA_COLUMNS)
df = pd.DataFrame.from_records([t.to_json(True) for t in trades], columns=BT_DATA_COLUMNS)
if len(df) > 0:
df["close_date"] = pd.to_datetime(df["close_timestamp"], unit="ms", utc=True)
df["open_date"] = pd.to_datetime(df["open_timestamp"], unit="ms", utc=True)
@@ -1,4 +1,3 @@
from numpy import format_float_positional
from pandas import DataFrame, Series
@@ -12,10 +11,7 @@ def get_tick_size_over_time(candles: DataFrame) -> Series:
# count the number of significant digits for the open and close prices
for col in ["open", "high", "low", "close"]:
candles[f"{col}_count"] = (
candles[col]
.apply(format_float_positional, precision=14, unique=False, fractional=False, trim="-")
.str.extract(r"\.(\d*[1-9])")[0]
.str.len()
candles[col].round(14).apply("{:.15f}".format).str.extract(r"\.(\d*[1-9])")[0].str.len()
)
candles["max_count"] = candles[["open_count", "close_count", "high_count", "low_count"]].max(
axis=1
@@ -1,15 +1,9 @@
import logging
from datetime import datetime
import numpy as np
import pandas as pd
from freqtrade.constants import IntOrInf
from freqtrade.exchange import (
timeframe_to_prev_date,
timeframe_to_resample_freq,
)
from freqtrade.util import dt_from_ts
logger = logging.getLogger(__name__)
@@ -64,95 +58,3 @@ def evaluate_result_multi(
"""
df_final = analyze_trade_parallelism(trades, timeframe)
return df_final[df_final["open_trades"] > max_open_trades]
def balance_distribution_over_time(
trades: pd.DataFrame,
min_date: datetime,
max_date: datetime,
timeframe: str,
stake_currency: str,
start_balance: float,
pairlist: list[str],
) -> pd.DataFrame:
"""
Return a dataframe with stake_currency and the pairlist as columns
Each column will contain the amount of the currency at the given time
Columns added are:
- stake_currency: amount of stake currency
- <pair>: amount of base currency in the pair
- <pair>_leverage: leverage used for the pair at the time (NaN if no open trade)
- <pair>_is_short: 1 if the open trade is short, 0 if long (NaN if no open trade)
- <pair>_collateral: amount of stake currency used as collateral for open trades
:param trades: Trades Dataframe - can be loaded from backtest, or created
via trade_list_to_dataframe
:param timeframe: Frequency to use for the resulting dataframe
:param min_date: start date
:param max_date: End date (will be rounded down to timeframe)
:param stake_currency: The stake currency
:param start_balance: Starting balance in stake currency
:param pairlist: List of trading pairs to include in the dataframe
Can be obtained via trade_df["pair"].unique()
For pairs without trades, the column will be all zeros
:return: Dataframe with balance distribution over time
"""
min_date_res = timeframe_to_prev_date(timeframe, min_date)
max_date_res = timeframe_to_prev_date(timeframe, max_date)
index = pd.date_range(min_date_res, max_date_res, freq=timeframe_to_resample_freq(timeframe))
pairs_lev = [f"{pair}_leverage" for pair in pairlist]
pairs_is_short = [f"{pair}_is_short" for pair in pairlist]
pairs_collateral = [f"{pair}_collateral" for pair in pairlist]
pairs_lev += pairs_is_short
df = pd.DataFrame(
index=index, columns=[stake_currency] + pairlist + pairs_lev + pairs_collateral, dtype=float
)
# Initialize variables to starting values
df[stake_currency] = float(start_balance)
df[pairlist + pairs_collateral] = 0.0
df[pairs_lev] = np.nan
for trade in trades.sort_values(by=["open_date"]).itertuples():
pair = trade.pair
end_date = trade.close_date if trade.close_date is not pd.NaT else None
# Exclude open orders - these won't have order_filled_timestamp set.
df.loc[trade.open_date : end_date, f"{pair}_leverage"] = trade.leverage
df.loc[trade.open_date : end_date, f"{pair}_is_short"] = 1 if trade.is_short else 0
orders = [o for o in trade.orders if o["order_filled_timestamp"]]
current_position = 0
current_collateral = 0
for order in sorted(orders, key=lambda x: x["order_filled_timestamp"]):
filled_at = pd.Timestamp(dt_from_ts(order["order_filled_timestamp"]))
real_amount = order.get("filled", order["amount"])
stake = order["safe_price"] * real_amount
stake_no_lev = stake / trade.leverage
if order["ft_is_entry"]:
# Entry order: lock collateral and pay fee
# For both long and short: balance decreases by collateral + fee
fee_open = stake * trade.fee_open
current_position += real_amount
current_collateral += stake_no_lev
df.loc[filled_at:end_date, pair] += real_amount
df.loc[filled_at:end_date, f"{pair}_collateral"] += stake_no_lev
df.loc[filled_at:, stake_currency] -= stake_no_lev + fee_open
else:
# Exit order: release collateral and realize profit/loss
fee_close = stake * trade.fee_close
if trade.is_short:
# For SHORT
df.loc[filled_at:, stake_currency] += (
current_collateral * (1 + trade.leverage) - stake
) - fee_close
else:
# For LONG
df.loc[filled_at:, stake_currency] += (
stake - current_collateral * (trade.leverage - 1) - fee_close
)
df.loc[filled_at:end_date, pair] -= real_amount
df.loc[filled_at:end_date, f"{pair}_collateral"] -= stake_no_lev
current_position -= real_amount
current_collateral -= stake_no_lev
# Round to avoid floating point issues
df = df.round(14)
return df
+7 -11
View File
@@ -39,11 +39,7 @@ def ohlcv_to_dataframe(
df = DataFrame(ohlcv, columns=cols)
# Floor date to seconds to account for exchange imprecisions
from freqtrade.exchange import timeframe_to_floor_freq
resample_interval = timeframe_to_floor_freq(timeframe)
df["date"] = to_datetime(df["date"], unit="ms", utc=True).dt.floor(resample_interval)
df["date"] = to_datetime(df["date"], unit="ms", utc=True).dt.floor("s")
# Some exchanges return int values for Volume and even for OHLC.
# Convert them since TA-LIB indicators used in the strategy assume floats
@@ -63,14 +59,14 @@ def ohlcv_to_dataframe(
def clean_ohlcv_dataframe(
dataframe: DataFrame, timeframe: str, pair: str, *, fill_missing: bool, drop_incomplete: bool
data: DataFrame, timeframe: str, pair: str, *, fill_missing: bool, drop_incomplete: bool
) -> DataFrame:
"""
Cleanse a OHLCV dataframe by
* Grouping it by date (removes duplicate tics)
* dropping last candles if requested
* Filling up missing data (if requested)
:param dataframe: DataFrame containing candle (OHLCV) data.
:param data: DataFrame containing candle (OHLCV) data.
:param timeframe: timeframe (e.g. 5m). Used to fill up eventual missing data
:param pair: Pair this data is for (used to warn if fillup was necessary)
:param fill_missing: fill up missing candles with 0 candles
@@ -79,7 +75,7 @@ def clean_ohlcv_dataframe(
:return: DataFrame
"""
# group by index and aggregate results to eliminate duplicate ticks
dataframe = dataframe.groupby(by="date", as_index=False, sort=True).agg(
data = data.groupby(by="date", as_index=False, sort=True).agg(
{
"open": "first",
"high": "max",
@@ -90,13 +86,13 @@ def clean_ohlcv_dataframe(
)
# eliminate partial candle
if drop_incomplete:
dataframe.drop(dataframe.tail(1).index, inplace=True)
data.drop(data.tail(1).index, inplace=True)
logger.debug("Dropping last candle")
if fill_missing:
return ohlcv_fill_up_missing_data(dataframe, timeframe, pair)
return ohlcv_fill_up_missing_data(data, timeframe, pair)
else:
return dataframe
return data
def ohlcv_fill_up_missing_data(dataframe: DataFrame, timeframe: str, pair: str) -> DataFrame:
@@ -1,6 +1,6 @@
import logging
from pandas import DataFrame, read_feather
from pandas import DataFrame, read_feather, to_datetime
from pyarrow import dataset
from freqtrade.configuration import TimeRange
@@ -71,7 +71,7 @@ class FeatherDataHandler(IDataHandler):
"volume": "float",
}
)
pairdata["date"] = pairdata["date"].dt.as_unit("ms")
pairdata["date"] = to_datetime(pairdata["date"], unit="ms", utc=True)
return pairdata
except Exception as e:
logger.exception(
@@ -31,8 +31,8 @@ logger = logging.getLogger(__name__)
class IDataHandler(ABC):
_OHLCV_REGEX = r"^([\w-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)"
_TRADES_REGEX = r"^([\w-]+)\-(trades)?(?=\.)"
_OHLCV_REGEX = r"^([a-zA-Z_\d-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)"
_TRADES_REGEX = r"^([a-zA-Z_\d-]+)\-(trades)?(?=\.)"
def __init__(self, datadir: Path) -> None:
self._datadir = datadir
@@ -70,6 +70,28 @@ class IDataHandler(ABC):
if match and len(match.groups()) > 1
]
@classmethod
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: CandleType) -> list[str]:
"""
Returns a list of all pairs with ohlcv data available in this datadir
for the specified timeframe
:param datadir: Directory to search for ohlcv files
:param timeframe: Timeframe to search pairs for
:param candle_type: Any of the enum CandleType (must match trading mode!)
:return: List of Pairs
"""
candle = ""
if candle_type != CandleType.SPOT:
datadir = datadir.joinpath("futures")
candle = f"-{candle_type}"
ext = cls._get_file_extension()
_tmp = [
re.search(r"^(\S+)(?=\-" + timeframe + candle + f".{ext})", p.name)
for p in datadir.glob(f"*{timeframe}{candle}.{ext}")
]
# Check if regex found something and only return these results
return [cls.rebuild_pair_from_filename(match[0]) for match in _tmp if match]
@abstractmethod
def ohlcv_store(
self, pair: str, timeframe: str, data: DataFrame, candle_type: CandleType
@@ -336,10 +358,11 @@ class IDataHandler(ABC):
def rebuild_pair_from_filename(pair: str) -> str:
"""
Rebuild pair name from filename
Replaces the first '_' with '/' and the second '_' (if present) with ':'.
e.g. BTC_USDT -> BTC/USDT, BTC_USDT_USDT -> BTC/USDT:USDT
Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names.
"""
return pair.replace("_", "/", 1).replace("_", ":", 1)
res = re.sub(r"^(([A-Za-z\d]{1,10})|^([A-Za-z\-]{1,6}))(_)", r"\g<1>/", pair, count=1)
res = re.sub("_", ":", res, count=1)
return res
def ohlcv_load(
self,
@@ -1,5 +1,6 @@
import logging
import numpy as np
from pandas import DataFrame, read_json, to_datetime
from freqtrade import misc
@@ -34,8 +35,8 @@ class JsonDataHandler(IDataHandler):
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
self.create_dir_if_needed(filename)
_data = data.copy()
# Convert date to int (milliseconds)
_data["date"] = _data["date"].dt.as_unit("ms").astype("int64")
# Convert date to int
_data["date"] = _data["date"].astype(np.int64) // 1000 // 1000
# Reset index, select only appropriate columns and save as json
_data.reset_index(drop=True).loc[:, self._columns].to_json(
@@ -80,7 +81,7 @@ class JsonDataHandler(IDataHandler):
"volume": "float",
}
)
pairdata["date"] = to_datetime(pairdata["date"], unit="ms", utc=True).dt.as_unit("ms")
pairdata["date"] = to_datetime(pairdata["date"], unit="ms", utc=True)
return pairdata
def ohlcv_append(
@@ -104,9 +105,6 @@ class JsonDataHandler(IDataHandler):
:param trading_mode: Trading mode to use (used to determine the filename)
"""
filename = self._pair_trades_filename(self._datadir, pair, trading_mode)
# Convert StringDtype columns to object to avoid NaN serialization issues
for col in data.select_dtypes(include="string").columns:
data[col] = data[col].astype(object).where(data[col].notna(), other=None)
trades = data.values.tolist()
misc.file_dump_json(filename, trades, is_zip=self._use_zip)
@@ -1,6 +1,6 @@
import logging
from pandas import DataFrame, read_parquet
from pandas import DataFrame, read_parquet, to_datetime
from freqtrade.configuration import TimeRange
from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS, DEFAULT_TRADES_COLUMNS
@@ -68,7 +68,7 @@ class ParquetDataHandler(IDataHandler):
"volume": "float",
}
)
pairdata["date"] = pairdata["date"].dt.as_unit("ms")
pairdata["date"] = to_datetime(pairdata["date"], unit="ms", utc=True)
return pairdata
except Exception as e:
logger.exception(
+26 -197
View File
@@ -140,7 +140,7 @@ def _calc_drawdown_series(
max_drawdown_df["drawdown_relative"] = (max_balance - cumulative_balance) / max_balance
else:
# NOTE: This is not completely accurate,
# but will be good enough if starting_balance is not available
# but might good enough if starting_balance is not available
max_drawdown_df["drawdown_relative"] = (
max_drawdown_df["high_value"] - max_drawdown_df["cumulative"]
) / max_drawdown_df["high_value"]
@@ -296,7 +296,7 @@ def calculate_cagr(days_passed: int, starting_balance: float, final_balance: flo
:param final_balance: Final balance to calculate CAGR against
:return: CAGR
"""
if (final_balance < 0) or (starting_balance <= 0) or (days_passed <= 0):
if final_balance < 0:
# With leveraged trades, final_balance can become negative.
return 0
return (final_balance / starting_balance) ** (1 / (days_passed / 365)) - 1
@@ -333,72 +333,6 @@ def calculate_expectancy(trades: pd.DataFrame) -> tuple[float, float]:
return expectancy, expectancy_ratio
def _calculate_annualized_ratio(
expected_returns_mean: float,
denominator: float,
annualization_factor: int = 365,
) -> float:
"""
Helper function to calculate annualized ratios like Sharpe and Sortino.
:param expected_returns_mean: Mean of the returns (expected returns)
:param denominator: Denominator of the ratio (e.g. standard deviation for Sharpe)
:param annualization_factor: Factor to annualize the ratio (default is 365 for daily returns)
:return: Annualized ratio, or -100.0 if denominator is zero or NaN to indicate this is
not optimal.
"""
if denominator != 0 and not np.isnan(denominator):
return float(expected_returns_mean / denominator * np.sqrt(annualization_factor))
# Define high (negative) ratio to be clear that this is NOT optimal.
return -100.0
def _calculate_daily_returns_from_balance(
balance_history: pd.DataFrame,
date_col: str,
balance_col: str,
) -> pd.Series:
wallet = _prepare_balance_history(balance_history, date_col, balance_col)
if len(wallet) == 0:
return pd.DataFrame(columns=[date_col, balance_col])
# Sample balance to daily end-of-day values to normalize variable snapshot frequency.
daily_balance = (
wallet.set_index(date_col)[balance_col].resample("1D").last().dropna().rename(balance_col)
)
daily_balance = daily_balance.reset_index()
if len(daily_balance) < 2:
return pd.Series(dtype=float)
return daily_balance[balance_col].pct_change().dropna()
def _prepare_balance_history(
balance_history: pd.DataFrame,
date_col: str,
balance_col: str,
) -> pd.DataFrame:
"""
Prepare balance history for calculations by filtering out rows with
missing date or balance values.
"""
if (
len(balance_history) == 0
or date_col not in balance_history
or balance_col not in balance_history
):
return pd.DataFrame(columns=[date_col, balance_col])
wallet = balance_history.loc[:, [date_col, balance_col]].copy()
wallet = wallet.dropna(subset=[date_col, balance_col]).sort_values(date_col)
if len(wallet) == 0:
return pd.DataFrame(columns=[date_col, balance_col])
return wallet
def calculate_sortino(
trades: pd.DataFrame,
min_date: datetime | None,
@@ -420,31 +354,14 @@ def calculate_sortino(
down_stdev = np.std(trades.loc[trades["profit_abs"] < 0, "profit_abs"] / starting_balance)
return _calculate_annualized_ratio(expected_returns_mean, down_stdev)
if down_stdev != 0 and not np.isnan(down_stdev):
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)
else:
# Define high (negative) sortino ratio to be clear that this is NOT optimal.
sortino_ratio = -100
def calculate_sortino_from_balance(
balance_history: pd.DataFrame,
date_col: str = "date",
balance_col: str = "total_quote",
) -> float:
"""
Calculate sortino ratio from historical balance snapshots.
:param balance_history: DataFrame containing at least date and balance columns
:param date_col: Column containing timestamps
:param balance_col: Column containing historical balance values
:return: sortino
"""
daily_returns = _calculate_daily_returns_from_balance(balance_history, date_col, balance_col)
if len(daily_returns) == 0:
return 0.0
expected_returns_mean = daily_returns.mean()
downside_returns = daily_returns[daily_returns < 0]
down_stdev = downside_returns.std(ddof=0)
return _calculate_annualized_ratio(expected_returns_mean, down_stdev)
# print(expected_returns_mean, down_stdev, sortino_ratio)
return sortino_ratio
def calculate_sharpe(
@@ -467,67 +384,14 @@ def calculate_sharpe(
expected_returns_mean = total_profit.sum() / days_period
up_stdev = np.std(total_profit)
return _calculate_annualized_ratio(expected_returns_mean, up_stdev)
if up_stdev != 0:
sharp_ratio = expected_returns_mean / up_stdev * np.sqrt(365)
else:
# Define high (negative) sharpe ratio to be clear that this is NOT optimal.
sharp_ratio = -100
def calculate_sharpe_from_balance(
balance_history: pd.DataFrame,
date_col: str = "date",
balance_col: str = "total_quote",
) -> float:
"""
Calculate sharpe ratio from historical balance snapshots.
:param balance_history: DataFrame containing at least date and balance columns
:param date_col: Column containing timestamps
:param balance_col: Column containing historical balance values
:return: sharpe
"""
daily_returns = _calculate_daily_returns_from_balance(balance_history, date_col, balance_col)
if len(daily_returns) == 0:
return 0.0
expected_returns_mean = daily_returns.mean()
up_stdev = daily_returns.std(ddof=0)
return _calculate_annualized_ratio(expected_returns_mean, up_stdev)
def calculate_max_drawdown_from_balance(
balance_history: pd.DataFrame,
date_col: str = "date",
balance_col: str = "total_quote",
relative: bool = False,
) -> DrawDownResult:
"""
Calculate max drawdown from historical balance snapshots.
:param balance_history: DataFrame containing at least date and balance columns
:param date_col: Column containing timestamps
:param balance_col: Column containing historical balance values
:param relative: If True, use relative drawdown for max calculation instead of absolute
:return: DrawDownResult object
:raise: ValueError if balance-history dataframe was found empty.
"""
wallet = _prepare_balance_history(
balance_history=balance_history,
date_col=date_col,
balance_col=balance_col,
)
if len(wallet) < 2:
raise ValueError("Balance-history dataframe empty.")
starting_balance = float(wallet[balance_col].iloc[0])
wallet.loc[:, "total_balance"] = wallet[balance_col].diff().fillna(0.0)
return calculate_max_drawdown(
wallet,
date_col=date_col,
value_col="total_balance",
starting_balance=starting_balance,
relative=relative,
)
# print(expected_returns_mean, up_stdev, sharp_ratio)
return sharp_ratio
def calculate_calmar(
@@ -537,12 +401,12 @@ def calculate_calmar(
starting_balance: float,
) -> float:
"""
Calculate calmar from trades data.
Calculate calmar
:param trades: DataFrame containing trades (requires columns close_date and profit_abs)
:return: calmar
"""
if (len(trades) == 0) or (min_date is None) or (max_date is None) or (min_date == max_date):
return 0.0
return 0
total_profit = trades["profit_abs"].sum() / starting_balance
days_period = max(1, (max_date - min_date).days)
@@ -558,51 +422,16 @@ def calculate_calmar(
)
max_drawdown = drawdown.relative_account_drawdown
except ValueError:
return 0.0
max_drawdown = 0
return _calculate_annualized_ratio(expected_returns_mean, max_drawdown)
if max_drawdown != 0:
calmar_ratio = expected_returns_mean / max_drawdown * math.sqrt(365)
else:
# Define high (negative) calmar ratio to be clear that this is NOT optimal.
calmar_ratio = -100
def calculate_calmar_from_balance(
balance_history: pd.DataFrame,
date_col: str = "date",
balance_col: str = "total_quote",
) -> float:
"""
Calculate calmar ratio from historical balance snapshots.
:param balance_history: DataFrame containing at least date and balance columns
:param date_col: Column containing timestamps
:param balance_col: Column containing historical balance values
:return: calmar
"""
wallet = _prepare_balance_history(
balance_history=balance_history,
date_col=date_col,
balance_col=balance_col,
)
if len(wallet) < 2:
return 0.0
starting_balance = float(wallet[balance_col].iloc[0])
final_balance = float(wallet[balance_col].iloc[-1])
days_period = max(1, (wallet[date_col].iloc[-1] - wallet[date_col].iloc[0]).days)
total_profit = (final_balance - starting_balance) / starting_balance
expected_returns_mean = total_profit / days_period * 100
try:
drawdown = calculate_max_drawdown_from_balance(
wallet,
date_col=date_col,
balance_col=balance_col,
)
max_drawdown = drawdown.relative_account_drawdown
except ValueError:
return 0.0
return _calculate_annualized_ratio(expected_returns_mean, max_drawdown)
# print(expected_returns_mean, max_drawdown, calmar_ratio)
return calmar_ratio
def calculate_sqn(trades: pd.DataFrame, starting_balance: float) -> float:
+5 -2
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class CandleType(StrEnum):
class CandleType(str, Enum):
"""Enum to distinguish candle types"""
SPOT = "spot"
@@ -14,6 +14,9 @@ class CandleType(StrEnum):
FUNDING_RATE = "funding_rate"
# BORROW_RATE = "borrow_rate" # * unimplemented
def __str__(self):
return f"{self.name.lower()}"
@staticmethod
def from_string(value: str) -> "CandleType":
if not value:
+5 -2
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class MarginMode(StrEnum):
class MarginMode(str, Enum):
"""
Enum to distinguish between
cross margin/futures margin_mode and
@@ -11,3 +11,6 @@ class MarginMode(StrEnum):
CROSS = "cross"
ISOLATED = "isolated"
NONE = ""
def __str__(self):
return f"{self.value.lower()}"
+2 -2
View File
@@ -1,6 +1,6 @@
from enum import StrEnum
from enum import Enum
class OrderTypeValues(StrEnum):
class OrderTypeValues(str, Enum):
limit = "limit"
market = "market"
+2 -2
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class PriceType(StrEnum):
class PriceType(str, Enum):
"""Enum to distinguish possible trigger prices for stoplosses"""
LAST = "last"
+9 -4
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class RPCMessageType(StrEnum):
class RPCMessageType(str, Enum):
STATUS = "status"
WARNING = "warning"
EXCEPTION = "exception"
@@ -25,16 +25,21 @@ class RPCMessageType(StrEnum):
NEW_CANDLE = "new_candle"
def __repr__(self):
# TODO: do we still need to overwrite __repr__? Impact needs to be looked at in detail
return self.value
def __str__(self):
return self.value
# Enum for parsing requests from ws consumers
class RPCRequestType(StrEnum):
class RPCRequestType(str, Enum):
SUBSCRIBE = "subscribe"
WHITELIST = "whitelist"
ANALYZED_DF = "analyzed_df"
def __str__(self):
return self.value
NO_ECHO_MESSAGES = (RPCMessageType.ANALYZED_DF, RPCMessageType.WHITELIST, RPCMessageType.NEW_CANDLE)
+2 -2
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class RunMode(StrEnum):
class RunMode(str, Enum):
"""
Bot running mode (backtest, hyperopt, ...)
can be "live", "dry-run", "backtest", "hyperopt".
+13 -4
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class SignalType(StrEnum):
class SignalType(Enum):
"""
Enum to distinguish between enter and exit signals
"""
@@ -11,8 +11,11 @@ class SignalType(StrEnum):
ENTER_SHORT = "enter_short"
EXIT_SHORT = "exit_short"
def __str__(self):
return f"{self.name.lower()}"
class SignalTagType(StrEnum):
class SignalTagType(Enum):
"""
Enum for signal columns
"""
@@ -20,7 +23,13 @@ class SignalTagType(StrEnum):
ENTER_TAG = "enter_tag"
EXIT_TAG = "exit_tag"
def __str__(self):
return f"{self.name.lower()}"
class SignalDirection(StrEnum):
class SignalDirection(str, Enum):
LONG = "long"
SHORT = "short"
def __str__(self):
return f"{self.name.lower()}"
+5 -2
View File
@@ -1,7 +1,7 @@
from enum import StrEnum
from enum import Enum
class TradingMode(StrEnum):
class TradingMode(str, Enum):
"""
Enum to distinguish between
spot, margin, futures or any other trading method
@@ -10,3 +10,6 @@ class TradingMode(StrEnum):
SPOT = "spot"
MARGIN = "margin"
FUTURES = "futures"
def __str__(self):
return f"{self.name.lower()}"
-2
View File
@@ -30,7 +30,6 @@ from freqtrade.exchange.exchange_utils import (
validate_exchange,
)
from freqtrade.exchange.exchange_utils_timeframe import (
timeframe_to_floor_freq,
timeframe_to_minutes,
timeframe_to_msecs,
timeframe_to_next_date,
@@ -44,7 +43,6 @@ from freqtrade.exchange.htx import Htx
from freqtrade.exchange.hyperliquid import Hyperliquid
from freqtrade.exchange.idex import Idex
from freqtrade.exchange.kraken import Kraken
from freqtrade.exchange.krakenfutures import Krakenfutures
from freqtrade.exchange.kucoin import Kucoin
from freqtrade.exchange.lbank import Lbank
from freqtrade.exchange.luno import Luno
+1 -6
View File
@@ -46,13 +46,8 @@ class Binance(Exchange):
"l2_limit_range": [5, 10, 20, 50, 100, 500, 1000],
"ws_enabled": True,
"has_delisting": True,
# Demo trading
# https://www.binance.com/en/support/faq/detail/9be58f73e5e14338809e3b705b9687dd
# Intentionally Disabled as it's a separate market - not a simulated live market.
"supports_demo_trading": False,
}
_ft_has_futures: FtHas = {
"ohlcv_candle_limit": 499,
"funding_fee_candle_limit": 1000,
"stoploss_order_types": {"limit": "stop", "market": "stop_market"},
"stoploss_blocks_assets": False, # Stoploss orders do not block assets
@@ -559,7 +554,7 @@ class Binance(Exchange):
class Binanceusdm(Binance):
"""Binance USDM Exchange
"""Binacne USDM Exchange
Same as Binance - only futures trading is supported (via ccxt).
Not actually necessary, binance should be preferred.
File diff suppressed because it is too large Load Diff
+31 -52
View File
@@ -4,10 +4,9 @@ from datetime import datetime, timedelta
import ccxt
from freqtrade.constants import BuySell
from freqtrade.enums import OPTIMIZE_MODES, CandleType, MarginMode, PriceType, TradingMode
from freqtrade.enums import OPTIMIZE_MODES, CandleType, MarginMode, TradingMode
from freqtrade.exceptions import (
DDosProtection,
InvalidOrderException,
OperationalException,
RetryableOrderError,
TemporaryError,
@@ -39,13 +38,6 @@ class Bitget(Exchange):
_ft_has_futures: FtHas = {
"funding_fee_candle_limit": 100,
"has_delisting": True,
"stop_price_param": "stopLossPrice",
"stop_price_prop": "stopLossPrice",
"stop_price_type_field": "triggerType",
"stop_price_type_value_mapping": {
PriceType.LAST: "fill_price",
PriceType.MARK: "mark_price",
},
}
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
@@ -102,36 +94,30 @@ class Bitget(Exchange):
return order
def _fetch_stop_order_fallback(self, order_id: str, pair: str) -> CcxtOrder:
# old stoploss orders
paramsold = {"stop": True}
# new stoploss orders with stopLossPrice (used in futures starting 2026.4)
paramsnew = {"planType": "profit_loss"}
params_to_try = (
(paramsnew, paramsold) if self.trading_mode == TradingMode.FUTURES else (paramsold,)
)
for params2 in params_to_try:
for method in (
self._api.fetch_open_orders,
self._api.fetch_canceled_and_closed_orders,
):
try:
orders = method(pair, params=params2)
orders_f = [order for order in orders if order["id"] == order_id]
if orders_f:
order = orders_f[0]
self._log_exchange_response("get_stop_order_fallback", order)
return self._convert_stop_order(pair, order_id, order)
except (ccxt.OrderNotFound, ccxt.InvalidOrder):
pass
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get order due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
params2 = {
"stop": True,
}
for method in (
self._api.fetch_open_orders,
self._api.fetch_canceled_and_closed_orders,
):
try:
orders = method(pair, params=params2)
orders_f = [order for order in orders if order["id"] == order_id]
if orders_f:
order = orders_f[0]
self._log_exchange_response("get_stop_order_fallback", order)
return self._convert_stop_order(pair, order_id, order)
except (ccxt.OrderNotFound, ccxt.InvalidOrder):
pass
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get order due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
raise RetryableOrderError(f"StoplossOrder not found (pair: {pair} id: {order_id}).")
@retrier(retries=API_RETRY_COUNT)
@@ -143,19 +129,6 @@ class Bitget(Exchange):
return self._fetch_stop_order_fallback(order_id, pair)
def cancel_stoploss_order(self, order_id: str, pair: str, params: dict | None = None) -> dict:
cancel_params = params.copy() if params else {}
cancel_params["stop"] = True
if self.trading_mode != TradingMode.FUTURES:
return self.cancel_order(order_id, pair, cancel_params)
try:
return self.cancel_order(order_id, pair, {**cancel_params, "planType": "pos_loss"})
except (InvalidOrderException, IndexError):
# Keep compatibility with stoploss orders created by older versions.
return self.cancel_order(order_id, pair, cancel_params)
@retrier
def additional_exchange_init(self) -> None:
"""
@@ -177,6 +150,12 @@ class Bitget(Exchange):
except ccxt.BaseError as e:
raise OperationalException(e) from e
def _lev_prep(self, pair: str, leverage: float, side: BuySell, accept_fail: bool = False):
if self.trading_mode != TradingMode.SPOT:
# Explicitly setting margin_mode is not necessary as marginMode can be set per order.
# self.set_margin_mode(pair, self.margin_mode, accept_fail)
self._set_leverage(leverage, pair, accept_fail)
def _get_params(
self,
side: BuySell,
-3
View File
@@ -35,9 +35,6 @@ class Bybit(Exchange):
# TODO: Can be removed once bybit fully forces all accounts to unified mode.
"fetchOrder": False,
},
# Demo trading
# https://learn.bybit.com/en/bybit-guide/how-to-use-bybit-demo-trading
"supports_demo_trading": True,
}
_ft_has_futures: FtHas = {
"ohlcv_has_history": True,
+4 -2
View File
@@ -51,10 +51,12 @@ def check_exchange(config: Config, check_for_bad: bool = True) -> bool:
if not valid:
if check_for_bad:
raise OperationalException(
f'Exchange "{exchange}" will not work with Freqtrade. Reason: {reason}.'
f'Exchange "{exchange}" will not work with Freqtrade. Reason: {reason}.'
)
else:
logger.warning(f'Exchange "{exchange}" will not work with Freqtrade. Reason: {reason}.')
logger.warning(
f'Exchange "{exchange}" will not work with Freqtrade. Reason: {reason}.'
)
if MAP_EXCHANGE_CHILDCLASS.get(exchange, exchange) in SUPPORTED_EXCHANGES:
logger.info(
+1 -1
View File
@@ -39,6 +39,7 @@ BAD_EXCHANGES = {
"bitmex": "Various reasons",
"probit": "Requires additional, regular calls to `signIn()`",
"poloniex": "Does not provide fetch_order endpoint to fetch both open and closed orders",
"krakenfutures": "Unsupported futures exchange",
"kucoinfutures": "Unsupported futures exchange",
"poloniexfutures": "Unsupported futures exchange",
"binancecoinm": "Unsupported futures exchange",
@@ -62,7 +63,6 @@ SUPPORTED_EXCHANGES = [
"htx",
"hyperliquid",
"kraken",
"krakenfutures",
"okx",
"myokx",
]
+19 -53
View File
@@ -13,7 +13,6 @@ from datetime import UTC, datetime, timedelta
from math import floor, isnan
from threading import Lock
from typing import Any, Literal, TypeGuard, TypeVar
from uuid import uuid4
import ccxt
import ccxt.pro as ccxt_pro
@@ -107,7 +106,6 @@ from freqtrade.misc import (
file_dump_json,
file_load_json,
safe_value_fallback,
safe_value_nested,
)
from freqtrade.util import FtTTLCache, PeriodicCache, dt_from_ts, dt_now
from freqtrade.util.datetime_helpers import dt_humanize_delta, dt_ts, format_ms_time
@@ -209,7 +207,7 @@ class Exchange:
self._config.get("trading_mode", self._supported_trading_mode_margin_pairs[0][0])
)
self.margin_mode: MarginMode = MarginMode(
self._config["margin_mode"]
MarginMode(self._config.get("margin_mode"))
if self._config.get("margin_mode")
else self._supported_trading_mode_margin_pairs[0][1]
)
@@ -250,7 +248,7 @@ class Exchange:
# Holds all open sell orders for dry_run
self._dry_run_open_orders: dict[str, Any] = {}
self._is_demo_trading = exchange_conf.get("demo_trading", False)
if self._config["dry_run"]:
logger.info("Instance is running with dry_run enabled")
logger.info(f"Using CCXT {ccxt.__version__}")
@@ -315,19 +313,10 @@ class Exchange:
if self._exchange_ws:
self._exchange_ws.cleanup()
logger.debug("Exchange object destroyed, closing async loop")
try:
generic_loop = asyncio.get_running_loop()
except RuntimeError:
generic_loop = None
loop_running = (getattr(self, "loop", None) and self.loop.is_running()) or (
generic_loop is not None and generic_loop.is_running()
)
if (
getattr(self, "_api_async", None)
and inspect.iscoroutinefunction(self._api_async.close)
and self._api_async.session
and not loop_running
):
logger.debug("Closing async ccxt session.")
self.loop.run_until_complete(self._api_async.close())
@@ -335,7 +324,6 @@ class Exchange:
self._ws_async
and inspect.iscoroutinefunction(self._ws_async.close)
and self._ws_async.session
and not loop_running
):
logger.debug("Closing ws ccxt session.")
self.loop.run_until_complete(self._ws_async.close())
@@ -366,7 +354,6 @@ class Exchange:
self.validate_pricing(config["exit_pricing"])
self.validate_pricing(config["entry_pricing"])
self.validate_orderflow(config["exchange"])
self.validate_demo_trading(config["exchange"])
self.validate_freqai(config)
self._set_startup_candle_count(config)
@@ -420,9 +407,6 @@ class Exchange:
except ccxt.BaseError as e:
raise OperationalException(f"Initialization of ccxt failed. Reason: {e}") from e
if self.get_option("supports_demo_trading") and exchange_config.get("demo_trading", False):
api.enable_demo_trading(True)
return api
@property
@@ -438,12 +422,12 @@ class Exchange:
@property
def name(self) -> str:
"""exchange Name (from ccxt)"""
return self._api.name if not self._is_demo_trading else f"{self._api.name} (Demo)"
return self._api.name
@property
def id(self) -> str:
"""exchange ccxt id"""
return self._api.id if not self._is_demo_trading else f"{self._api.id}_demo"
return self._api.id
@property
def timeframes(self) -> list[str]:
@@ -830,8 +814,7 @@ class Exchange:
and order_types["stoploss_price_type"] not in price_mapping
):
raise ConfigurationError(
f"On exchange stoploss price type '{order_types['stoploss_price_type']}' "
f"is not supported for {self.name}."
f"On exchange stoploss price type is not supported for {self.name}."
)
def validate_pricing(self, pricing: dict) -> None:
@@ -875,16 +858,6 @@ class Exchange:
"fetching historic OHLCV data, otherwise freqAI will not work."
)
def validate_demo_trading(self, exchange_conf: dict) -> None:
"""Validate demo trading configuration
Prevents accidental configuration with wrong expectations.
"""
if exchange_conf.get("demo_trading", False):
if not self.get_option("supports_demo_trading"):
raise ConfigurationError(f"Demo trading is not supported for {self.name}.")
else:
logger.info(f"Demo trading enabled for {self.name}")
def validate_required_startup_candles(self, startup_candles: int, timeframe: str) -> int:
"""
Checks if required startup_candles is more than ohlcv_candle_limit().
@@ -1009,12 +982,12 @@ class Exchange:
swap.linear.fetchOHLCV.limit
"""
feat = (
safe_value_nested(self._api_async.features, "spot", {})
self._api_async.features.get("spot", {})
if market_type == "spot"
else safe_value_nested(self._api_async.features, "swap.linear", {})
else self._api_async.features.get("swap", {}).get("linear", {})
)
return safe_value_nested(feat, f"{endpoint}.{attribute}", default)
return feat.get(endpoint, {}).get(attribute, default)
def get_precision_amount(self, pair: str) -> float | None:
"""
@@ -1153,7 +1126,7 @@ class Exchange:
stop_price: float | None = None,
) -> CcxtOrder:
now = dt_now()
order_id = f"dry_run_{side}_{pair}_{uuid4()}"
order_id = f"dry_run_{side}_{pair}_{now.timestamp()}"
# Rounding here must respect to contract sizes
_amount = self._contracts_to_amount(
pair, self.amount_to_precision(pair, self._amount_to_contracts(pair, amount))
@@ -1183,7 +1156,7 @@ class Exchange:
orderbook: OrderBook | None = None
if self.exchange_has("fetchL2OrderBook"):
orderbook = self.fetch_l2_order_book(pair, 20)
if not stop_loss and ordertype == "limit" and orderbook:
if ordertype == "limit" and orderbook:
# Allow a 1% price difference
allowed_diff = 0.01
if self._dry_is_price_crossed(pair, side, rate, orderbook, allowed_diff):
@@ -1320,7 +1293,6 @@ class Exchange:
Check dry-run limit order fill and update fee (if it filled).
"""
if order["status"] != "closed" and order.get("ft_order_type") == "stoploss":
# Stoploss branch
pair = order["symbol"]
if not orderbook and self.exchange_has("fetchL2OrderBook"):
orderbook = self.fetch_l2_order_book(pair, 20)
@@ -1328,11 +1300,6 @@ class Exchange:
crossed = self._dry_is_price_crossed(
pair, order["side"], price, orderbook, is_stop=True
)
if crossed and immediate:
raise InvalidOrderException(
"Could not create dry stoploss order. Stoploss would trigger immediately."
)
if crossed:
average = self.get_dry_market_fill_price(
pair,
@@ -1912,12 +1879,9 @@ class Exchange:
orders = []
if self.exchange_has("fetchClosedOrders"):
orders = self._api.fetch_closed_orders(pair, since=since_ms)
if self.exchange_has("fetchCanceledOrders"):
orders_canceled = self._api.fetch_canceled_orders(pair, since=since_ms)
orders.extend(orders_canceled)
if self.exchange_has("fetchOpenOrders"):
orders_open = self._api.fetch_open_orders(pair, since=since_ms)
orders.extend(orders_open)
if self.exchange_has("fetchOpenOrders"):
orders_open = self._api.fetch_open_orders(pair, since=since_ms)
orders.extend(orders_open)
return orders
@retrier(retries=0)
@@ -2670,11 +2634,11 @@ class Exchange:
if self._can_use_websocket(self._exchange_ws, pair, timeframe, candle_type):
candle_ts = dt_ts(timeframe_to_prev_date(timeframe))
prev_candle_ts = dt_ts(date_minus_candles(timeframe, 1))
candles, last_refresh_time = self._exchange_ws.get_ohlcv_with_refresh(
pair, timeframe, candle_type
)
last_refresh_time = int(last_refresh_time)
candles = self._exchange_ws.ohlcvs(pair, timeframe)
half_candle = int(candle_ts - (candle_ts - prev_candle_ts) * 0.5)
last_refresh_time = int(
self._exchange_ws.klines_last_refresh.get((pair, timeframe, candle_type), 0)
)
if (
candles
@@ -3950,6 +3914,7 @@ class Exchange:
is_short: bool,
open_date: datetime,
close_date: datetime,
time_in_ratio: float | None = None,
) -> float:
"""
calculates the sum of all funding fees that occurred for a pair during a futures trade
@@ -3959,6 +3924,7 @@ class Exchange:
:param is_short: trade direction
:param open_date: The date and time that the trade started
:param close_date: The date and time that the trade ended
:param time_in_ratio: Not used by most exchange classes
"""
fees: float = 0
-2
View File
@@ -67,8 +67,6 @@ class FtHas(TypedDict, total=False):
# Delisting check
has_delisting: bool
# Demo mode - this is not sandbox but an exchange-provided demo mode.
supports_demo_trading: bool
class Ticker(TypedDict):
@@ -29,21 +29,6 @@ def timeframe_to_msecs(timeframe: str) -> int:
return ccxt.Exchange.parse_timeframe(timeframe) * 1000
def timeframe_to_floor_freq(timeframe: str) -> str:
"""
Translates the timeframe interval value written in the human readable
form ('1m', '5m', '1h', '1d', '1w', etc.) to the desired floor frequency used by pandas
("1m", "5m", "1h", "1d", "1w", etc.).
Will use minute for most higher timeframes.
"""
timeframe_seconds = timeframe_to_seconds(timeframe)
timeframe_minutes = timeframe_seconds // 60
if timeframe_minutes <= 1:
return "1s"
else:
return "1min"
def timeframe_to_resample_freq(timeframe: str) -> str:
"""
Translates the timeframe interval value written in the human readable
+77 -148
View File
@@ -1,8 +1,9 @@
import asyncio
import logging
import time
from copy import deepcopy
from functools import partial
from threading import Event, RLock, Thread
from threading import Thread
import ccxt
@@ -23,71 +24,49 @@ class ExchangeWS:
self.config = config
self._ccxt_object = ccxt_object
self._background_tasks: set[asyncio.Task] = set()
self._state_lock = RLock()
self._loop_ready = Event()
self._klines_watching: set[PairWithTimeframe] = set()
self._klines_scheduled: set[PairWithTimeframe] = set()
self._klines_last_refresh: dict[PairWithTimeframe, float] = {}
self._klines_last_request: dict[PairWithTimeframe, float] = {}
self.klines_last_refresh: dict[PairWithTimeframe, float] = {}
self.klines_last_request: dict[PairWithTimeframe, float] = {}
self._thread = Thread(name="ccxt_ws", target=self._start_forever)
self._thread.start()
self.__cleanup_called = False
def _start_forever(self) -> None:
self._loop = asyncio.new_event_loop()
self._loop_ready.set()
try:
self._loop.run_forever()
finally:
if not self._loop.is_closed():
# Cancel remaining tasks and close the loop in the owning thread.
pending = asyncio.all_tasks(self._loop)
for task in pending:
task.cancel()
if pending:
self._loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
self._loop.run_until_complete(self._loop.shutdown_asyncgens())
self._loop.close()
self._loop_ready.clear()
def _wait_for_loop(self, timeout: float = 1.0) -> bool:
"""
Wait for the event loop to be ready
Returns True once the loop is ready.
Will probably only return false during startup/shutdown.
"""
if hasattr(self, "_loop"):
return True
return self._loop_ready.wait(timeout=timeout) and hasattr(self, "_loop")
if self._loop.is_running():
self._loop.stop()
def cleanup(self) -> None:
logger.debug("Cleanup called - stopping")
with self._state_lock:
self._klines_watching.clear()
tasks = list(self._background_tasks)
for task in tasks:
self._klines_watching.clear()
for task in self._background_tasks:
task.cancel()
if self._wait_for_loop(timeout=0.2) and not self._loop.is_closed():
self.reset_connections(cleanup=True)
if hasattr(self, "_loop") and not self._loop.is_closed():
self.reset_connections()
self._loop.call_soon_threadsafe(self._loop.stop)
self._thread.join(timeout=5)
if self._thread.is_alive():
logger.warning("Websocket loop thread did not stop within timeout.")
time.sleep(0.1)
if not self._loop.is_closed():
self._loop.close()
self._thread.join()
logger.debug("Stopped")
def reset_connections(self, cleanup: bool = False) -> None:
def reset_connections(self) -> None:
"""
Reset all connections - avoids "connection-reset" errors that happen after ~9 days
"""
if self._wait_for_loop() and not self._loop.is_closed():
logger.info(f"{'Cleaning up' if cleanup else 'Resetting'} exchange WS connections.")
try:
fut = asyncio.run_coroutine_threadsafe(self._cleanup_async(), loop=self._loop)
fut.result(timeout=10)
except TimeoutError:
logger.warning("Timed out while resetting websocket connections.")
except Exception:
logger.exception("Exception while resetting websocket connections")
if hasattr(self, "_loop") and not self._loop.is_closed():
logger.info("Resetting WS connections.")
asyncio.run_coroutine_threadsafe(self._cleanup_async(), loop=self._loop)
while not self.__cleanup_called:
time.sleep(0.1)
self.__cleanup_called = False
async def _cleanup_async(self) -> None:
try:
@@ -97,14 +76,15 @@ class ExchangeWS:
self._ccxt_object.ohlcvs.clear()
except Exception:
logger.exception("Exception in _cleanup_async")
finally:
self.__cleanup_called = True
def _pop_history(self, paircomb: PairWithTimeframe) -> None:
"""
Remove history for a pair/timeframe combination from ccxt cache
"""
with self._state_lock:
self._ccxt_object.ohlcvs.get(paircomb[0], {}).pop(paircomb[1], None)
self._klines_last_refresh.pop(paircomb, None)
self._ccxt_object.ohlcvs.get(paircomb[0], {}).pop(paircomb[1], None)
self.klines_last_refresh.pop(paircomb, None)
@retrier(retries=3)
def ohlcvs(self, pair: str, timeframe: str) -> list[list]:
@@ -120,129 +100,81 @@ class ExchangeWS:
# TemporaryError does not cause backoff - so we're essentially retrying immediately
raise TemporaryError(f"Error deepcopying: {e}") from e
def get_ohlcv_with_refresh(
self, pair: str, timeframe: str, candle_type: CandleType
) -> tuple[list[list], float]:
"""
Get deepcopied klines and update the last refresh time
"""
ohlcvs = self.ohlcvs(pair, timeframe)
with self._state_lock:
last_refresh = self._klines_last_refresh.get((pair, timeframe, candle_type), 0)
return ohlcvs, last_refresh
def cleanup_expired(self) -> None:
"""
Remove pairs from watchlist if they've not been requested within
the last timeframe (+ offset)
"""
changed = False
with self._state_lock:
for p in list(self._klines_watching):
_, timeframe, _ = p
timeframe_s = timeframe_to_seconds(timeframe)
last_refresh = self._klines_last_request.get(p, 0)
if last_refresh > 0 and (dt_ts() - last_refresh) > ((timeframe_s + 20) * 1000):
logger.info(f"Removing {p} from websocket watchlist.")
self._klines_watching.discard(p)
# Pop history to avoid getting stale data
self._pop_history(p)
changed = True
for p in list(self._klines_watching):
_, timeframe, _ = p
timeframe_s = timeframe_to_seconds(timeframe)
last_refresh = self.klines_last_request.get(p, 0)
if last_refresh > 0 and (dt_ts() - last_refresh) > ((timeframe_s + 20) * 1000):
logger.info(f"Removing {p} from websocket watchlist.")
self._klines_watching.discard(p)
# Pop history to avoid getting stale data
self._pop_history(p)
changed = True
if changed:
logger.info(f"Removal done: new watch list ({len(self._klines_watching)})")
async def _schedule_while_true(self) -> None:
# For the ones we should be watching
with self._state_lock:
pairs_to_check = list(self._klines_watching)
for p in pairs_to_check:
for p in self._klines_watching:
# Check if they're already scheduled
with self._state_lock:
if p in self._klines_scheduled:
continue
if p not in self._klines_scheduled:
self._klines_scheduled.add(p)
pair, timeframe, candle_type = p
task = asyncio.create_task(
self._continuously_async_watch_ohlcv(pair, timeframe, candle_type)
)
with self._state_lock:
self._background_tasks.add(task)
task.add_done_callback(
partial(
self._continuous_stopped,
pair=pair,
timeframe=timeframe,
candle_type=candle_type,
pair, timeframe, candle_type = p
task = asyncio.create_task(
self._continuously_async_watch_ohlcv(pair, timeframe, candle_type)
)
self._background_tasks.add(task)
task.add_done_callback(
partial(
self._continuous_stopped,
pair=pair,
timeframe=timeframe,
candle_type=candle_type,
)
)
)
def exchange_has(self, endpoint: str) -> bool:
"""
Checks if exchange implements a specific API endpoint.
Wrapper around ccxt 'has' attribute
:param endpoint: Name of endpoint (e.g. 'fetchOHLCV', 'fetchTickers')
:return: bool
"""
return endpoint in self._ccxt_object.has and self._ccxt_object.has[endpoint]
async def _unwatch_ohlcv(self, pair: str, timeframe: str, candle_type: CandleType) -> None:
try:
if self.exchange_has("unWatchOHLCVForSymbols"):
await self._ccxt_object.un_watch_ohlcv_for_symbols([[pair, timeframe]])
elif self.exchange_has("unWatchOHLCV"):
await self._ccxt_object.un_watch_ohlcv(pair, timeframe)
else:
logger.debug("un_watch_ohlcv not supported for %s, %s", pair, timeframe)
await self._ccxt_object.un_watch_ohlcv_for_symbols([[pair, timeframe]])
except ccxt.NotSupported as e:
logger.debug("un_watch_ohlcv_for_symbols not supported: %s", e)
pass
except ccxt.NetworkError as e:
# Network errors are common on shutdown so we can ignore them.
# It's a network error - which most likely means that the connection is already closed.
logger.debug("Network error during unwatch for %s, %s: %s", pair, timeframe, e)
except Exception:
logger.exception(f"Exception in _unwatch_ohlcv for {pair}, {timeframe},")
logger.exception("Exception in _unwatch_ohlcv")
def _continuous_stopped(
self, task: asyncio.Task, pair: str, timeframe: str, candle_type: CandleType
) -> None:
with self._state_lock:
self._background_tasks.discard(task)
):
self._background_tasks.discard(task)
result = "done"
try:
if task.cancelled():
result = "cancelled"
else:
if (result1 := task.result()) is not None:
result = str(result1)
except Exception:
result = "error"
logger.exception(f"Unhandled exception in watch task callback for {pair}, {timeframe}")
finally:
logger.info(f"{pair}, {timeframe}, {candle_type} - Task finished - {result}")
if hasattr(self, "_loop") and not self._loop.is_closed():
asyncio.run_coroutine_threadsafe(
self._unwatch_ohlcv(pair, timeframe, candle_type), loop=self._loop
)
if task.cancelled():
result = "cancelled"
else:
if (result1 := task.result()) is not None:
result = str(result1)
with self._state_lock:
self._klines_scheduled.discard((pair, timeframe, candle_type))
self._pop_history((pair, timeframe, candle_type))
logger.info(f"{pair}, {timeframe}, {candle_type} - Task finished - {result}")
asyncio.run_coroutine_threadsafe(
self._unwatch_ohlcv(pair, timeframe, candle_type), loop=self._loop
)
self._klines_scheduled.discard((pair, timeframe, candle_type))
self._pop_history((pair, timeframe, candle_type))
async def _continuously_async_watch_ohlcv(
self, pair: str, timeframe: str, candle_type: CandleType
) -> None:
try:
while True:
with self._state_lock:
if (pair, timeframe, candle_type) not in self._klines_watching:
break
while (pair, timeframe, candle_type) in self._klines_watching:
start = dt_ts()
data = await self._ccxt_object.watch_ohlcv(pair, timeframe)
with self._state_lock:
self._klines_last_refresh[(pair, timeframe, candle_type)] = dt_ts()
self.klines_last_refresh[(pair, timeframe, candle_type)] = dt_ts()
logger.debug(
f"watch done {pair}, {timeframe}, data {len(data)} "
f"in {(dt_ts() - start) / 1000:.3f}s"
@@ -252,19 +184,14 @@ class ExchangeWS:
except ccxt.BaseError:
logger.exception(f"Exception in continuously_async_watch_ohlcv for {pair}, {timeframe}")
finally:
with self._state_lock:
self._klines_watching.discard((pair, timeframe, candle_type))
self._klines_watching.discard((pair, timeframe, candle_type))
def schedule_ohlcv(self, pair: str, timeframe: str, candle_type: CandleType) -> None:
"""
Schedule a pair/timeframe combination to be watched
"""
if not self._wait_for_loop():
logger.warning(f"Websocket loop not ready. Could not schedule {pair}, {timeframe}.")
return
with self._state_lock:
self._klines_watching.add((pair, timeframe, candle_type))
self._klines_last_request[(pair, timeframe, candle_type)] = dt_ts()
self._klines_watching.add((pair, timeframe, candle_type))
self.klines_last_request[(pair, timeframe, candle_type)] = dt_ts()
# asyncio.run_coroutine_threadsafe(self.schedule_schedule(), loop=self._loop)
asyncio.run_coroutine_threadsafe(self._schedule_while_true(), loop=self._loop)
self.cleanup_expired()
@@ -280,10 +207,12 @@ class ExchangeWS:
Returns cached klines from ccxt's "watch" cache.
:param candle_ts: timestamp of the end-time of the candle we expect.
"""
candles, refresh_date = self.get_ohlcv_with_refresh(pair, timeframe, candle_type)
# Deepcopy the response - as it might be modified in the background as new messages arrive
candles = self.ohlcvs(pair, timeframe)
refresh_date = self.klines_last_refresh[(pair, timeframe, candle_type)]
received_ts = candles[-1][0] if candles else 0
drop_hint = received_ts >= candle_ts
if refresh_date and received_ts > refresh_date:
if received_ts > refresh_date:
logger.warning(
f"{pair}, {timeframe} - Candle date > last refresh "
f"({format_ms_time(received_ts)} > {format_ms_time_det(refresh_date)}). "
+19 -67
View File
@@ -5,20 +5,11 @@ from copy import deepcopy
from datetime import datetime
from typing import Any
import ccxt
from freqtrade.constants import BuySell
from freqtrade.enums import MarginMode, TradingMode
from freqtrade.enums.runmode import NON_UTIL_MODES
from freqtrade.exceptions import (
ConfigurationError,
DDosProtection,
ExchangeError,
OperationalException,
TemporaryError,
)
from freqtrade.exceptions import ConfigurationError, ExchangeError, OperationalException
from freqtrade.exchange import Exchange
from freqtrade.exchange.common import retrier
from freqtrade.exchange.exchange_types import CcxtBalances, CcxtOrder, CcxtPosition, FtHas
from freqtrade.util.datetime_helpers import dt_from_ts
@@ -31,8 +22,6 @@ class Hyperliquid(Exchange):
Contains adjustments needed for Freqtrade to work with this exchange.
"""
unified_account = False
_ft_has: FtHas = {
"ohlcv_has_history": False,
"l2_limit_range": [20],
@@ -69,38 +58,6 @@ class Hyperliquid(Exchange):
config.update(super()._ccxt_config)
return config
@retrier
def additional_exchange_init(self) -> None:
"""
Additional exchange initialization logic.
.api will be available at this point.
Query User account Account Type to determine unified account status
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#query-a-users-abstraction-state
"""
try:
if self.trading_mode == TradingMode.FUTURES and not self._config["dry_run"]:
# Determine account status
# Unified accounts must use the spot endpoint for balances
request = {
"type": "userAbstraction",
"user": self._api.walletAddress,
}
response = self._api.publicPostInfo(request)
self.unified_account = response in ('"unifiedAccount"', '"portfolioMargin"')
if self.unified_account:
logger.info("Unified Hyperliquid account detected.")
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Error in additional_exchange_init due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
def _get_configured_hip3_dexes(self) -> list[str]:
"""Get list of configured HIP-3 DEXes."""
return self._config.get("exchange", {}).get("hip3_dexes", [])
@@ -165,33 +122,28 @@ class Hyperliquid(Exchange):
This override is not absolutely necessary and is only there for correct used / total values
which are however not used by Freqtrade in futures mode at the moment.
"""
params = params or {}
if self.unified_account:
params["type"] = "spot"
balances = super().get_balances(params)
if not self.unified_account:
# In unified accounts, the balance already includes all DEXes
dexes = self._get_configured_hip3_dexes()
for dex in dexes:
try:
dex_balance = super().get_balances(params={"dex": dex})
balances = super().get_balances()
dexes = self._get_configured_hip3_dexes()
for dex in dexes:
try:
dex_balance = super().get_balances(params={"dex": dex})
for currency, amount_info in dex_balance.items():
if currency in ["info", "free", "used", "total", "datetime", "timestamp"]:
continue
for currency, amount_info in dex_balance.items():
if currency in ["info", "free", "used", "total", "datetime", "timestamp"]:
continue
if currency not in balances:
balances[currency] = amount_info
else:
balances[currency]["free"] += amount_info["free"]
balances[currency]["used"] += amount_info["used"]
balances[currency]["total"] += amount_info["total"]
if currency not in balances:
balances[currency] = amount_info
else:
balances[currency]["free"] += amount_info["free"]
balances[currency]["used"] += amount_info["used"]
balances[currency]["total"] += amount_info["total"]
except Exception as e:
logger.error(f"Could not fetch balance for HIP-3 DEX '{dex}': {e}")
except Exception as e:
logger.error(f"Could not fetch balance for HIP-3 DEX '{dex}': {e}")
if dexes:
self._log_exchange_response("fetch_balance", balances, add_info="combined")
if dexes:
self._log_exchange_response("fetch_balance", balances, add_info="combined")
return balances
def fetch_positions(
+50
View File
@@ -1,9 +1,11 @@
"""Kraken exchange subclass"""
import logging
from datetime import datetime
from typing import Any
import ccxt
from pandas import DataFrame
from freqtrade.constants import BuySell
from freqtrade.enums import MarginMode, TradingMode
@@ -38,6 +40,7 @@ class Kraken(Exchange):
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
(TradingMode.SPOT, MarginMode.NONE),
# (TradingMode.MARGIN, MarginMode.CROSS),
# (TradingMode.FUTURES, MarginMode.CROSS)
]
def market_is_tradable(self, market: dict[str, Any]) -> bool:
@@ -111,6 +114,18 @@ class Kraken(Exchange):
except ccxt.BaseError as e:
raise OperationalException(e) from e
def _set_leverage(
self,
leverage: float,
pair: str | None = None,
accept_fail: bool = False,
):
"""
Kraken set's the leverage as an option in the order object, so we need to
add it to params
"""
return
def _get_params(
self,
side: BuySell,
@@ -133,6 +148,41 @@ class Kraken(Exchange):
params["postOnly"] = True
return params
def calculate_funding_fees(
self,
df: DataFrame,
amount: float,
is_short: bool,
open_date: datetime,
close_date: datetime,
time_in_ratio: float | None = None,
) -> float:
"""
# ! This method will always error when run by Freqtrade because time_in_ratio is never
# ! passed to _get_funding_fee. For kraken futures to work in dry run and backtesting
# ! functionality must be added that passes the parameter time_in_ratio to
# ! _get_funding_fee when using Kraken
calculates the sum of all funding fees that occurred for a pair during a futures trade
:param df: Dataframe containing combined funding and mark rates
as `open_fund` and `open_mark`.
:param amount: The quantity of the trade
:param is_short: trade direction
:param open_date: The date and time that the trade started
:param close_date: The date and time that the trade ended
:param time_in_ratio: Not used by most exchange classes
"""
if not time_in_ratio:
raise OperationalException(
f"time_in_ratio is required for {self.name}._get_funding_fee"
)
fees: float = 0
if not df.empty:
df = df[(df["date"] >= open_date) & (df["date"] <= close_date)]
fees = sum(df["open_fund"] * df["open_mark"] * amount * time_in_ratio)
return fees if is_short else -fees
def _get_trade_pagination_next_value(self, trades: list[dict]):
"""
Extract pagination id for the next "from_id" value
-300
View File
@@ -1,300 +0,0 @@
"""Kraken Futures exchange subclass"""
import logging
from datetime import datetime
from typing import Any
import ccxt
from freqtrade.enums import MarginMode, PriceType, TradingMode
from freqtrade.exceptions import (
DDosProtection,
ExchangeError,
InvalidOrderException,
OperationalException,
TemporaryError,
)
from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT, retrier
from freqtrade.exchange.exchange import Exchange
from freqtrade.exchange.exchange_types import CcxtBalances, CcxtOrder, FtHas
from freqtrade.misc import safe_value_nested
from freqtrade.util.datetime_helpers import dt_from_ts
logger = logging.getLogger(__name__)
class Krakenfutures(Exchange):
"""Kraken Futures exchange class.
Contains adjustments needed for Freqtrade to work with this exchange.
Key differences from spot Kraken:
- Stop orders use triggerPrice/triggerSignal instead of stopPrice
- Flex (multi-collateral) accounts need USD balance synthesis
"""
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
(TradingMode.FUTURES, MarginMode.ISOLATED),
]
_ft_has: FtHas = {
"tickers_have_quoteVolume": False,
"stoploss_on_exchange": True,
"stoploss_order_types": {
"limit": "limit",
"market": "market",
},
"stoploss_query_requires_stop_flag": True,
"stop_price_param": "triggerPrice",
"stop_price_prop": "stopPrice",
"stop_price_type_field": "triggerSignal",
"stop_price_type_value_mapping": {
PriceType.LAST: "last",
PriceType.MARK: "mark",
PriceType.INDEX: "index",
},
"exchange_has_overrides": {"fetchOrders": False},
}
@retrier
def get_balances(self, params: dict | None = None) -> CcxtBalances:
"""
Fetch balances with USD synthesis for flex (multi-collateral) accounts.
Kraken Futures flex accounts hold multiple currencies as collateral.
CCXT returns per-currency balances but doesn't expose margin values
as a USD balance. This override synthesizes a USD entry from flex account data
when stake_currency is USD.
Field mapping (margin-centric for internal consistency):
- free: availableMargin (margin available for new positions)
- total: marginEquity (haircut-adjusted collateral + unrealized P&L)
- used: total - free (margin currently in use)
Fallback chain for total: marginEquity -> portfolioValue -> balanceValue
"""
try:
balances = self._api.fetch_balance(params or {})
# Only synthesize USD if stake_currency is USD
stake = str(self._config.get("stake_currency", "")).upper()
if stake == "USD":
# Only synthesize if USD stake - flex only applies for these currencies.
# For flex accounts, synthesize USD balance from margin values
info = balances.get("info", {})
accounts = info.get("accounts", {}) if isinstance(info, dict) else {}
flex = accounts.get("flex", {}) if isinstance(accounts, dict) else {}
if flex:
usd_free = self._safe_float(flex.get("availableMargin"))
# Prefer marginEquity for consistency (same basis as availableMargin)
raw_total = (
flex.get("marginEquity")
or flex.get("portfolioValue")
or flex.get("balanceValue")
)
usd_total = self._safe_float(raw_total)
if usd_free is not None or usd_total is not None:
# Use available value for both if only one is present
usd_free_value = usd_free if usd_free is not None else usd_total
usd_total_value = usd_total if usd_total is not None else usd_free
if usd_free_value is not None and usd_total_value is not None:
usd_used = max(0.0, usd_total_value - usd_free_value)
balances["USD"] = {
"free": usd_free_value,
"used": usd_used,
"total": usd_total_value,
}
# Remove additional info from ccxt results (same as base class)
balances.pop("info", None)
balances.pop("free", None)
balances.pop("total", None)
balances.pop("used", None)
self._log_exchange_response("fetch_balance", balances, add_info=params)
return balances
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get balance due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
@staticmethod
def _safe_float(value: Any) -> float | None:
"""Convert value to float, returning None if conversion fails."""
if value is None:
return None
try:
return float(value)
except (ValueError, TypeError):
return None
def _order_contracts_to_amount(self, order: CcxtOrder) -> CcxtOrder:
"""Normalize order and apply Kraken Futures-specific order corrections."""
order = super()._order_contracts_to_amount(order)
return self._adjust_krakenfutures_order(order)
def _adjust_krakenfutures_order(self, order: CcxtOrder) -> CcxtOrder:
"""Apply Kraken Futures-specific order corrections.
For filled terminal orders, always fetch trades and compute VWAP because
CCXT's average is still unreliable.
See: https://github.com/ccxt/ccxt/issues/27996
"""
if order.get("status") == "canceled" and order.get("filled") is None:
# Workaround for missing filled parsing - https://github.com/ccxt/ccxt/issues/28210
order["filled"] = safe_value_nested(order, "info.order.filled", default_value=None)
filled = self._safe_float(order.get("filled")) or 0.0
if order.get("status") in ("canceled", "closed") and filled > 0:
# Compute VWAP and cost for filled orders.
trades = self.get_trades_for_order(
order["id"], order["symbol"], since=dt_from_ts(order["timestamp"])
)
if trades:
total_amount = sum(t["amount"] for t in trades)
if total_amount:
# Compute VWAP
order["average"] = sum(t["price"] * t["amount"] for t in trades) / total_amount
trade_costs = [t["cost"] for t in trades if t.get("cost") is not None]
if trade_costs:
order["cost"] = sum(trade_costs)
return order
def get_trades_for_order(
self, order_id: str, pair: str, since: datetime, params: dict | None = None
) -> list:
"""Fetch trades and enrich with calculated fees.
Kraken Futures' /fills endpoint does not include fee amounts — only
fillType (maker/taker). This enriches each trade with a calculated fee
using the market's fee schedule so Freqtrade's fee detection works.
"""
trades = super().get_trades_for_order(order_id, pair, since, params)
for trade in trades:
if trade.get("fee") is None or trade["fee"].get("cost") is None:
taker_or_maker = trade.get("takerOrMaker", "taker")
symbol = trade.get("symbol", pair)
market = self.markets.get(symbol, {})
fee_rate = market.get(taker_or_maker, market.get("taker", 0.0005))
cost = trade.get("cost")
if cost is not None and fee_rate is not None:
trade["fee"] = {
"cost": cost * fee_rate,
"currency": market.get("quote", "USD"),
"rate": fee_rate,
}
return trades
@retrier(retries=API_FETCH_ORDER_RETRY_COUNT)
def fetch_order(
self, order_id: str, pair: str, params: dict[str, Any] | None = None
) -> CcxtOrder:
"""Fetch order with direct CCXT call and fallback to history endpoints."""
if self._config.get("dry_run"):
return self.fetch_dry_run_order(order_id)
params = params or {}
status_params = {k: v for k, v in params.items() if k not in ("trigger", "stop")}
try:
order = self._api.fetch_order(order_id, pair, params=status_params)
self._log_exchange_response("fetch_order", order)
return self._order_contracts_to_amount(order)
except ccxt.OrderNotFound:
# Expected for older Kraken Futures orders not visible in orders/status.
pass
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except ccxt.InvalidOrder as e:
msg = f"Tried to get an invalid order (pair: {pair} id: {order_id}). Message: {e}"
raise InvalidOrderException(msg) from e
except (ccxt.OperationFailed, ccxt.ExchangeError):
# Fallback to history endpoints for temporary/status endpoint gaps.
pass
except ccxt.BaseError as e:
raise OperationalException(e) from e
order = self._fetch_order_fallback(order_id, pair, params)
if order is not None:
return order
# Order not in status, open, closed, or canceled endpoints - genuinely gone.
# Raise non-retrying InvalidOrderException (Kraken has limited history retention).
raise InvalidOrderException(
f"Order not found in any endpoint (pair: {pair} id: {order_id})"
)
def _fetch_order_fallback(
self, order_id: str, pair: str, params: dict[str, Any]
) -> CcxtOrder | None:
"""Search open, closed, and canceled order endpoints for order_id.
Kraken Futures' orders/status endpoint only returns currently open orders.
Older orders require querying history endpoints (closed/canceled).
For stoploss (trigger) orders, the caller should pass stop=True in params
(handled automatically via stoploss_query_requires_stop_flag in _ft_has)
so that closed/canceled queries hit the trigger history endpoint.
"""
order_id_str = str(order_id)
# Open orders include triggers by default. Avoid passing trigger/stop flags
# to prevent endpoint/filter mismatches.
open_params = {k: v for k, v in params.items() if k not in ("trigger", "stop")}
order = self._find_order_in_list(
self._api.fetch_open_orders, pair, open_params, order_id_str
)
if order is not None:
return order
# Closed/canceled: pass params through (including stop=True for stoploss orders,
# which CCXT maps to the trigger history endpoint).
for fetch_fn in (self._api.fetch_closed_orders, self._api.fetch_canceled_orders):
order = self._find_order_in_list(fetch_fn, pair, params, order_id_str)
if order is not None:
return order
return None
def _find_order_in_list(
self,
fetch_fn,
symbol: str | None,
params: dict[str, Any],
order_id_str: str,
) -> CcxtOrder | None:
"""Fetch orders and return matching order_id, or None."""
try:
orders = fetch_fn(symbol, params=params) or []
self._log_exchange_response(fetch_fn.__name__, orders)
for order in orders:
if str(order.get("id")) == order_id_str:
self._log_exchange_response("fetch_order_fallback", order)
return self._order_contracts_to_amount(order)
except (ccxt.OrderNotFound, ccxt.InvalidOrder) as e:
logger.debug(f"{fetch_fn.__name__} failed: {e}")
return None
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get order due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
return None
def get_funding_fees(self, pair: str, amount: float, is_short: bool, open_date) -> float:
"""Fetch funding fees, returning 0.0 if retrieval fails."""
if self.trading_mode == TradingMode.FUTURES:
try:
return self._fetch_and_calculate_funding_fees(pair, amount, is_short, open_date)
except ExchangeError:
logger.warning(f"Could not update funding fees for {pair}.")
return 0.0
+5 -9
View File
@@ -361,7 +361,7 @@ class FreqaiDataDrawer:
label_loc = df.columns.get_loc(label)
pred_label_loc = predictions.columns.get_loc(label)
df.iloc[-1, label_loc] = predictions.iloc[-1, pred_label_loc]
if pd.api.types.is_string_dtype(df[label].dtype):
if df[label].dtype == object:
continue
label_mean_loc = df.columns.get_loc(f"{label}_mean")
label_std_loc = df.columns.get_loc(f"{label}_std")
@@ -446,7 +446,7 @@ class FreqaiDataDrawer:
model_folders = [x for x in self.full_path.iterdir() if x.is_dir()]
pattern = re.compile(r"^sub-train-(.+)_(\d{10})$")
pattern = re.compile(r"sub-train-(\w+)_(\d{10})")
delete_dict: dict[str, Any] = {}
@@ -614,13 +614,9 @@ class FreqaiDataDrawer:
elif self.model_type == "pytorch":
import torch
zipfile = torch.load(
dk.data_path / f"{dk.model_filename}_model.zip",
weights_only=False,
)
# weights_only is necessary due to pytrainer being a serialized python object.
_trainer = zipfile["pytrainer"]
model = _trainer.load_from_checkpoint(zipfile)
zipfile = torch.load(dk.data_path / f"{dk.model_filename}_model.zip")
model = zipfile["pytrainer"]
model = model.load_from_checkpoint(zipfile)
if not model:
raise OperationalException(
+19 -21
View File
@@ -24,6 +24,8 @@ from freqtrade.strategy import merge_informative_pair
from freqtrade.strategy.interface import IStrategy
pd.set_option("future.no_silent_downcasting", True)
SECONDS_IN_DAY = 86400
SECONDS_IN_HOUR = 3600
@@ -237,14 +239,16 @@ class FreqaiDataKitchen:
filtered_df = filtered_df.replace([np.inf, -np.inf], np.nan)
drop_index = pd.isnull(filtered_df).any(axis=1) # get the rows that have NaNs,
drop_index = drop_index.replace(True, 1).replace(False, 0).infer_objects()
drop_index = drop_index.replace(True, 1).replace(False, 0).infer_objects(copy=False)
if training_filter:
# we don't care about total row number (total no. datapoints) in training, we only care
# about removing any row with NaNs
# if labels has multiple columns (user wants to train multiple modelEs), we detect here
labels = unfiltered_df.filter(label_list or [], axis=1)
drop_index_labels = pd.isnull(labels).any(axis=1)
drop_index_labels = drop_index_labels.replace(True, 1).replace(False, 0).infer_objects()
drop_index_labels = (
drop_index_labels.replace(True, 1).replace(False, 0).infer_objects(copy=False)
)
dates = unfiltered_df["date"]
filtered_df = filtered_df[
(drop_index == 0) & (drop_index_labels == 0)
@@ -424,28 +428,22 @@ class FreqaiDataKitchen:
Get backtest prediction from current backtest period
"""
# Build dict first and construct DataFrame once to avoid
# column-by-column assignment which causes DataFrame fragmentation
# and PerformanceWarning on large prediction sets.
append_dict: dict[str, Any] = {}
append_df = DataFrame()
for label in predictions.columns:
append_dict[label] = predictions[label]
if pd.api.types.is_string_dtype(predictions[label].dtype):
append_df[label] = predictions[label]
if append_df[label].dtype == object:
continue
if "labels_mean" in self.data and label in self.data["labels_mean"]:
append_dict[f"{label}_mean"] = self.data["labels_mean"][label]
if "labels_std" in self.data and label in self.data["labels_std"]:
append_dict[f"{label}_std"] = self.data["labels_std"][label]
if "labels_mean" in self.data:
append_df[f"{label}_mean"] = self.data["labels_mean"][label]
if "labels_std" in self.data:
append_df[f"{label}_std"] = self.data["labels_std"][label]
for extra_col in self.data["extra_returns_per_train"]:
append_dict[f"{extra_col}"] = self.data["extra_returns_per_train"][extra_col]
append_df[f"{extra_col}"] = self.data["extra_returns_per_train"][extra_col]
append_dict["do_predict"] = do_predict
append_df["do_predict"] = do_predict
if self.freqai_config["feature_parameters"].get("DI_threshold", 0) > 0:
append_dict["DI_values"] = self.DI_values
append_df = DataFrame(append_dict)
append_df["DI_values"] = self.DI_values
user_cols = [col for col in dataframe_backtest.columns if col.startswith("%%")]
cols = ["date"]
@@ -875,7 +873,7 @@ class FreqaiDataKitchen:
self.data["labels_mean"], self.data["labels_std"] = {}, {}
for label in self.data_dictionary["train_labels"].columns:
if pd.api.types.is_string_dtype(self.data_dictionary["train_labels"][label].dtype):
if self.data_dictionary["train_labels"][label].dtype == object:
continue
f = spy.stats.norm.fit(self.data_dictionary["train_labels"][label])
self.data["labels_mean"][label], self.data["labels_std"][label] = f[0], f[1]
@@ -901,7 +899,7 @@ class FreqaiDataKitchen:
self.find_labels(dataframe)
for key in self.label_list:
if pd.api.types.is_string_dtype(dataframe[key].dtype):
if dataframe[key].dtype == object:
self.unique_classes[key] = dataframe[key].dropna().unique()
if self.unique_classes:
@@ -986,7 +984,7 @@ class FreqaiDataKitchen:
are 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
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.
+3 -3
View File
@@ -676,7 +676,7 @@ class IFreqaiModel(ABC):
self.set_start_dry_live_date(strat_df)
for label in hist_preds_df.columns:
if pd.api.types.is_string_dtype(hist_preds_df[label].dtype):
if hist_preds_df[label].dtype == object:
continue
hist_preds_df[f"{label}_mean"] = 0
hist_preds_df[f"{label}_std"] = 0
@@ -706,7 +706,7 @@ class IFreqaiModel(ABC):
num_candles = self.freqai_info.get("fit_live_predictions_candles", 100)
dk.data["labels_mean"], dk.data["labels_std"] = {}, {}
for label in full_labels:
if pd.api.types.is_string_dtype(self.dd.historic_predictions[dk.pair][label].dtype):
if self.dd.historic_predictions[dk.pair][label].dtype == object:
continue
f = spy.stats.norm.fit(self.dd.historic_predictions[dk.pair][label].tail(num_candles))
dk.data["labels_mean"][label], dk.data["labels_std"][label] = f[0], f[1]
@@ -896,7 +896,7 @@ class IFreqaiModel(ABC):
]
self.fit_live_predictions(self.dk, self.dk.pair)
for label in label_columns:
if pd.api.types.is_string_dtype(dk.full_df[label].dtype):
if dk.full_df[label].dtype == object:
continue
if "labels_mean" in self.dk.data:
dk.full_df.at[index, f"{label}_mean"] = self.dk.data["labels_mean"][
@@ -1,12 +1,10 @@
import logging
from collections.abc import Callable
from typing import Any
from lightgbm import LGBMClassifier
from freqtrade.freqai.base_models.BaseClassifierModel import BaseClassifierModel
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
from freqtrade.freqai.tensorboard import LightGBMCallback
logger = logging.getLogger(__name__)
@@ -48,10 +46,6 @@ class LightGBMClassifier(BaseClassifierModel):
init_model = self.get_init_model(dk.pair)
model = LGBMClassifier(**self.model_training_parameters)
activate_tensorboard = self.freqai_info.get("activate_tensorboard", True)
callbacks: list[Callable[..., Any]] = []
if LightGBMCallback is not None:
callbacks = [LightGBMCallback(dk.data_path, activate_tensorboard)]
model.fit(
X=X,
y=y,
@@ -59,7 +53,6 @@ class LightGBMClassifier(BaseClassifierModel):
sample_weight=train_weights,
eval_sample_weight=[test_weights],
init_model=init_model,
callbacks=callbacks,
)
return model
@@ -6,7 +6,6 @@ from lightgbm import LGBMClassifier
from freqtrade.freqai.base_models.BaseClassifierModel import BaseClassifierModel
from freqtrade.freqai.base_models.FreqaiMultiOutputClassifier import FreqaiMultiOutputClassifier
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
from freqtrade.freqai.tensorboard import LightGBMCallback
logger = logging.getLogger(__name__)
@@ -54,11 +53,6 @@ class LightGBMClassifierMultiTarget(BaseClassifierModel):
else:
init_models = [None] * y.shape[1]
activate_tensorboard = self.freqai_info.get("activate_tensorboard", True)
callbacks = []
if LightGBMCallback is not None:
callbacks = [LightGBMCallback(dk.data_path, activate_tensorboard)]
fit_params = []
for i in range(len(eval_sets)):
fit_params.append(
@@ -66,7 +60,6 @@ class LightGBMClassifierMultiTarget(BaseClassifierModel):
"eval_set": eval_sets[i],
"eval_sample_weight": eval_weights,
"init_model": init_models[i],
"callbacks": callbacks,
}
)
@@ -1,12 +1,10 @@
import logging
from collections.abc import Callable
from typing import Any
from lightgbm import LGBMRegressor
from freqtrade.freqai.base_models.BaseRegressionModel import BaseRegressionModel
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
from freqtrade.freqai.tensorboard import LightGBMCallback
logger = logging.getLogger(__name__)
@@ -44,11 +42,6 @@ class LightGBMRegressor(BaseRegressionModel):
model = LGBMRegressor(**self.model_training_parameters)
activate_tensorboard = self.freqai_info.get("activate_tensorboard", True)
callbacks: list[Callable[..., Any]] = []
if LightGBMCallback is not None:
callbacks = [LightGBMCallback(dk.data_path, activate_tensorboard)]
model.fit(
X=X,
y=y,
@@ -56,7 +49,6 @@ class LightGBMRegressor(BaseRegressionModel):
sample_weight=train_weights,
eval_sample_weight=[eval_weights],
init_model=init_model,
callbacks=callbacks,
)
return model

Some files were not shown because too many files have changed in this diff Show More