Compare commits
578 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b11119dbe5 | |||
| cefc833ab1 | |||
| 5c7c3a88fb | |||
| 14e2e160af | |||
| 000eb875a2 | |||
| 33c8969411 | |||
| d90666d2e8 | |||
| f568d63c41 | |||
| 78943bf88d | |||
| 1b8a42d472 | |||
| faa398053a | |||
| 23e4943b3a | |||
| b3ec69fa8a | |||
| dc4aaf0a82 | |||
| d5b9c6dde8 | |||
| bdfd3396cc | |||
| c9256e0d9f | |||
| c7e02b9a7f | |||
| 7d5cd998a3 | |||
| 96e8319e82 | |||
| 12d8fc8c3a | |||
| 1ad0e423c9 | |||
| 2ef1e203c6 | |||
| 959f81f4ac | |||
| 3090e47a12 | |||
| 02ab0eb139 | |||
| 5d8759de78 | |||
| b13b00df17 | |||
| d8b51875bf | |||
| 7f12f3a0e4 | |||
| 6afcc80937 | |||
| efdb726362 | |||
| 3ca7407b09 | |||
| 22ba0e61e3 | |||
| 6e83890a13 | |||
| 8a8cc5e563 | |||
| e1bf3bb825 | |||
| 875216cdc5 | |||
| 903b580026 | |||
| 073b625355 | |||
| b3b21e6b93 | |||
| b8b4b2d2f3 | |||
| 0cf1f6dc88 | |||
| 502d50c988 | |||
| ed8b8fbf61 | |||
| 956398ab21 | |||
| f3154423bd | |||
| 124c051432 | |||
| 67bcf38ea5 | |||
| a98dd0eea3 | |||
| 103f64227f | |||
| 5b481009d6 | |||
| 3da6a8146e | |||
| a8b313d387 | |||
| 574419f3a4 | |||
| 5793888113 | |||
| b835af58c5 | |||
| ca0b6998f0 | |||
| 77c3894fe2 | |||
| 0c46afaee4 | |||
| b6e9609039 | |||
| 1b6dadbc87 | |||
| 1b18856d0b | |||
| 35e9805ef1 | |||
| dcf38557ee | |||
| 54d78fd1c6 | |||
| 6040c391d3 | |||
| 0c6ed588b5 | |||
| 45dc667233 | |||
| 10d79f6232 | |||
| 3c20106e7d | |||
| 1e1c9a28f2 | |||
| 6a01985fd1 | |||
| be572ba046 | |||
| f711afd843 | |||
| d6f58cd6cf | |||
| 9dd1ce71ca | |||
| 0a0a8428d5 | |||
| fdc248a1b1 | |||
| bfadd54ea3 | |||
| ed23dc0f72 | |||
| 27e3ae8c24 | |||
| f6cb446bff | |||
| 72786ca706 | |||
| 3e2a799d9f | |||
| 841f57800e | |||
| 5b6ea5ca90 | |||
| 162c1c606c | |||
| de0759c36a | |||
| 1dbef58fe9 | |||
| a63280bfa5 | |||
| 093a3f0e25 | |||
| f8fc8a7f33 | |||
| f8bf850673 | |||
| d06a531c72 | |||
| b341bc5a8c | |||
| 5ac1cf929b | |||
| eca2ca3dc2 | |||
| 1d8fd059c6 | |||
| a95972ae3f | |||
| 37985dfeea | |||
| 768efc45ff | |||
| e6b5233d2f | |||
| 6fa1133c61 | |||
| b1adb2b13d | |||
| 16378d32d7 | |||
| 33105a996e | |||
| a6d76cad39 | |||
| 3d1568783e | |||
| 194d53acf8 | |||
| 82cd343fc1 | |||
| 751d98495f | |||
| 49b119f1dc | |||
| 6ba0eaf593 | |||
| 87f07d5f91 | |||
| a24f5d64a1 | |||
| 30eb32862c | |||
| 6ae5724ad1 | |||
| 90a57e7384 | |||
| 16379bbcc5 | |||
| 05bb7e2fad | |||
| 6e98635345 | |||
| de8dd83340 | |||
| b3296b75e9 | |||
| 2f9ec970a5 | |||
| 568c579cab | |||
| e116b71400 | |||
| a85dc6972d | |||
| feab28de91 | |||
| 0aa05855d5 | |||
| 44591053b6 | |||
| c11de3ac38 | |||
| b797a5bf2f | |||
| 1d9d2fce7f | |||
| 0e92372b0b | |||
| 68fbab5c32 | |||
| 596f6711f3 | |||
| c2296d83c3 | |||
| 9a3ada65f5 | |||
| df50e03239 | |||
| 9d0f5df549 | |||
| 6b41594c53 | |||
| 2d194995bc | |||
| 904580b914 | |||
| 9373779fba | |||
| 692bb36c80 | |||
| 8de5e2b7b8 | |||
| 6185761727 | |||
| 6c625c77c0 | |||
| 9950ed715e | |||
| 9b9ef6ae6d | |||
| 8075106286 | |||
| 6b033c211e | |||
| 8be31275d7 | |||
| a3d3a4de51 | |||
| f1b890954a | |||
| 0f2ff70bdf | |||
| 4c42bd7100 | |||
| 9acf8943ed | |||
| 4986f356ee | |||
| ca390eea6a | |||
| cd9c45e875 | |||
| c90ac30077 | |||
| 466914d5c7 | |||
| f86f955e24 | |||
| affab24185 | |||
| 125126fb86 | |||
| 010ed6992b | |||
| d8bbd4054e | |||
| baefaeb311 | |||
| 288db16198 | |||
| eb4199fe80 | |||
| 9a151b1ecf | |||
| 7dddab18c4 | |||
| a85afd9af3 | |||
| d09efa6dd1 | |||
| f817b21d17 | |||
| b7298f472c | |||
| 96baa90003 | |||
| fae7198bb4 | |||
| 55be046933 | |||
| 38fa7068ca | |||
| e5389be209 | |||
| 19a997a2db | |||
| eac440649b | |||
| 21a47bb1ac | |||
| b839e159a8 | |||
| 91df1257e7 | |||
| 88f8e831d7 | |||
| 627eee5fcf | |||
| 26c7752b7c | |||
| 1aaf0c2034 | |||
| ac3a5900b4 | |||
| 60695fe205 | |||
| 2e2f40ca10 | |||
| 1f09b90dbe | |||
| 9c39b99ec6 | |||
| 2e343b9fbd | |||
| 087fb31f26 | |||
| 3edc442f48 | |||
| b6cf3cc57d | |||
| be2d97b559 | |||
| a3f23fd4fb | |||
| 68f32d76ae | |||
| bb596d6f8d | |||
| ca573a828f | |||
| e9cd840f5b | |||
| 7894c08b83 | |||
| 296c14afc0 | |||
| b2b1518708 | |||
| 93967ad8f0 | |||
| 6082beb58d | |||
| 8309853439 | |||
| 2522a3be61 | |||
| 19b38a02fa | |||
| 4935e23271 | |||
| a4f9a25007 | |||
| 795a0b81ee | |||
| e5268a0449 | |||
| c81761e3e2 | |||
| 8fbb4e1e60 | |||
| 937aa5c70e | |||
| db647ab4d5 | |||
| 98652bfd89 | |||
| 63010bc5e9 | |||
| dd388a51e0 | |||
| 22f109bab1 | |||
| 67e2d9c730 | |||
| 07fb941758 | |||
| 6fca35adae | |||
| ac9b26cc57 | |||
| 31aa397492 | |||
| b77739b5ca | |||
| 722d5b2319 | |||
| 91ace759c5 | |||
| 3d8d2fc0c6 | |||
| 58154d76ae | |||
| 38feb90f9e | |||
| 4632839fc5 | |||
| 26ea4fdcc9 | |||
| 3637d7a54c | |||
| 6ee500db4f | |||
| 583e20dc9d | |||
| b3296a06d9 | |||
| 09051fb641 | |||
| 3c6500c2bc | |||
| f242110957 | |||
| bb08880c4a | |||
| 948487518d | |||
| 9480331b45 | |||
| be5d158761 | |||
| 4f2681500a | |||
| 00237d68e4 | |||
| 20325a2b5e | |||
| be40e828a9 | |||
| 916ef43f7f | |||
| 2b01d2e06b | |||
| 0553486e55 | |||
| 4fa8c3f9ab | |||
| 543c77fe00 | |||
| e77ce8d481 | |||
| 285867f8c6 | |||
| 7c5b2fdffb | |||
| 8cf3f3826f | |||
| 799ce4e1f2 | |||
| 1fdce89806 | |||
| e1f2f0cb64 | |||
| c3b6258dfe | |||
| 4154a7058d | |||
| bdfa9c146e | |||
| c6d6bc62eb | |||
| 2347195b0b | |||
| f3101e8a75 | |||
| 43dd90f6d4 | |||
| 7ef52365f7 | |||
| 00bdf13fae | |||
| 5f8608d3b3 | |||
| d19498667a | |||
| b2898cf742 | |||
| 31625befd1 | |||
| 394535c2e8 | |||
| 16576d37b1 | |||
| 53bd2d71a0 | |||
| df4b44d09e | |||
| b6b3429b62 | |||
| 0adb264c9b | |||
| 286371c1e4 | |||
| 445c3a67db | |||
| 06c4b661f7 | |||
| 3ffc69ad02 | |||
| 7b44dd17ae | |||
| 5b0b44069a | |||
| 85fc936431 | |||
| 04a28b2550 | |||
| 9fa3a15e24 | |||
| 23b10161d5 | |||
| b8dffe0eb0 | |||
| 85772ac7f7 | |||
| 3ec72f88e2 | |||
| 4f4f927b97 | |||
| 46fab55378 | |||
| 1d44f75659 | |||
| a4416b885a | |||
| 209c2e0ceb | |||
| 324aada2bc | |||
| 6f58e01f8e | |||
| 31e4501765 | |||
| 50d60fad89 | |||
| 7286568447 | |||
| 3116fd34cf | |||
| f70815dd8e | |||
| 47151e77e1 | |||
| 5a1f96d35c | |||
| fe03bf7ce0 | |||
| d09160fff8 | |||
| f46c8cdc4a | |||
| db57f83922 | |||
| c6e64bad49 | |||
| bbf0ac83a1 | |||
| a9714727b1 | |||
| 8e2de9ef7e | |||
| 5ea7ba6b9a | |||
| e3e924d888 | |||
| 02b0f0abd6 | |||
| 7735ea91bb | |||
| 7178ce8559 | |||
| 26ba076143 | |||
| 425701ddcf | |||
| 42e45a0a65 | |||
| b97f3ca818 | |||
| dfc77945ce | |||
| 6d8011e075 | |||
| 1b4f8dfa54 | |||
| 48b7a85c90 | |||
| 0d7854ff1b | |||
| d3464ac2dc | |||
| 95f5db9dcd | |||
| 61b29962c4 | |||
| b83754c5a4 | |||
| 9a1f2d42a7 | |||
| bd511c2158 | |||
| 6b6d7fc310 | |||
| c6959c92ac | |||
| 7bc6a2279c | |||
| b431c5b343 | |||
| 176f5518ea | |||
| 06406b7103 | |||
| 17e4f5ed1f | |||
| 578ba9ea4a | |||
| 83a8651d41 | |||
| ba0c22b6f0 | |||
| 90219f040b | |||
| fef234d80f | |||
| 68ad688665 | |||
| 0c7a2747d3 | |||
| 23187f0c41 | |||
| f66d81c4b8 | |||
| 87a64cbe68 | |||
| ef58aaf9e9 | |||
| 4a432760ed | |||
| 484943a640 | |||
| eec16cfc8a | |||
| fddceb2572 | |||
| d665a01fe6 | |||
| 8f93ac5770 | |||
| 33164ec041 | |||
| 0e6cd72edd | |||
| 4f218e4fb2 | |||
| 0bf411ae19 | |||
| 283199b6ed | |||
| 0270a61cba | |||
| 1aeed3951b | |||
| ba38f8120c | |||
| 7de9e2c4b6 | |||
| 331c6beafc | |||
| 93cbbbbe31 | |||
| ddd2e2cc3b | |||
| 55301b8d0c | |||
| a47ed1dbdb | |||
| 17b161cb03 | |||
| 5d3c764e27 | |||
| f3aac3d66d | |||
| 39903d521e | |||
| 7255beddea | |||
| a95c3ace92 | |||
| d543feb032 | |||
| 623f27341f | |||
| 55dc2d4bf4 | |||
| 24e94cfaa7 | |||
| 7db62689c4 | |||
| da53b5d115 | |||
| 03dfe4ec45 | |||
| 39288d2e53 | |||
| 2a6dc3e45d | |||
| 5964845265 | |||
| 9911d2aa32 | |||
| bfd2c3f942 | |||
| 74c837519a | |||
| 415e361c66 | |||
| 7e154c6fb6 | |||
| 385b39ff66 | |||
| 9d232c4949 | |||
| 85ccc31a63 | |||
| 65d19c38b6 | |||
| 5b8752e649 | |||
| 8832bae371 | |||
| a85e044e99 | |||
| 7b1ee84b34 | |||
| 79ebc943a2 | |||
| eabcaa38e2 | |||
| e930221b78 | |||
| 08c4f24bdf | |||
| 56c23f9dd8 | |||
| 6edee269d8 | |||
| f9d978f16a | |||
| 1eac77fe0b | |||
| a98121ea26 | |||
| cc9c373a76 | |||
| 390b113776 | |||
| bf33f8b632 | |||
| 030dcfdd83 | |||
| cd77758852 | |||
| 1aa6c2ad55 | |||
| 55d71cecdd | |||
| 70a81c86ba | |||
| 1c6c710696 | |||
| 4ca2a043b5 | |||
| 41418784e3 | |||
| 9afd572948 | |||
| 51a99f2a66 | |||
| 969b0570c2 | |||
| e94ccece93 | |||
| cd435098bd | |||
| 33659ee273 | |||
| c30db9d0d6 | |||
| 429505b134 | |||
| 2c2cc086c3 | |||
| fe16654733 | |||
| f85891941f | |||
| 493b6f6592 | |||
| 97faa7fc5a | |||
| 5402b14336 | |||
| 4c7ff7ab0c | |||
| 8288a5cf91 | |||
| 442b29e0ea | |||
| 743422ccf3 | |||
| d69b1566b1 | |||
| 5c01023d55 | |||
| 97d303579a | |||
| 265a798f78 | |||
| db19446e27 | |||
| e62a0f76ed | |||
| 673447794e | |||
| 76aefccd03 | |||
| b0b9e398e1 | |||
| fac0491658 | |||
| 7770f082c8 | |||
| 3281049264 | |||
| fe48f6769f | |||
| 6a5be68367 | |||
| 6613366343 | |||
| 48c1aaaa38 | |||
| 23928e55a3 | |||
| 6d84b93715 | |||
| 5b1011668a | |||
| 30d2298d54 | |||
| 98b6f58eb2 | |||
| a0cbdc9135 | |||
| 805e03b83b | |||
| 35cc7da9b3 | |||
| 6efe6bbfc2 | |||
| ac29ef67fd | |||
| 4a7140c05d | |||
| cd971cff4f | |||
| 538139ef31 | |||
| 8bd4926c29 | |||
| a9195c8ff9 | |||
| 93c8a11824 | |||
| aec496a73b | |||
| 7bc1398574 | |||
| 3371bad504 | |||
| 64e27637dc | |||
| ee4f05a5b8 | |||
| 6636a2fda8 | |||
| 754936d253 | |||
| 3762f40538 | |||
| 4a3c45af2d | |||
| 29fdbc8f7f | |||
| 6116c6abb9 | |||
| 466c21e9fd | |||
| d461d6f8e8 | |||
| 53f68a3834 | |||
| 76d43782db | |||
| e7a6db8916 | |||
| cdb7fa83e4 | |||
| f785f9ff00 | |||
| 4d87d13165 | |||
| 9128011208 | |||
| 3dd7f7f17b | |||
| 7665d3d1f2 | |||
| e055feb1d3 | |||
| dfe6982099 | |||
| ad2aef09c4 | |||
| facfdfd85c | |||
| 1bba2a5f21 | |||
| ef239b8d0c | |||
| bccbac9f23 | |||
| 113efe129d | |||
| 8d73cccde5 | |||
| 055c56edfc | |||
| 942c1c1f5c | |||
| 243a91a141 | |||
| 281bd69fa5 | |||
| 6630259833 | |||
| 674d28622b | |||
| e21aedfb73 | |||
| 8f22c58875 | |||
| e3d1c4c9c7 | |||
| 40f87c9ab5 | |||
| bd5f02a8df | |||
| 91438affc8 | |||
| 1548fdfca6 | |||
| 4bebb20477 | |||
| 3fb4524c5a | |||
| cdd1273ed0 | |||
| 717f17a9b5 | |||
| 11763e8cd1 | |||
| 5e50348150 | |||
| ccfc690281 | |||
| e1f6702932 | |||
| 13e9f8a98e | |||
| cc0337585e | |||
| 3070e37335 | |||
| c50edafac6 | |||
| 7ccac492bb | |||
| 5b9102f9a8 | |||
| f447de4840 | |||
| 36eeac365e | |||
| 2b8c4942fd | |||
| 9fbc413d4d | |||
| ad96fa0f58 | |||
| f2283410ce | |||
| ceff757bc6 | |||
| 975ad26eb8 | |||
| a1a5cab04e | |||
| 8182947f29 | |||
| 2231ba3f04 | |||
| bf0a08f5a7 | |||
| 552575c7e6 | |||
| d0979d560f | |||
| 6931b81daa | |||
| 92405f94ec | |||
| 3e1daf50b0 | |||
| 0caeb6b5f7 | |||
| 85d235958e | |||
| 008f875282 | |||
| 8b42c2558a | |||
| 40f56e43cc | |||
| e9c961802b | |||
| 948b6e041d | |||
| 80d776af56 | |||
| e62d84e35d | |||
| 098a6551f6 | |||
| 6e15fd0da6 | |||
| 1f2dadc333 | |||
| c3b7a2b382 | |||
| 3746305b5a | |||
| af3f9d5a75 | |||
| 9207cf501c | |||
| fc1c3a8f97 | |||
| 83e56a09c2 | |||
| 47613b1cf9 | |||
| ef3a7d5c92 | |||
| 705d1e4cc0 | |||
| 5b3f348bbb | |||
| aa81c75bef | |||
| 6b889814ad | |||
| 1ade11f00b |
@@ -12,7 +12,7 @@ Have you searched for similar issues before posting it?
|
||||
If you have discovered a bug in the bot, please [search the issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue).
|
||||
If it hasn't been reported, please create a new issue.
|
||||
|
||||
Please do not use bug reports to request new features.
|
||||
Please do not use the bug report template to request new features.
|
||||
-->
|
||||
|
||||
## Describe your environment
|
||||
|
||||
@@ -8,9 +8,12 @@ assignees: ''
|
||||
---
|
||||
<!--
|
||||
Have you searched for similar issues before posting it?
|
||||
Did you have a VERY good look at the [documentation](https://www.freqtrade.io/en/latest/) and are sure that the question is not explained there
|
||||
Did you have a VERY good look at the [documentation](https://www.freqtrade.io/) and are sure that the question is not explained there
|
||||
|
||||
Please do not use the question template to report bugs or to request new features.
|
||||
|
||||
Has your strategy or configuration been generated by an AI model, and is now not working?
|
||||
Please consult the documentation. We'll close such issues and point to the documentation.
|
||||
-->
|
||||
|
||||
## Describe your environment
|
||||
@@ -22,4 +25,4 @@ Please do not use the question template to report bugs or to request new feature
|
||||
|
||||
## Your question
|
||||
|
||||
*Ask the question you have not been able to find an answer in the [Documentation](https://www.freqtrade.io/en/latest/)*
|
||||
*Ask the question you have not been able to find an answer in the [Documentation](https://www.freqtrade.io/)*
|
||||
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
run: python build_helpers/binance_update_lev_tiers.py
|
||||
|
||||
|
||||
- uses: peter-evans/create-pull-request@v7
|
||||
- uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
|
||||
with:
|
||||
token: ${{ secrets.REPO_SCOPED_TOKEN }}
|
||||
add-paths: freqtrade/exchange/binance_leverage_tiers.json
|
||||
|
||||
+25
-19
@@ -38,8 +38,9 @@ jobs:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
|
||||
with:
|
||||
activate-environment: true
|
||||
enable-cache: true
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache-dependency-glob: "requirements**.txt"
|
||||
@@ -73,17 +74,17 @@ jobs:
|
||||
python build_helpers/freqtrade_client_version_align.py
|
||||
|
||||
- name: Tests
|
||||
if: (!(runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-22.04'))
|
||||
if: (!(runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-24.04'))
|
||||
run: |
|
||||
pytest --random-order
|
||||
|
||||
- name: Tests with Coveralls
|
||||
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-22.04')
|
||||
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-24.04')
|
||||
run: |
|
||||
pytest --random-order --cov=freqtrade --cov=freqtrade_client --cov-config=.coveragerc
|
||||
|
||||
- name: Coveralls
|
||||
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-22.04')
|
||||
if: (runner.os == 'Linux' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-24.04')
|
||||
env:
|
||||
# Coveralls token. Not used as secret due to github not providing secrets to forked repositories
|
||||
COVERALLS_REPO_TOKEN: 6D1m0xupS3FgutfuGao8keFf9Hc0FpIXu
|
||||
@@ -139,11 +140,12 @@ jobs:
|
||||
ruff format --check
|
||||
|
||||
- name: Mypy
|
||||
if: matrix.os == 'ubuntu-24.04'
|
||||
run: |
|
||||
mypy freqtrade scripts tests
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||
with:
|
||||
severity: error
|
||||
@@ -169,8 +171,9 @@ jobs:
|
||||
check-latest: true
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
|
||||
with:
|
||||
activate-environment: true
|
||||
enable-cache: true
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache-dependency-glob: "requirements**.txt"
|
||||
@@ -264,11 +267,12 @@ jobs:
|
||||
ruff format --check
|
||||
|
||||
- name: Mypy
|
||||
if: matrix.os == 'macos-15'
|
||||
run: |
|
||||
mypy freqtrade scripts
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||
with:
|
||||
severity: info
|
||||
@@ -294,8 +298,9 @@ jobs:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
|
||||
with:
|
||||
activate-environment: true
|
||||
enable-cache: true
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache-dependency-glob: "requirements**.txt"
|
||||
@@ -361,7 +366,7 @@ jobs:
|
||||
shell: powershell
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||
with:
|
||||
severity: error
|
||||
@@ -395,7 +400,7 @@ jobs:
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- uses: pre-commit/action@v3.0.1
|
||||
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
|
||||
|
||||
docs-check:
|
||||
runs-on: ubuntu-22.04
|
||||
@@ -419,7 +424,7 @@ jobs:
|
||||
mkdocs build
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: failure() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||
with:
|
||||
severity: error
|
||||
@@ -441,8 +446,9 @@ jobs:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
|
||||
with:
|
||||
activate-environment: true
|
||||
enable-cache: true
|
||||
python-version: "3.12"
|
||||
cache-dependency-glob: "requirements**.txt"
|
||||
@@ -499,14 +505,14 @@ jobs:
|
||||
|
||||
- name: Check user permission
|
||||
id: check
|
||||
uses: scherermichael-oss/action-has-permission@1.0.6
|
||||
uses: scherermichael-oss/action-has-permission@136e061bfe093832d87f090dd768e14e27a740d3 # 1.0.6
|
||||
with:
|
||||
required-permission: write
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: always() && steps.check.outputs.has-permission && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
|
||||
with:
|
||||
severity: info
|
||||
@@ -578,7 +584,7 @@ jobs:
|
||||
merge-multiple: true
|
||||
|
||||
- name: Publish to PyPI (Test)
|
||||
uses: pypa/gh-action-pypi-publish@v1.12.4
|
||||
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
|
||||
with:
|
||||
repository-url: https://test.pypi.org/legacy/
|
||||
|
||||
@@ -607,7 +613,7 @@ jobs:
|
||||
merge-multiple: true
|
||||
|
||||
- name: Publish to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@v1.12.4
|
||||
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
|
||||
|
||||
|
||||
deploy-docker:
|
||||
@@ -648,11 +654,11 @@ jobs:
|
||||
docker version -f '{{.Server.Experimental}}'
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 #v3.10.0
|
||||
|
||||
- name: Available platforms
|
||||
run: echo ${PLATFORMS}
|
||||
@@ -701,7 +707,7 @@ jobs:
|
||||
build_helpers/publish_docker_arm64.sh
|
||||
|
||||
- name: Discord notification
|
||||
uses: rjstone/discord-webhook-notify@v1
|
||||
uses: rjstone/discord-webhook-notify@1399c1b2d57cc05894d506d2cfdc33c5f012b993 #v1.1.1
|
||||
if: always() && ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) && (github.event_name != 'schedule')
|
||||
with:
|
||||
severity: info
|
||||
|
||||
@@ -28,13 +28,13 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Pre-build dev container image
|
||||
uses: devcontainers/ci@v0.3
|
||||
uses: devcontainers/ci@8bf61b26e9c3a98f69cb6ce2f88d24ff59b785c6 # v0.3.19
|
||||
with:
|
||||
subFolder: .github
|
||||
imageName: ghcr.io/${{ github.repository }}-devcontainer
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
uses: peter-evans/dockerhub-description@432a30c9e07499fd01da9f8a49f0faf9e0ca5b77 # v4.0.2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
- name: Run auto-update
|
||||
run: pre-commit autoupdate
|
||||
|
||||
- uses: peter-evans/create-pull-request@v7
|
||||
- uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
|
||||
with:
|
||||
token: ${{ secrets.REPO_SCOPED_TOKEN }}
|
||||
add-paths: .pre-commit-config.yaml
|
||||
|
||||
+17
-5
@@ -1,8 +1,20 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
|
||||
- repo: local
|
||||
# Keep json schema in sync with the config schema
|
||||
# This will write the files - and fail pre-commit if a file has been changed.
|
||||
hooks:
|
||||
- id: Extract config json schema
|
||||
name: extract-config-json-schema
|
||||
entry: "python build_helpers/extract_config_json_schema.py"
|
||||
language: python
|
||||
pass_filenames: false
|
||||
additional_dependencies: ["python-rapidjson", "jsonschema"]
|
||||
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: "7.1.2"
|
||||
rev: "7.2.0"
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [Flake8-pyproject]
|
||||
@@ -16,10 +28,10 @@ repos:
|
||||
additional_dependencies:
|
||||
- types-cachetools==5.5.0.20240820
|
||||
- types-filelock==3.2.7
|
||||
- types-requests==2.32.0.20241016
|
||||
- types-requests==2.32.0.20250328
|
||||
- types-tabulate==0.9.0.20241207
|
||||
- types-python-dateutil==2.9.0.20241206
|
||||
- SQLAlchemy==2.0.38
|
||||
- SQLAlchemy==2.0.40
|
||||
# stages: [push]
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
@@ -31,7 +43,7 @@ repos:
|
||||
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: 'v0.9.7'
|
||||
rev: 'v0.11.7'
|
||||
hooks:
|
||||
- id: ruff
|
||||
- id: ruff-format
|
||||
@@ -70,6 +82,6 @@ repos:
|
||||
|
||||
# Ensure github actions remain safe
|
||||
- repo: https://github.com/woodruffw/zizmor-pre-commit
|
||||
rev: v1.4.1
|
||||
rev: v1.6.0
|
||||
hooks:
|
||||
- id: zizmor
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM python:3.12.9-slim-bookworm as base
|
||||
FROM python:3.12.10-slim-bookworm as base
|
||||
|
||||
# Setup env
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 
|
||||
|
||||
[](https://github.com/freqtrade/freqtrade/actions/)
|
||||
[](https://github.com/freqtrade/freqtrade/actions/)
|
||||
[](https://doi.org/10.21105/joss.04864)
|
||||
[](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
||||
[](https://www.freqtrade.io)
|
||||
|
||||
@@ -12,7 +12,12 @@ secret = os.environ.get("FREQTRADE__EXCHANGE__SECRET")
|
||||
proxy = os.environ.get("CI_WEB_PROXY")
|
||||
|
||||
exchange = ccxt.binance(
|
||||
{"apiKey": key, "secret": secret, "httpsProxy": proxy, "options": {"defaultType": "swap"}}
|
||||
{
|
||||
"apiKey": key,
|
||||
"secret": secret,
|
||||
"httpsProxy": proxy,
|
||||
"options": {"defaultType": "swap"},
|
||||
}
|
||||
)
|
||||
_ = exchange.load_markets()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import subprocess
|
||||
import subprocess # noqa: S404, RUF100
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,23 @@ from pathlib import Path
|
||||
|
||||
import rapidjson
|
||||
|
||||
from freqtrade.configuration.config_schema import CONF_SCHEMA
|
||||
|
||||
|
||||
def extract_config_json_schema():
|
||||
try:
|
||||
# Try to import from the installed package
|
||||
from freqtrade.config_schema import CONF_SCHEMA
|
||||
except ImportError:
|
||||
# If freqtrade is not installed, add the parent directory to sys.path
|
||||
# to import directly from the source
|
||||
import sys
|
||||
|
||||
script_dir = Path(__file__).parent
|
||||
freqtrade_dir = script_dir.parent
|
||||
sys.path.insert(0, str(freqtrade_dir))
|
||||
|
||||
# Now try to import from the source
|
||||
from freqtrade.config_schema import CONF_SCHEMA
|
||||
|
||||
schema_filename = Path(__file__).parent / "schema.json"
|
||||
with schema_filename.open("w") as f:
|
||||
rapidjson.dump(CONF_SCHEMA, f, indent=2)
|
||||
|
||||
BIN
Binary file not shown.
@@ -257,7 +257,8 @@
|
||||
"enum": [
|
||||
"day",
|
||||
"week",
|
||||
"month"
|
||||
"month",
|
||||
"year"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -541,6 +542,10 @@
|
||||
"description": "Edge configuration.",
|
||||
"$ref": "#/definitions/edge"
|
||||
},
|
||||
"log_config": {
|
||||
"description": "Logging configuration.",
|
||||
"$ref": "#/definitions/logging"
|
||||
},
|
||||
"freqai": {
|
||||
"description": "FreqAI configuration.",
|
||||
"$ref": "#/definitions/freqai"
|
||||
@@ -612,6 +617,14 @@
|
||||
"description": "Telegram topic ID - only applicable for group chats",
|
||||
"type": "string"
|
||||
},
|
||||
"authorized_users": {
|
||||
"description": "Authorized users for the bot.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"allow_custom_messages": {
|
||||
"description": "Allow sending custom messages from the Strategy.",
|
||||
"type": "boolean",
|
||||
@@ -1019,6 +1032,7 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"running",
|
||||
"paused",
|
||||
"stopped"
|
||||
]
|
||||
},
|
||||
@@ -1272,6 +1286,30 @@
|
||||
"allowed_risk"
|
||||
]
|
||||
},
|
||||
"logging": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": "number",
|
||||
"const": 1
|
||||
},
|
||||
"formatters": {
|
||||
"type": "object"
|
||||
},
|
||||
"handlers": {
|
||||
"type": "object"
|
||||
},
|
||||
"root": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"version",
|
||||
"formatters",
|
||||
"handlers",
|
||||
"root"
|
||||
]
|
||||
},
|
||||
"external_message_consumer": {
|
||||
"description": "Configuration for external message consumer.",
|
||||
"type": "object",
|
||||
@@ -1366,10 +1404,10 @@
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"keras": {
|
||||
"description": "Use Keras for model training.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
"identifier": {
|
||||
"description": "A unique ID for the current model. Must be changed when modifying features.",
|
||||
"type": "string",
|
||||
"default": "example"
|
||||
},
|
||||
"write_metrics_to_disk": {
|
||||
"description": "Write metrics to disk?",
|
||||
@@ -1399,16 +1437,49 @@
|
||||
"type": "number",
|
||||
"default": 7
|
||||
},
|
||||
"identifier": {
|
||||
"description": "A unique ID for the current model. Must be changed when modifying features.",
|
||||
"type": "string",
|
||||
"default": "example"
|
||||
"live_retrain_hours": {
|
||||
"description": "Frequency of retraining during dry/live runs.",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
},
|
||||
"expiration_hours": {
|
||||
"description": "Avoid making predictions if a model is more than `expiration_hours` old. Defaults to 0 (no expiration).",
|
||||
"type": "number",
|
||||
"default": 0
|
||||
},
|
||||
"save_backtest_models": {
|
||||
"description": "Save models to disk when running backtesting.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"fit_live_predictions_candles": {
|
||||
"description": "Number of historical candles to use for computing target (label) statistics from prediction data, instead of from the training dataset.",
|
||||
"type": "integer"
|
||||
},
|
||||
"data_kitchen_thread_count": {
|
||||
"description": "Designate the number of threads you want to use for data processing (outlier methods, normalization, etc.).",
|
||||
"type": "integer"
|
||||
},
|
||||
"activate_tensorboard": {
|
||||
"description": "Indicate whether or not to activate tensorboard",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"wait_for_training_iteration_on_reload": {
|
||||
"description": "Wait for the next training iteration to complete after /reload or ctrl+c.",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"continual_learning": {
|
||||
"description": "Use the final state of the most recently trained model as starting point for the new model, allowing for incremental learning.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"keras": {
|
||||
"description": "Use Keras for model training.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"feature_parameters": {
|
||||
"description": "The parameters used to engineer the feature set",
|
||||
"type": "object",
|
||||
@@ -1445,6 +1516,14 @@
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"indicator_periods_candles": {
|
||||
"description": "Time periods to calculate indicators for. The indicators are added to the base indicator dataset.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
"use_SVM_to_remove_outliers": {
|
||||
"description": "Use SVM to remove outliers from the features.",
|
||||
"type": "boolean",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM python:3.11.11-slim-bookworm as base
|
||||
FROM python:3.11.12-slim-bookworm as base
|
||||
|
||||
# Setup env
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
+201
-14
@@ -177,7 +177,7 @@ sudo loginctl enable-linger "$USER"
|
||||
If you run the bot as a service, you can use systemd service manager as a software watchdog monitoring freqtrade bot
|
||||
state and restarting it in the case of failures. If the `internals.sd_notify` parameter is set to true in the
|
||||
configuration or the `--sd-notify` command line option is used, the bot will send keep-alive ping messages to systemd
|
||||
using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running or Stopped)
|
||||
using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running, Paused or Stopped)
|
||||
when it changes.
|
||||
|
||||
The `freqtrade.service.watchdog` file contains an example of the service unit configuration file which uses systemd
|
||||
@@ -188,30 +188,113 @@ as the watchdog.
|
||||
|
||||
## Advanced Logging
|
||||
|
||||
Freqtrade uses the default logging module provided by python.
|
||||
Python allows for extensive [logging configuration](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig) in this regard - way more than what can be covered here.
|
||||
|
||||
Default logging format (coloured terminal output) is set up by default if no `log_config` is provided in your freqtrade configuration.
|
||||
Using `--logfile logfile.log` will enable the RotatingFileHandler.
|
||||
|
||||
If you're not content with the log format, or with the default settings provided for the RotatingFileHandler, you can customize logging to your liking by adding the `log_config` configuration to your freqtrade configuration file(s).
|
||||
|
||||
The default configuration looks roughly like the below, with the file handler being provided but not enabled as the `filename` is commented out.
|
||||
Uncomment this line and supply a valid path/filename to enable it.
|
||||
|
||||
``` json hl_lines="5-7 13-16 27"
|
||||
{
|
||||
"log_config": {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"basic": {
|
||||
"format": "%(message)s"
|
||||
},
|
||||
"standard": {
|
||||
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "freqtrade.loggers.ft_rich_handler.FtRichHandler",
|
||||
"formatter": "basic"
|
||||
},
|
||||
"file": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"formatter": "standard",
|
||||
// "filename": "someRandomLogFile.log",
|
||||
"maxBytes": 10485760,
|
||||
"backupCount": 10
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"handlers": [
|
||||
"console",
|
||||
// "file"
|
||||
],
|
||||
"level": "INFO",
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
!!! Note "highlighted lines"
|
||||
Highlighted lines in the above code-block define the Rich handler and belong together.
|
||||
The formatter "standard" and "file" will belong to the FileHandler.
|
||||
|
||||
Each handler must use one of the defined formatters (by name), its class must be available, and must be a valid logging class.
|
||||
To actually use a handler, it must be in the "handlers" section inside the "root" segment.
|
||||
If this section is left out, freqtrade will provide no output (in the non-configured handler, anyway).
|
||||
|
||||
!!! Tip "Explicit log configuration"
|
||||
We recommend to extract the logging configuration from your main freqtrade configuration file, and provide it to your bot via [multiple configuration files](configuration.md#multiple-configuration-files) functionality. This will avoid unnecessary code duplication.
|
||||
|
||||
---
|
||||
|
||||
On many Linux systems the bot can be configured to send its log messages to `syslog` or `journald` system services. Logging to a remote `syslog` server is also available on Windows. The special values for the `--logfile` command line option can be used for this.
|
||||
|
||||
### Logging to syslog
|
||||
|
||||
To send Freqtrade log messages to a local or remote `syslog` service use the `--logfile` command line option with the value in the following format:
|
||||
To send Freqtrade log messages to a local or remote `syslog` service use the `"log_config"` setup option to configure logging.
|
||||
|
||||
* `--logfile syslog:<syslog_address>` -- send log messages to `syslog` service using the `<syslog_address>` as the syslog address.
|
||||
``` json
|
||||
{
|
||||
// ...
|
||||
"log_config": {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"syslog_fmt": {
|
||||
"format": "%(name)s - %(levelname)s - %(message)s"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
// Other handlers?
|
||||
"syslog": {
|
||||
"class": "logging.handlers.SysLogHandler",
|
||||
"formatter": "syslog_fmt",
|
||||
// Use one of the other options above as address instead?
|
||||
"address": "/dev/log"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"handlers": [
|
||||
// other handlers
|
||||
"syslog",
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the `:` character.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
So, the following are the examples of possible usages:
|
||||
[Additional log-handlers](#advanced-logging) may need to be configured to for example also have log output in the console.
|
||||
|
||||
* `--logfile syslog:/dev/log` -- log to syslog (rsyslog) using the `/dev/log` socket, suitable for most systems.
|
||||
* `--logfile syslog` -- same as above, the shortcut for `/dev/log`.
|
||||
* `--logfile syslog:/var/run/syslog` -- log to syslog (rsyslog) using the `/var/run/syslog` socket. Use this on MacOS.
|
||||
* `--logfile syslog:localhost:514` -- log to local syslog using UDP socket, if it listens on port 514.
|
||||
* `--logfile syslog:<ip>:514` -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.
|
||||
#### Syslog usage
|
||||
|
||||
Log messages are send to `syslog` with the `user` facility. So you can see them with the following commands:
|
||||
|
||||
* `tail -f /var/log/user`, or
|
||||
* `tail -f /var/log/user`, or
|
||||
* install a comprehensive graphical viewer (for instance, 'Log File Viewer' for Ubuntu).
|
||||
|
||||
On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
|
||||
On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both syslog or journald can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
|
||||
|
||||
For `rsyslog` the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add
|
||||
|
||||
@@ -228,13 +311,69 @@ For `syslog` (`rsyslog`), the reduction mode can be switched on. This will reduc
|
||||
$RepeatedMsgReduction on
|
||||
```
|
||||
|
||||
#### Syslog addressing
|
||||
|
||||
The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the `:` character.
|
||||
|
||||
|
||||
So, the following are the examples of possible addresses:
|
||||
|
||||
* `"address": "/dev/log"` -- log to syslog (rsyslog) using the `/dev/log` socket, suitable for most systems.
|
||||
* `"address": "/var/run/syslog"` -- log to syslog (rsyslog) using the `/var/run/syslog` socket. Use this on MacOS.
|
||||
* `"address": "localhost:514"` -- log to local syslog using UDP socket, if it listens on port 514.
|
||||
* `"address": "<ip>:514"` -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.
|
||||
|
||||
|
||||
??? Info "Deprecated - configure syslog via command line"
|
||||
|
||||
`--logfile syslog:<syslog_address>` -- send log messages to `syslog` service using the `<syslog_address>` as the syslog address.
|
||||
|
||||
The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the `:` character.
|
||||
|
||||
So, the following are the examples of possible usages:
|
||||
|
||||
* `--logfile syslog:/dev/log` -- log to syslog (rsyslog) using the `/dev/log` socket, suitable for most systems.
|
||||
* `--logfile syslog` -- same as above, the shortcut for `/dev/log`.
|
||||
* `--logfile syslog:/var/run/syslog` -- log to syslog (rsyslog) using the `/var/run/syslog` socket. Use this on MacOS.
|
||||
* `--logfile syslog:localhost:514` -- log to local syslog using UDP socket, if it listens on port 514.
|
||||
* `--logfile syslog:<ip>:514` -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.
|
||||
|
||||
### Logging to journald
|
||||
|
||||
This needs the `cysystemd` python package installed as dependency (`pip install cysystemd`), which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.
|
||||
|
||||
To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:
|
||||
To send Freqtrade log messages to `journald` system service, add the following configuration snippet to your configuration.
|
||||
|
||||
* `--logfile journald` -- send log messages to `journald`.
|
||||
``` json
|
||||
{
|
||||
// ...
|
||||
"log_config": {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"journald_fmt": {
|
||||
"format": "%(name)s - %(levelname)s - %(message)s"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
// Other handlers?
|
||||
"journald": {
|
||||
"class": "cysystemd.journal.JournaldLogHandler",
|
||||
"formatter": "journald_fmt",
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"handlers": [
|
||||
// ..
|
||||
"journald",
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[Additional log-handlers](#advanced-logging) may need to be configured to for example also have log output in the console.
|
||||
|
||||
Log messages are send to `journald` with the `user` facility. So you can see them with the following commands:
|
||||
|
||||
@@ -244,3 +383,51 @@ Log messages are send to `journald` with the `user` facility. So you can see the
|
||||
There are many other options in the `journalctl` utility to filter the messages, see manual pages for this utility.
|
||||
|
||||
On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
|
||||
|
||||
??? Info "Deprecated - configure journald via command line"
|
||||
To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:
|
||||
|
||||
`--logfile journald` -- send log messages to `journald`.
|
||||
|
||||
### Log format as JSON
|
||||
|
||||
You can also configure the default output stream to use JSON format instead.
|
||||
The "fmt_dict" attribute defines the keys for the json output - as well as the [python logging LogRecord attributes](https://docs.python.org/3/library/logging.html#logrecord-attributes).
|
||||
|
||||
The below configuration will change the default output to JSON. The same formatter could however also be used in combination with the `RotatingFileHandler`.
|
||||
We recommend to keep one format in human readable form.
|
||||
|
||||
``` json
|
||||
{
|
||||
// ...
|
||||
"log_config": {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"json": {
|
||||
"()": "freqtrade.loggers.json_formatter.JsonFormatter",
|
||||
"fmt_dict": {
|
||||
"timestamp": "asctime",
|
||||
"level": "levelname",
|
||||
"logger": "name",
|
||||
"message": "message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
// Other handlers?
|
||||
"jsonStream": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "json"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"handlers": [
|
||||
// ..
|
||||
"jsonStream",
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -209,6 +209,7 @@ A backtesting result will look like that:
|
||||
| Sortino | 1.88 |
|
||||
| Sharpe | 2.97 |
|
||||
| Calmar | 6.29 |
|
||||
| SQN | 2.45 |
|
||||
| Profit factor | 1.11 |
|
||||
| Expectancy (Ratio) | -0.15 (-0.05) |
|
||||
| Avg. stake amount | 0.001 BTC |
|
||||
@@ -315,6 +316,7 @@ It contains some useful key metrics about performance of your strategy on backte
|
||||
| Sortino | 1.88 |
|
||||
| Sharpe | 2.97 |
|
||||
| Calmar | 6.29 |
|
||||
| SQN | 2.45 |
|
||||
| Profit factor | 1.11 |
|
||||
| Expectancy (Ratio) | -0.15 (-0.05) |
|
||||
| Avg. stake amount | 0.001 BTC |
|
||||
@@ -368,6 +370,7 @@ It contains some useful key metrics about performance of your strategy on backte
|
||||
- `Sortino`: Annualized Sortino ratio.
|
||||
- `Sharpe`: Annualized Sharpe ratio.
|
||||
- `Calmar`: Annualized Calmar ratio.
|
||||
- `SQN`: System Quality Number (SQN) - by Van Tharp.
|
||||
- `Profit factor`: profit / loss.
|
||||
- `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount.
|
||||
- `Total trade volume`: Volume generated on the exchange to reach the above profit.
|
||||
@@ -432,6 +435,20 @@ To save time, by default backtest will reuse a cached result from within the las
|
||||
To further analyze your backtest results, freqtrade will export the trades to file by default.
|
||||
You can then load the trades to perform further analysis as shown in the [data analysis](strategy_analysis_example.md#load-backtest-results-to-pandas-dataframe) backtesting section.
|
||||
|
||||
### Backtest output file
|
||||
|
||||
The output file freqtrade produces is a zip file containing the following files:
|
||||
|
||||
- The backtest report in json format
|
||||
- the market change data in feather format
|
||||
- a copy of the strategy file
|
||||
- a copy of the strategy parameters (if a parameter file was used)
|
||||
- a sanitized copy of the config file
|
||||
|
||||
This will ensure results are reproducible - under the assumption that the same data is available.
|
||||
|
||||
Only the strategy file and the config file are included in the zip file, eventual dependencies are not included.
|
||||
|
||||
## Assumptions made by backtesting
|
||||
|
||||
Since backtesting lacks some detailed information about what happens within a candle, it needs to take a few assumptions:
|
||||
|
||||
@@ -59,7 +59,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
usage: freqtrade backtesting-show [-h] [-v] [--no-color] [--logfile FILE] [-V]
|
||||
[-c PATH] [-d PATH] [--userdir PATH]
|
||||
[--export-filename PATH] [--show-pair-list]
|
||||
[--breakdown {day,week,month} [{day,week,month} ...]]
|
||||
[--breakdown {day,week,month,year} [{day,week,month,year} ...]]
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
@@ -11,8 +11,9 @@ options:
|
||||
`--export` to be set as well. Example: `--export-filen
|
||||
ame=user_data/backtest_results/backtest_today.json`
|
||||
--show-pair-list Show backtesting pairlist sorted by profit.
|
||||
--breakdown {day,week,month} [{day,week,month} ...]
|
||||
Show backtesting breakdown per [day, week, month].
|
||||
--breakdown {day,week,month,year} [{day,week,month,year} ...]
|
||||
Show backtesting breakdown per [day, week, month,
|
||||
year].
|
||||
|
||||
Common arguments:
|
||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||
@@ -29,7 +30,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ usage: freqtrade backtesting [-h] [-v] [--no-color] [--logfile FILE] [-V]
|
||||
[--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]
|
||||
[--export {none,trades,signals}]
|
||||
[--export-filename PATH]
|
||||
[--breakdown {day,week,month} [{day,week,month} ...]]
|
||||
[--breakdown {day,week,month,year} [{day,week,month,year} ...]]
|
||||
[--cache {none,day,week,month}]
|
||||
[--freqai-backtest-live-models]
|
||||
|
||||
@@ -65,8 +65,9 @@ options:
|
||||
Use this filename for backtest results.Requires
|
||||
`--export` to be set as well. Example: `--export-filen
|
||||
ame=user_data/backtest_results/backtest_today.json`
|
||||
--breakdown {day,week,month} [{day,week,month} ...]
|
||||
Show backtesting breakdown per [day, week, month].
|
||||
--breakdown {day,week,month,year} [{day,week,month,year} ...]
|
||||
Show backtesting breakdown per [day, week, month,
|
||||
year].
|
||||
--cache {none,day,week,month}
|
||||
Load a cached backtest result no older than specified
|
||||
age (default: day).
|
||||
@@ -88,7 +89,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -55,7 +55,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ usage: freqtrade hyperopt-show [-h] [-v] [--no-color] [--logfile FILE] [-V]
|
||||
[--profitable] [-n INT] [--print-json]
|
||||
[--hyperopt-filename FILENAME] [--no-header]
|
||||
[--disable-param-export]
|
||||
[--breakdown {day,week,month} [{day,week,month} ...]]
|
||||
[--breakdown {day,week,month,year} [{day,week,month,year} ...]]
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
@@ -18,8 +18,9 @@ options:
|
||||
--no-header Do not print epoch details header.
|
||||
--disable-param-export
|
||||
Disable automatic hyperopt parameter export.
|
||||
--breakdown {day,week,month} [{day,week,month} ...]
|
||||
Show backtesting breakdown per [day, week, month].
|
||||
--breakdown {day,week,month,year} [{day,week,month,year} ...]
|
||||
Show backtesting breakdown per [day, week, month,
|
||||
year].
|
||||
|
||||
Common arguments:
|
||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||
@@ -36,7 +37,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ options:
|
||||
SortinoHyperOptLoss, SortinoHyperOptLossDaily,
|
||||
CalmarHyperOptLoss, MaxDrawDownHyperOptLoss,
|
||||
MaxDrawDownRelativeHyperOptLoss,
|
||||
MaxDrawDownPerPairHyperOptLoss,
|
||||
ProfitDrawDownHyperOptLoss, MultiMetricHyperOptLoss
|
||||
--disable-param-export
|
||||
Disable automatic hyperopt parameter export.
|
||||
@@ -102,7 +103,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
```
|
||||
usage: freqtrade install-ui [-h] [--erase] [--ui-version UI_VERSION]
|
||||
usage: freqtrade install-ui [-h] [--erase] [--prerelease]
|
||||
[--ui-version UI_VERSION]
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
--erase Clean UI folder, don't download new version.
|
||||
--prerelease Install the latest pre-release version of FreqUI. This
|
||||
is not recommended for production use.
|
||||
--ui-version UI_VERSION
|
||||
Specify a specific version of FreqUI to install. Not
|
||||
specifying this installs the latest version.
|
||||
|
||||
@@ -41,7 +41,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -89,7 +89,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -30,7 +30,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ Common arguments:
|
||||
exists). Multiple --config options may be used. Can be
|
||||
set to `-` to read config from stdin.
|
||||
-d PATH, --datadir PATH, --data-dir PATH
|
||||
Path to directory with historical backtesting data.
|
||||
Path to the base directory of the exchange with
|
||||
historical backtesting data. To see futures data, use
|
||||
trading-mode additionally.
|
||||
--userdir PATH, --user-data-dir PATH
|
||||
Path to userdata directory.
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
||||
| `exit_pricing.use_order_book` | Enable exiting of open trades using [Order Book Exit](#exit-price-with-orderbook-enabled). <br> *Defaults to `true`.*<br> **Datatype:** Boolean
|
||||
| `exit_pricing.order_book_top` | Bot will use the top N rate in Order Book "price_side" to exit. I.e. a value of 2 will allow the bot to pick the 2nd ask rate in [Order Book Exit](#exit-price-with-orderbook-enabled)<br>*Defaults to `1`.* <br> **Datatype:** Positive Integer
|
||||
| `custom_price_max_distance_ratio` | Configure maximum distance ratio between current and custom entry or exit price. <br>*Defaults to `0.02` 2%).*<br> **Datatype:** Positive float
|
||||
| | **TODO**
|
||||
| | **Order/Signal handling**
|
||||
| `use_exit_signal` | Use exit signals produced by the strategy in addition to the `minimal_roi`. <br>Setting this to false disables the usage of `"exit_long"` and `"exit_short"` columns. Has no influence on other exit methods (Stoploss, ROI, callbacks). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `true`.* <br> **Datatype:** Boolean
|
||||
| `exit_profit_only` | Wait until the bot reaches `exit_profit_offset` before taking an exit decision. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||
| `exit_profit_offset` | Exit-signal is only active above this value. Only active in combination with `exit_profit_only=True`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0`.* <br> **Datatype:** Float (as ratio)
|
||||
@@ -266,7 +266,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
||||
| `bot_name` | Name of the bot. Passed via API to a client - can be shown to distinguish / name bots.<br> *Defaults to `freqtrade`*<br> **Datatype:** String
|
||||
| `external_message_consumer` | Enable [Producer/Consumer mode](producer-consumer.md) for more details. <br> **Datatype:** Dict
|
||||
| | **Other**
|
||||
| `initial_state` | Defines the initial application state. If set to stopped, then the bot has to be explicitly started via `/start` RPC command. <br>*Defaults to `stopped`.* <br> **Datatype:** Enum, either `stopped` or `running`
|
||||
| `initial_state` | Defines the initial application state. If set to stopped, then the bot has to be explicitly started via `/start` RPC command. <br>*Defaults to `stopped`.* <br> **Datatype:** Enum, either `running`, `paused` or `stopped`
|
||||
| `force_entry_enable` | Enables the RPC Commands to force a Trade entry. More information below. <br> **Datatype:** Boolean
|
||||
| `disable_dataframe_checks` | Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. [Strategy Override](#parameters-in-the-strategy).<br> *Defaults to `False`*. <br> **Datatype:** Boolean
|
||||
| `internals.process_throttle_secs` | Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second. <br>*Defaults to `5` seconds.* <br> **Datatype:** Positive Integer
|
||||
@@ -281,7 +281,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 in FreqAI). (Currently only affects FreqAI use-cases) <br> **Datatype:** Boolean. <br> Default: `False`.
|
||||
| `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
|
||||
|
||||
|
||||
@@ -88,3 +88,8 @@ Setting protections from the configuration via `"protections": [],` has been rem
|
||||
Using hdf5 as data storage has been deprecated in 2024.12 and was removed in 2025.1. We recommend switching to the feather data format.
|
||||
|
||||
Please use the [`convert-data` subcommand](data-download.md#sub-command-convert-data) to convert your existing data to one of the supported formats before updating.
|
||||
|
||||
## Configuring advanced logging via config
|
||||
|
||||
Configuring syslog and journald via `--logfile systemd` and `--logfile journald` respectively has been deprecated in 2025.3.
|
||||
Please use configuration based [log setup](advanced-setup.md#advanced-logging) instead.
|
||||
|
||||
@@ -363,6 +363,10 @@ 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.
|
||||
|
||||
### 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.
|
||||
|
||||
## All exchanges
|
||||
|
||||
Should you experience constant errors with Nonce (like `InvalidNonce`), it is best to regenerate the API keys. Resetting Nonce is difficult and it's usually easier to regenerate the API keys.
|
||||
|
||||
@@ -258,6 +258,8 @@ freqtrade trade --config config_examples/config_freqai.example.json --strategy F
|
||||
We do provide an explicit docker-compose file for this in `docker/docker-compose-freqai.yml` - which can be used via `docker compose -f docker/docker-compose-freqai.yml run ...` - or can be copied to replace the original docker file.
|
||||
This docker-compose file also contains a (disabled) section to enable GPU resources within docker containers. This obviously assumes the system has GPU resources available.
|
||||
|
||||
PyTorch dropped support for macOS x64 (intel based Apple devices) in version 2.3. Subsequently, freqtrade also dropped support for PyTorch on this platform.
|
||||
|
||||
### Structure
|
||||
|
||||
#### Model
|
||||
|
||||
@@ -471,6 +471,7 @@ Currently, the following loss functions are builtin:
|
||||
* `SortinoHyperOptLossDaily` - optimizes Sortino Ratio calculated on **daily** trade returns relative to **downside** standard deviation.
|
||||
* `MaxDrawDownHyperOptLoss` - Optimizes Maximum absolute drawdown.
|
||||
* `MaxDrawDownRelativeHyperOptLoss` - Optimizes both maximum absolute drawdown while also adjusting for maximum relative drawdown.
|
||||
* `MaxDrawDownPerPairHyperOptLoss` - Calculates the profit/drawdown ratio per pair and returns the worst result as objective, forcing hyperopt to optimize the parameters for all pairs in the pairlist. This way, we prevent one or more pairs with good results from inflating the metrics, while the pairs with poor results are not represented and therefore not optimized.
|
||||
* `CalmarHyperOptLoss` - Optimizes Calmar Ratio calculated on trade returns relative to max drawdown.
|
||||
* `ProfitDrawDownHyperOptLoss` - Optimizes by max Profit & min Drawdown objective. `DRAWDOWN_MULT` variable within the hyperoptloss file can be adjusted to be stricter or more flexible on drawdown purposes.
|
||||
* `MultiMetricHyperOptLoss` - Optimizes by several key metrics to achieve balanced performance. The primary focus is on maximizing Profit and minimizing Drawdown, while also considering additional metrics such as Profit Factor, Expectancy Ratio and Winrate. Moreover, it applies a penalty for epochs with a low number of trades, encouraging strategies with adequate trade frequency.
|
||||
|
||||
@@ -44,9 +44,24 @@ You may also use something like `.*DOWN/BTC` or `.*UP/BTC` to exclude leveraged
|
||||
|
||||
By default, the `StaticPairList` method is used, which uses a statically defined pair whitelist from the configuration. The pairlist also supports wildcards (in regex-style) - so `.*/BTC` will include all pairs with BTC as a stake.
|
||||
|
||||
It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklist`.
|
||||
It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklist`, which in the below example, will trade BTC/USDT and ETH/USDT - and will prevent BNB/USDT trading.
|
||||
|
||||
Both `pair_*list` parameters support regex - so values like `.*/USDT` would enable trading all pairs that are not in the blacklist.
|
||||
|
||||
```json
|
||||
"exchange": {
|
||||
"name": "...",
|
||||
// ...
|
||||
"pair_whitelist": [
|
||||
"BTC/USDT",
|
||||
"ETH/USDT",
|
||||
// ...
|
||||
],
|
||||
"pair_blacklist": [
|
||||
"BNB/USDT",
|
||||
// ...
|
||||
]
|
||||
},
|
||||
"pairlists": [
|
||||
{"method": "StaticPairList"}
|
||||
],
|
||||
|
||||
@@ -3,7 +3,7 @@ This section will highlight a few projects from members of the community.
|
||||
The projects below are for the most part not maintained by the freqtrade , therefore use your own caution before using them.
|
||||
|
||||
- [Example freqtrade strategies](https://github.com/freqtrade/freqtrade-strategies/)
|
||||
- [FrequentHippo - Grafana dashboard with dry/live runs and backtests](http://frequenthippo.ddns.net:3000/) (by hippocritical).
|
||||
- [FrequentHippo - Statistics of dry/live runs and backtests](http://frequenthippo.ddns.net) (by hippocritical).
|
||||
- [Online pairlist generator](https://remotepairlist.com/) (by Blood4rc).
|
||||
- [Freqtrade Backtesting Project](https://strat.ninja/) (by Blood4rc).
|
||||
- [Freqtrade analysis notebook](https://github.com/froggleston/freqtrade_analysis_notebook) (by Froggleston).
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
[](https://github.com/freqtrade/freqtrade/actions/)
|
||||
[](https://github.com/freqtrade/freqtrade/actions/)
|
||||
[](https://doi.org/10.21105/joss.04864)
|
||||
[](https://coveralls.io/github/freqtrade/freqtrade?branch=develop)
|
||||
[](https://codeclimate.com/github/freqtrade/freqtrade/maintainability)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
markdown==3.7
|
||||
markdown==3.8
|
||||
mkdocs==1.6.1
|
||||
mkdocs-material==9.6.5
|
||||
mkdocs-material==9.6.12
|
||||
mdx_truly_sane_lists==1.3
|
||||
pymdown-extensions==10.14.3
|
||||
jinja2==3.1.5
|
||||
pymdown-extensions==10.15
|
||||
jinja2==3.1.6
|
||||
mike==2.1.3
|
||||
|
||||
@@ -268,6 +268,9 @@ show_config
|
||||
start
|
||||
Start the bot if it's in the stopped state.
|
||||
|
||||
pause
|
||||
Pause the bot if it's in the running state. If triggered on stopped state will handle open positions.
|
||||
|
||||
stats
|
||||
Return the stats report (durations, sell-reasons).
|
||||
|
||||
@@ -302,6 +305,19 @@ trades
|
||||
:param limit: Limits trades to the X last trades. Max 500 trades.
|
||||
:param offset: Offset by this amount of trades.
|
||||
|
||||
list_open_trades_custom_data
|
||||
Return a dict containing open trades custom-datas
|
||||
|
||||
:param key: str, optional - Key of the custom-data
|
||||
:param limit: Limits trades to X trades.
|
||||
:param offset: Offset by this amount of trades.
|
||||
|
||||
list_custom_data
|
||||
Return a dict containing custom-datas of a specified trade
|
||||
|
||||
:param trade_id: int - ID of the trade
|
||||
:param key: str, optional - Key of the custom-data
|
||||
|
||||
version
|
||||
Return the version of the bot.
|
||||
|
||||
@@ -320,6 +336,7 @@ All endpoints in the below table need to be prefixed with the base URL of the AP
|
||||
|-----------|--------|--------------------------|
|
||||
| `/ping` | GET | Simple command testing the API Readiness - requires no authentication.
|
||||
| `/start` | POST | Starts the trader.
|
||||
| `/pause` | POST | Pause the trader. Gracefully handle open trades according to their rules. Do not enter new positions.
|
||||
| `/stop` | POST | Stops the trader.
|
||||
| `/stopbuy` | POST | Stops the trader from opening new trades. Gracefully closes open trades according to their rules.
|
||||
| `/reload_config` | POST | Reloads the configuration file.
|
||||
|
||||
@@ -165,18 +165,23 @@ If there is any significant difference, verify that your entry and exit signals
|
||||
|
||||
## Controlling or monitoring a running bot
|
||||
|
||||
Once your bot is running in dry or live mode, Freqtrade has five mechanisms to control or monitor a running bot:
|
||||
Once your bot is running in dry or live mode, Freqtrade has six mechanisms to control or monitor a running bot:
|
||||
|
||||
- **[FreqUI](freq-ui.md)**: The easiest to get started with, FreqUI is a web interface to see and control current activity of your bot.
|
||||
- **[Telegram](telegram-usage.md)**: On mobile devices, Telegram integration is available to get alerts about your bot activity and to control certain aspects.
|
||||
- **[FTUI](https://github.com/freqtrade/ftui)**: FTUI is a terminal (command line) interface to Freqtrade, and allows monitoring of a running bot only.
|
||||
- **[REST API](rest-api.md)**: The REST API allows programmers to develop their own tools to interact with a Freqtrade bot.
|
||||
- **[freqtrade-client](rest-api.md#consuming-the-api)**: A python implementation of the REST API, making it easy to make requests and consume bot responses from your python apps or the command line.
|
||||
- **[REST API endpoints](rest-api.md#available-endpoints)**: The REST API allows programmers to develop their own tools to interact with a Freqtrade bot.
|
||||
- **[Webhooks](webhook-config.md)**: Freqtrade can send information to other services, e.g. discord, by webhooks.
|
||||
|
||||
### Logs
|
||||
|
||||
Freqtrade generates extensive debugging logs to help you understand what's happening. Please familiarise yourself with the information and error messages you might see in your bot logs.
|
||||
|
||||
Logging by default occurs on standard out (the command line). If you want to write out to a file instead, many freqtrade commands, including the `trade` command, accept the `--logfile` option to write to a file.
|
||||
|
||||
Check the [FAQ](faq.md#how-do-i-search-the-bot-logs-for-something) for examples.
|
||||
|
||||
## Final Thoughts
|
||||
|
||||
Algo trading is difficult, and most public strategies are not good performers due to the time and effort to make a strategy work profitably in multiple scenarios.
|
||||
|
||||
@@ -758,7 +758,7 @@ For performance reasons, it's disabled by default and freqtrade will show a warn
|
||||
|
||||
Additional orders also result in additional fees and those orders don't count towards `max_open_trades`.
|
||||
|
||||
This callback is also called when there is an open order (either buy or sell) waiting for execution - and will cancel the existing open order to place a new order if the amount, price or direction is different.
|
||||
This callback is also called when there is an open order (either buy or sell) waiting for execution - and will cancel the existing open order to place a new order if the amount, price or direction is different. Also partially filled orders will be canceled, and will be replaced with the new amount as returned by the callback.
|
||||
|
||||
`adjust_trade_position()` is called very frequently for the duration of a trade, so you must keep your implementation as performant as possible.
|
||||
|
||||
@@ -770,9 +770,10 @@ Modifications to leverage are not possible, and the stake-amount returned is ass
|
||||
The combined stake currently allocated to the position is held in `trade.stake_amount`. Therefore `trade.stake_amount` will always be updated on every additional entry and partial exit made through `adjust_trade_position()`.
|
||||
|
||||
!!! Danger "Loose Logic"
|
||||
On dry and live run, this function will be called every `throttle_process_secs` (default to 5s). If you have a loose logic, for example your logic for extra entry is only to check RSI of last candle is below 30, then when such condition fulfilled, your bot will do extra re-entry every 5 secs until either it run out of money, it hit the `max_position_adjustment` limit, or a new candle with RSI more than 30 arrived.
|
||||
On dry and live run, this function will be called every `throttle_process_secs` (default to 5s). If you have a loose logic, (e.g. increase position if RSI of the last candle is below 30), your bot will do extra re-entry every 5 secs until you either it run out of money, hit the `max_position_adjustment` limit, or a new candle with RSI more than 30 arrived.
|
||||
|
||||
Same thing also can happen with partial exit. So be sure to have a strict logic and/or check for the last filled order.
|
||||
Same thing also can happen with partial exit.
|
||||
So be sure to have a strict logic and/or check for the last filled order and if an order is already open.
|
||||
|
||||
!!! Warning "Performance with many position adjustments"
|
||||
Position adjustments can be a good approach to increase a strategy's output - but it can also have drawbacks if using this feature extensively.
|
||||
@@ -876,6 +877,9 @@ class DigDeeperStrategy(IStrategy):
|
||||
Return None for no action.
|
||||
Optionally, return a tuple with a 2nd element with an order reason
|
||||
"""
|
||||
if trade.has_open_orders:
|
||||
# Only act if no orders are open
|
||||
return
|
||||
|
||||
if current_profit > 0.05 and trade.nr_of_successful_exits == 0:
|
||||
# Take half of the profit at +5%
|
||||
@@ -973,7 +977,7 @@ class AwesomeStrategy(IStrategy):
|
||||
side: str,
|
||||
is_entry: bool,
|
||||
**kwargs,
|
||||
) -> float:
|
||||
) -> float | None:
|
||||
"""
|
||||
Exit and entry order price re-adjustment logic, returning the user desired limit price.
|
||||
This only executes when a order was already placed, still open (unfilled fully or partially)
|
||||
@@ -995,7 +999,7 @@ class AwesomeStrategy(IStrategy):
|
||||
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
||||
:param is_entry: True if the order is an entry order, False if it's an exit order.
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
:return float: New entry price value if provided
|
||||
:return float or None: New entry price value if provided
|
||||
"""
|
||||
|
||||
# Limit entry orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.
|
||||
|
||||
@@ -1122,6 +1122,7 @@ The following list contains some common patterns which should be avoided to prev
|
||||
- don't use `.iloc[-1]` or any other absolute position in the dataframe within `populate_` functions, as this will be different between dry-run and backtesting. Absolute `iloc` indexing is safe to use in callbacks however - see [Strategy Callbacks](strategy-callbacks.md).
|
||||
- don't use functions that use all dataframe or column values, e.g. `dataframe['mean_volume'] = dataframe['volume'].mean()`. As backtesting uses the full dataframe, at any point in the dataframe, the `'mean_volume'` series would include data from the future. Use rolling() calculations instead, e.g. `dataframe['volume'].rolling(<window>).mean()`.
|
||||
- don't use `.resample('1h')`. This uses the left border of the period interval, so moves data from an hour boundary to the start of the hour. Use `.resample('1h', label='right')` instead.
|
||||
- don't use `.merge()` to combine longer timeframes onto shorter ones. Instead, use the [informative pair](#informative-pairs) helpers. (A plain merge can implicitly cause a lookahead bias as date refers to open date, not close date).
|
||||
|
||||
!!! Tip "Identifying problems"
|
||||
You should always use the two helper commands [lookahead-analysis](lookahead-analysis.md) and [recursive-analysis](recursive-analysis.md), which can each help you figure out problems with your strategy in different ways.
|
||||
|
||||
+31
-16
@@ -81,6 +81,19 @@ Without this, the bot will always respond to the general channel in the group if
|
||||
|
||||
Similar to the group-id - you can use `/tg_info` from the topic/thread to get the correct topic-id.
|
||||
|
||||
#### Authorized users
|
||||
|
||||
For groups, it can be useful to limit who can send commands to the bot.
|
||||
|
||||
If `"authorized_users": []` is present and empty, no user will be allowed to control the bot.
|
||||
In the below example, only the user with the id "1234567" is allowed to control the bot - all other users will only be able to receive messages.
|
||||
|
||||
```json
|
||||
"chat_id": "-1001332619709",
|
||||
"topic_id": "3",
|
||||
"authorized_users": ["1234567"]
|
||||
```
|
||||
|
||||
## Control telegram noise
|
||||
|
||||
Freqtrade provides means to control the verbosity of your telegram bot.
|
||||
@@ -175,7 +188,7 @@ You can create your own keyboard in `config.json`:
|
||||
!!! Note "Supported Commands"
|
||||
Only the following commands are allowed. Command arguments are not supported!
|
||||
|
||||
`/start`, `/stop`, `/status`, `/status table`, `/trades`, `/profit`, `/performance`, `/daily`, `/stats`, `/count`, `/locks`, `/balance`, `/stopentry`, `/reload_config`, `/show_config`, `/logs`, `/whitelist`, `/blacklist`, `/edge`, `/help`, `/version`, `/marketdir`
|
||||
`/start`, `/pause`, `/stop`, `/status`, `/status table`, `/trades`, `/profit`, `/performance`, `/daily`, `/stats`, `/count`, `/locks`, `/balance`, `/stopentry`, `/reload_config`, `/show_config`, `/logs`, `/whitelist`, `/blacklist`, `/edge`, `/help`, `/version`, `/marketdir`
|
||||
|
||||
## Telegram commands
|
||||
|
||||
@@ -187,8 +200,8 @@ official commands. You can ask at any moment for help with `/help`.
|
||||
|----------|-------------|
|
||||
| **System commands**
|
||||
| `/start` | Starts the trader
|
||||
| `/pause | /stopentry | /stopbuy` | Pause the trader. Gracefully handle open trades according to their rules. Do not enter new positions.
|
||||
| `/stop` | Stops the trader
|
||||
| `/stopbuy | /stopentry` | Stops the trader from opening new trades. Gracefully closes open trades according to their rules.
|
||||
| `/reload_config` | Reloads the configuration file
|
||||
| `/show_config` | Shows part of the current configuration with relevant settings to operation
|
||||
| `/logs [limit]` | Show last log messages.
|
||||
@@ -237,25 +250,27 @@ Below, example of Telegram message you will receive for each command.
|
||||
|
||||
> **Status:** `running`
|
||||
|
||||
### /pause | /stopentry | /stopbuy
|
||||
|
||||
> **Status:** `paused, no more entries will occur from now. Run /start to enable entries.`
|
||||
|
||||
Prevents the bot from opening new trades by changing the state to `paused`.
|
||||
Open trades will continue to be managed according to their regular rules (ROI/exit signals, stop-loss, etc.).
|
||||
Note that position adjustment remains active, but only on the exit side — meaning that when the bot is `paused`, it can only reduce the position size of open trades.
|
||||
|
||||
After this, give the bot time to close off open trades (can be checked via `/status table`).
|
||||
Once all positions are closed, run `/stop` to completely stop the bot.
|
||||
|
||||
Use `/start` to resume the bot to the `running` state, allowing it to open new positions.
|
||||
|
||||
!!! Warning
|
||||
The pause/stopentry signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset.
|
||||
|
||||
### /stop
|
||||
|
||||
> `Stopping trader ...`
|
||||
> **Status:** `stopped`
|
||||
|
||||
### /stopbuy
|
||||
|
||||
> **status:** `Setting max_open_trades to 0. Run /reload_config to reset.`
|
||||
|
||||
Prevents the bot from opening new trades by temporarily setting "max_open_trades" to 0. Open trades will be handled via their regular rules (ROI / Sell-signal, stoploss, ...).
|
||||
|
||||
After this, give the bot time to close off open trades (can be checked via `/status table`).
|
||||
Once all positions are sold, run `/stop` to completely stop the bot.
|
||||
|
||||
`/reload_config` resets "max_open_trades" to the value set in the configuration and resets this command.
|
||||
|
||||
!!! Warning
|
||||
The stop-buy signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset.
|
||||
|
||||
### /status
|
||||
|
||||
For each open trade, the bot will send you the following message.
|
||||
|
||||
@@ -25,6 +25,7 @@ The following attributes / properties are available for each individual trade -
|
||||
| `close_date_utc` | datetime | Timestamp when trade was closed - in UTC. |
|
||||
| `close_profit` | float | Relative profit at the time of trade closure. `0.01` == 1% |
|
||||
| `close_profit_abs` | float | Absolute profit (in stake currency) at the time of trade closure. |
|
||||
| `realized_profit` | float | Absolute already realized profit (in stake currency) while the trade is still open. |
|
||||
| `leverage` | float | Leverage used for this trade - defaults to 1.0 in spot markets. |
|
||||
| `enter_tag` | string | Tag provided on entry via the `enter_tag` column in the dataframe. |
|
||||
| `is_short` | boolean | True for short trades, False otherwise. |
|
||||
@@ -35,6 +36,7 @@ The following attributes / properties are available for each individual trade -
|
||||
| `trade_direction` | "long" / "short" | Trade direction in text - long or short. |
|
||||
| `nr_of_successful_entries` | int | Number of successful (filled) entry orders. |
|
||||
| `nr_of_successful_exits` | int | Number of successful (filled) exit orders. |
|
||||
| `has_open_orders` | boolean | Has the trade open orders (excluding stoploss orders). |
|
||||
|
||||
## Class methods
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
"""Freqtrade bot"""
|
||||
|
||||
__version__ = "2025.2"
|
||||
__version__ = "2025.4"
|
||||
|
||||
if "dev" in __version__:
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import subprocess # noqa: S404
|
||||
import subprocess # noqa: S404, RUF100
|
||||
|
||||
freqtrade_basedir = Path(__file__).parent
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ ARGS_COMMON = [
|
||||
"user_data_dir",
|
||||
]
|
||||
|
||||
ARGS_MAIN = ["version_main"]
|
||||
|
||||
ARGS_STRATEGY = [
|
||||
"strategy",
|
||||
"strategy_path",
|
||||
@@ -43,7 +45,8 @@ ARGS_COMMON_OPTIMIZE = [
|
||||
"pairs",
|
||||
]
|
||||
|
||||
ARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + [
|
||||
ARGS_BACKTEST = [
|
||||
*ARGS_COMMON_OPTIMIZE,
|
||||
"position_stacking",
|
||||
"enable_protections",
|
||||
"dry_run_wallet",
|
||||
@@ -56,7 +59,8 @@ ARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + [
|
||||
"freqai_backtest_live_models",
|
||||
]
|
||||
|
||||
ARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + [
|
||||
ARGS_HYPEROPT = [
|
||||
*ARGS_COMMON_OPTIMIZE,
|
||||
"hyperopt",
|
||||
"hyperopt_path",
|
||||
"position_stacking",
|
||||
@@ -76,7 +80,7 @@ ARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + [
|
||||
"analyze_per_epoch",
|
||||
]
|
||||
|
||||
ARGS_EDGE = ARGS_COMMON_OPTIMIZE + ["stoploss_range"]
|
||||
ARGS_EDGE = [*ARGS_COMMON_OPTIMIZE, "stoploss_range"]
|
||||
|
||||
ARGS_LIST_STRATEGIES = [
|
||||
"strategy_path",
|
||||
@@ -125,7 +129,7 @@ ARGS_BUILD_STRATEGY = ["user_data_dir", "strategy", "strategy_path", "template"]
|
||||
|
||||
ARGS_CONVERT_DATA_TRADES = ["pairs", "format_from_trades", "format_to", "erase", "exchange"]
|
||||
ARGS_CONVERT_DATA = ["pairs", "format_from", "format_to", "erase", "exchange"]
|
||||
ARGS_CONVERT_DATA_OHLCV = ARGS_CONVERT_DATA + ["timeframes", "trading_mode", "candle_types"]
|
||||
ARGS_CONVERT_DATA_OHLCV = [*ARGS_CONVERT_DATA, "timeframes", "trading_mode", "candle_types"]
|
||||
|
||||
ARGS_CONVERT_TRADES = [
|
||||
"pairs",
|
||||
@@ -191,7 +195,7 @@ ARGS_PLOT_PROFIT = [
|
||||
|
||||
ARGS_CONVERT_DB = ["db_url", "db_url_from"]
|
||||
|
||||
ARGS_INSTALL_UI = ["erase_ui_only", "ui_version"]
|
||||
ARGS_INSTALL_UI = ["erase_ui_only", "ui_prerelease", "ui_version"]
|
||||
|
||||
ARGS_SHOW_TRADES = ["db_url", "trade_ids", "print_json"]
|
||||
|
||||
@@ -347,7 +351,7 @@ class Arguments:
|
||||
self.parser = ArgumentParser(
|
||||
prog="freqtrade", description="Free, open source crypto trading bot"
|
||||
)
|
||||
self._build_args(optionlist=["version_main"], parser=self.parser)
|
||||
self._build_args(optionlist=ARGS_MAIN, parser=self.parser)
|
||||
|
||||
from freqtrade.commands import (
|
||||
start_analysis_entries_exits,
|
||||
|
||||
@@ -83,7 +83,8 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
"-d",
|
||||
"--datadir",
|
||||
"--data-dir",
|
||||
help="Path to directory with historical backtesting data.",
|
||||
help="Path to the base directory of the exchange with historical backtesting data. "
|
||||
"To see futures data, use trading-mode additionally.",
|
||||
metavar="PATH",
|
||||
),
|
||||
"user_data_dir": Arg(
|
||||
@@ -224,7 +225,7 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
),
|
||||
"backtest_breakdown": Arg(
|
||||
"--breakdown",
|
||||
help="Show backtesting breakdown per [day, week, month].",
|
||||
help="Show backtesting breakdown per [day, week, month, year].",
|
||||
nargs="+",
|
||||
choices=constants.BACKTEST_BREAKDOWNS,
|
||||
),
|
||||
@@ -463,7 +464,7 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
"format_from_trades": Arg(
|
||||
"--format-from",
|
||||
help="Source format for data conversion.",
|
||||
choices=constants.AVAILABLE_DATAHANDLERS + ["kraken_csv"],
|
||||
choices=[*constants.AVAILABLE_DATAHANDLERS, "kraken_csv"],
|
||||
required=True,
|
||||
),
|
||||
"format_from": Arg(
|
||||
@@ -527,6 +528,15 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
),
|
||||
type=str,
|
||||
),
|
||||
"ui_prerelease": Arg(
|
||||
"--prerelease",
|
||||
help=(
|
||||
"Install the latest pre-release version of FreqUI. "
|
||||
"This is not recommended for production use."
|
||||
),
|
||||
action="store_true",
|
||||
default=False,
|
||||
),
|
||||
# Templating options
|
||||
"template": Arg(
|
||||
"--template",
|
||||
|
||||
@@ -23,8 +23,8 @@ def start_create_userdir(args: dict[str, Any]) -> None:
|
||||
"""
|
||||
from freqtrade.configuration.directory_operations import copy_sample_files, create_userdata_dir
|
||||
|
||||
if "user_data_dir" in args and args["user_data_dir"]:
|
||||
userdir = create_userdata_dir(args["user_data_dir"], create_dir=True)
|
||||
if user_data_dir := args.get("user_data_dir"):
|
||||
userdir = create_userdata_dir(user_data_dir, create_dir=True)
|
||||
copy_sample_files(userdir, overwrite=args["reset"])
|
||||
else:
|
||||
logger.warning("`create-userdir` requires --userdir to be set.")
|
||||
@@ -85,22 +85,22 @@ def start_new_strategy(args: dict[str, Any]) -> None:
|
||||
|
||||
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
||||
|
||||
if "strategy" in args and args["strategy"]:
|
||||
if "strategy_path" in args and args["strategy_path"]:
|
||||
strategy_dir = Path(args["strategy_path"])
|
||||
if strategy := args.get("strategy"):
|
||||
if strategy_path := args.get("strategy_path"):
|
||||
strategy_dir = Path(strategy_path)
|
||||
else:
|
||||
strategy_dir = config["user_data_dir"] / USERPATH_STRATEGIES
|
||||
if not strategy_dir.is_dir():
|
||||
logger.info(f"Creating strategy directory {strategy_dir}")
|
||||
strategy_dir.mkdir(parents=True)
|
||||
new_path = strategy_dir / (args["strategy"] + ".py")
|
||||
new_path = strategy_dir / (strategy + ".py")
|
||||
|
||||
if new_path.exists():
|
||||
raise OperationalException(
|
||||
f"`{new_path}` already exists. Please choose another Strategy Name."
|
||||
)
|
||||
|
||||
deploy_new_strategy(args["strategy"], new_path, args["template"])
|
||||
deploy_new_strategy(strategy, new_path, args["template"])
|
||||
|
||||
else:
|
||||
raise ConfigurationError("`new-strategy` requires --strategy to be set.")
|
||||
@@ -116,7 +116,9 @@ def start_install_ui(args: dict[str, Any]) -> None:
|
||||
|
||||
dest_folder = Path(__file__).parents[1] / "rpc/api_server/ui/installed/"
|
||||
# First make sure the assets are removed.
|
||||
dl_url, latest_version = get_ui_download_url(args.get("ui_version"))
|
||||
dl_url, latest_version = get_ui_download_url(
|
||||
args.get("ui_version"), args.get("ui_prerelease", False)
|
||||
)
|
||||
|
||||
curr_version = read_ui_version(dest_folder)
|
||||
if curr_version == latest_version and not args.get("erase_ui_only"):
|
||||
|
||||
@@ -51,7 +51,7 @@ def download_and_install_ui(dest_folder: Path, dl_url: str, version: str):
|
||||
f.write(version)
|
||||
|
||||
|
||||
def get_ui_download_url(version: str | None = None) -> tuple[str, str]:
|
||||
def get_ui_download_url(version: str | None, prerelease: bool) -> tuple[str, str]:
|
||||
base_url = "https://api.github.com/repos/freqtrade/frequi/"
|
||||
# Get base UI Repo path
|
||||
|
||||
@@ -61,14 +61,18 @@ def get_ui_download_url(version: str | None = None) -> tuple[str, str]:
|
||||
|
||||
if version:
|
||||
tmp = [x for x in r if x["name"] == version]
|
||||
if tmp:
|
||||
latest_version = tmp[0]["name"]
|
||||
assets = tmp[0].get("assets", [])
|
||||
else:
|
||||
raise ValueError("UI-Version not found.")
|
||||
else:
|
||||
latest_version = r[0]["name"]
|
||||
assets = r[0].get("assets", [])
|
||||
tmp = [x for x in r if prerelease or not x.get("prerelease")]
|
||||
|
||||
if tmp:
|
||||
# Ensure we have the latest version
|
||||
if version is None:
|
||||
tmp.sort(key=lambda x: x["created_at"], reverse=True)
|
||||
latest_version = tmp[0]["name"]
|
||||
assets = tmp[0].get("assets", [])
|
||||
else:
|
||||
raise ValueError("UI-Version not found.")
|
||||
|
||||
dl_url = ""
|
||||
if assets and len(assets) > 0:
|
||||
dl_url = assets[0]["browser_download_url"]
|
||||
|
||||
@@ -5,7 +5,6 @@ from typing import Any
|
||||
|
||||
from freqtrade.enums import RunMode
|
||||
from freqtrade.exceptions import ConfigurationError, OperationalException
|
||||
from freqtrade.ft_types import ValidExchangesType
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -17,11 +16,12 @@ def start_list_exchanges(args: dict[str, Any]) -> None:
|
||||
:param args: Cli args from Arguments()
|
||||
:return: None
|
||||
"""
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich.text import Text
|
||||
|
||||
from freqtrade.exchange import list_available_exchanges
|
||||
from freqtrade.ft_types import ValidExchangesType
|
||||
from freqtrade.loggers.rich_console import get_rich_console
|
||||
|
||||
available_exchanges: list[ValidExchangesType] = list_available_exchanges(
|
||||
args["list_exchanges_all"]
|
||||
@@ -77,15 +77,16 @@ def start_list_exchanges(args: dict[str, Any]) -> None:
|
||||
)
|
||||
# table.add_row(*[exchange[header] for header in headers])
|
||||
|
||||
console = Console()
|
||||
console = get_rich_console()
|
||||
console.print(table)
|
||||
|
||||
|
||||
def _print_objs_tabular(objs: list, print_colorized: bool) -> None:
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich.text import Text
|
||||
|
||||
from freqtrade.loggers.rich_console import get_rich_console
|
||||
|
||||
names = [s["name"] for s in objs]
|
||||
objs_to_print: list[dict[str, Text | str]] = [
|
||||
{
|
||||
@@ -118,10 +119,7 @@ def _print_objs_tabular(objs: list, print_colorized: bool) -> None:
|
||||
for row in objs_to_print:
|
||||
table.add_row(*[row[header] for header in objs_to_print[0].keys()])
|
||||
|
||||
console = Console(
|
||||
color_system="auto" if print_colorized else None,
|
||||
width=200 if "pytest" in sys.modules else None,
|
||||
)
|
||||
console = get_rich_console(color_system="auto" if print_colorized else None)
|
||||
console.print(table)
|
||||
|
||||
|
||||
@@ -219,7 +217,7 @@ def start_list_markets(args: dict[str, Any], pairs_only: bool = False) -> None:
|
||||
"""
|
||||
from freqtrade.configuration import setup_utils_configuration
|
||||
from freqtrade.exchange import market_is_active
|
||||
from freqtrade.misc import plural
|
||||
from freqtrade.misc import plural, safe_value_fallback
|
||||
from freqtrade.resolvers import ExchangeResolver
|
||||
from freqtrade.util import print_rich_table
|
||||
|
||||
@@ -246,88 +244,99 @@ def start_list_markets(args: dict[str, Any], pairs_only: bool = False) -> None:
|
||||
except Exception as e:
|
||||
raise OperationalException(f"Cannot get markets. Reason: {e}") from e
|
||||
|
||||
else:
|
||||
summary_str = (
|
||||
(f"Exchange {exchange.name} has {len(pairs)} ")
|
||||
+ ("active " if active_only else "")
|
||||
+ (plural(len(pairs), "pair" if pairs_only else "market"))
|
||||
+ (
|
||||
f" with {', '.join(base_currencies)} as base "
|
||||
f"{plural(len(base_currencies), 'currency', 'currencies')}"
|
||||
if base_currencies
|
||||
else ""
|
||||
)
|
||||
+ (" and" if base_currencies and quote_currencies else "")
|
||||
+ (
|
||||
f" with {', '.join(quote_currencies)} as quote "
|
||||
f"{plural(len(quote_currencies), 'currency', 'currencies')}"
|
||||
if quote_currencies
|
||||
else ""
|
||||
)
|
||||
tickers = exchange.get_tickers()
|
||||
|
||||
summary_str = (
|
||||
(f"Exchange {exchange.name} has {len(pairs)} ")
|
||||
+ ("active " if active_only else "")
|
||||
+ (plural(len(pairs), "pair" if pairs_only else "market"))
|
||||
+ (
|
||||
f" with {', '.join(base_currencies)} as base "
|
||||
f"{plural(len(base_currencies), 'currency', 'currencies')}"
|
||||
if base_currencies
|
||||
else ""
|
||||
)
|
||||
+ (" and" if base_currencies and quote_currencies else "")
|
||||
+ (
|
||||
f" with {', '.join(quote_currencies)} as quote "
|
||||
f"{plural(len(quote_currencies), 'currency', 'currencies')}"
|
||||
if quote_currencies
|
||||
else ""
|
||||
)
|
||||
)
|
||||
|
||||
headers = [
|
||||
"Id",
|
||||
"Symbol",
|
||||
"Base",
|
||||
"Quote",
|
||||
"Active",
|
||||
"Spot",
|
||||
"Margin",
|
||||
"Future",
|
||||
"Leverage",
|
||||
]
|
||||
headers = [
|
||||
"Id",
|
||||
"Symbol",
|
||||
"Base",
|
||||
"Quote",
|
||||
"Active",
|
||||
"Spot",
|
||||
"Margin",
|
||||
"Future",
|
||||
"Leverage",
|
||||
"Min Stake",
|
||||
]
|
||||
|
||||
tabular_data = [
|
||||
{
|
||||
"Id": v["id"],
|
||||
"Symbol": v["symbol"],
|
||||
"Base": v["base"],
|
||||
"Quote": v["quote"],
|
||||
"Active": market_is_active(v),
|
||||
"Spot": "Spot" if exchange.market_is_spot(v) else "",
|
||||
"Margin": "Margin" if exchange.market_is_margin(v) else "",
|
||||
"Future": "Future" if exchange.market_is_future(v) else "",
|
||||
"Leverage": exchange.get_max_leverage(v["symbol"], 20),
|
||||
}
|
||||
for _, v in pairs.items()
|
||||
]
|
||||
tabular_data = [
|
||||
{
|
||||
"Id": v["id"],
|
||||
"Symbol": v["symbol"],
|
||||
"Base": v["base"],
|
||||
"Quote": v["quote"],
|
||||
"Active": market_is_active(v),
|
||||
"Spot": "Spot" if exchange.market_is_spot(v) else "",
|
||||
"Margin": "Margin" if exchange.market_is_margin(v) else "",
|
||||
"Future": "Future" if exchange.market_is_future(v) else "",
|
||||
"Leverage": exchange.get_max_leverage(v["symbol"], 20),
|
||||
"Min Stake": round(
|
||||
exchange.get_min_pair_stake_amount(
|
||||
v["symbol"],
|
||||
safe_value_fallback(tickers.get(v["symbol"], {}), "last", "ask", 0.0),
|
||||
0.0,
|
||||
)
|
||||
or 0.0,
|
||||
8,
|
||||
),
|
||||
}
|
||||
for _, v in pairs.items()
|
||||
]
|
||||
|
||||
if (
|
||||
args.get("print_one_column", False)
|
||||
or args.get("list_pairs_print_json", False)
|
||||
or args.get("print_csv", False)
|
||||
):
|
||||
# Print summary string in the log in case of machine-readable
|
||||
# regular formats.
|
||||
logger.info(f"{summary_str}.")
|
||||
if (
|
||||
args.get("print_one_column", False)
|
||||
or args.get("list_pairs_print_json", False)
|
||||
or args.get("print_csv", False)
|
||||
):
|
||||
# Print summary string in the log in case of machine-readable
|
||||
# regular formats.
|
||||
logger.info(f"{summary_str}.")
|
||||
else:
|
||||
# Print empty string separating leading logs and output in case of
|
||||
# human-readable formats.
|
||||
print()
|
||||
|
||||
if pairs:
|
||||
if args.get("print_list", False):
|
||||
# print data as a list, with human-readable summary
|
||||
print(f"{summary_str}: {', '.join(pairs.keys())}.")
|
||||
elif args.get("print_one_column", False):
|
||||
print("\n".join(pairs.keys()))
|
||||
elif args.get("list_pairs_print_json", False):
|
||||
import rapidjson
|
||||
|
||||
print(rapidjson.dumps(list(pairs.keys()), default=str))
|
||||
elif args.get("print_csv", False):
|
||||
writer = csv.DictWriter(sys.stdout, fieldnames=headers)
|
||||
writer.writeheader()
|
||||
writer.writerows(tabular_data)
|
||||
else:
|
||||
# Print empty string separating leading logs and output in case of
|
||||
# human-readable formats.
|
||||
print()
|
||||
|
||||
if pairs:
|
||||
if args.get("print_list", False):
|
||||
# print data as a list, with human-readable summary
|
||||
print(f"{summary_str}: {', '.join(pairs.keys())}.")
|
||||
elif args.get("print_one_column", False):
|
||||
print("\n".join(pairs.keys()))
|
||||
elif args.get("list_pairs_print_json", False):
|
||||
import rapidjson
|
||||
|
||||
print(rapidjson.dumps(list(pairs.keys()), default=str))
|
||||
elif args.get("print_csv", False):
|
||||
writer = csv.DictWriter(sys.stdout, fieldnames=headers)
|
||||
writer.writeheader()
|
||||
writer.writerows(tabular_data)
|
||||
else:
|
||||
print_rich_table(tabular_data, headers, summary_str)
|
||||
elif not (
|
||||
args.get("print_one_column", False)
|
||||
or args.get("list_pairs_print_json", False)
|
||||
or args.get("print_csv", False)
|
||||
):
|
||||
print(f"{summary_str}.")
|
||||
print_rich_table(tabular_data, headers, summary_str)
|
||||
elif not (
|
||||
args.get("print_one_column", False)
|
||||
or args.get("list_pairs_print_json", False)
|
||||
or args.get("print_csv", False)
|
||||
):
|
||||
print(f"{summary_str}.")
|
||||
|
||||
|
||||
def start_show_trades(args: dict[str, Any]) -> None:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from freqtrade.config_schema.config_schema import CONF_SCHEMA
|
||||
|
||||
|
||||
__all__ = ["CONF_SCHEMA"]
|
||||
+99
-14
@@ -425,6 +425,10 @@ CONF_SCHEMA = {
|
||||
"description": "Edge configuration.",
|
||||
"$ref": "#/definitions/edge",
|
||||
},
|
||||
"log_config": {
|
||||
"description": "Logging configuration.",
|
||||
"$ref": "#/definitions/logging",
|
||||
},
|
||||
"freqai": {
|
||||
"description": "FreqAI configuration.",
|
||||
"$ref": "#/definitions/freqai",
|
||||
@@ -471,6 +475,12 @@ CONF_SCHEMA = {
|
||||
"description": "Telegram topic ID - only applicable for group chats",
|
||||
"type": "string",
|
||||
},
|
||||
"authorized_users": {
|
||||
"description": "Authorized users for the bot.",
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"uniqueItems": True,
|
||||
},
|
||||
"allow_custom_messages": {
|
||||
"description": "Allow sending custom messages from the Strategy.",
|
||||
"type": "boolean",
|
||||
@@ -679,7 +689,7 @@ CONF_SCHEMA = {
|
||||
"initial_state": {
|
||||
"description": "Initial state of the system.",
|
||||
"type": "string",
|
||||
"enum": ["running", "stopped"],
|
||||
"enum": ["running", "paused", "stopped"],
|
||||
},
|
||||
"force_entry_enable": {
|
||||
"description": "Force enable entry.",
|
||||
@@ -877,6 +887,28 @@ CONF_SCHEMA = {
|
||||
},
|
||||
"required": ["process_throttle_secs", "allowed_risk"],
|
||||
},
|
||||
"logging": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {"type": "number", "const": 1},
|
||||
"formatters": {
|
||||
"type": "object",
|
||||
# In theory the below, but can be more flexible
|
||||
# based on logging.config documentation
|
||||
# "additionalProperties": {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "format": {"type": "string"},
|
||||
# "datefmt": {"type": "string"},
|
||||
# },
|
||||
# "required": ["format"],
|
||||
# },
|
||||
},
|
||||
"handlers": {"type": "object"},
|
||||
"root": {"type": "object"},
|
||||
},
|
||||
"required": ["version", "formatters", "handlers", "root"],
|
||||
},
|
||||
"external_message_consumer": {
|
||||
"description": "Configuration for external message consumer.",
|
||||
"type": "object",
|
||||
@@ -965,10 +997,13 @@ CONF_SCHEMA = {
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"keras": {
|
||||
"description": "Use Keras for model training.",
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
"identifier": {
|
||||
"description": (
|
||||
"A unique ID for the current model. "
|
||||
"Must be changed when modifying features."
|
||||
),
|
||||
"type": "string",
|
||||
"default": "example",
|
||||
},
|
||||
"write_metrics_to_disk": {
|
||||
"description": "Write metrics to disk?",
|
||||
@@ -1000,13 +1035,42 @@ CONF_SCHEMA = {
|
||||
"type": "number",
|
||||
"default": 7,
|
||||
},
|
||||
"identifier": {
|
||||
"live_retrain_hours": {
|
||||
"description": "Frequency of retraining during dry/live runs.",
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
},
|
||||
"expiration_hours": {
|
||||
"description": (
|
||||
"A unique ID for the current model. "
|
||||
"Must be changed when modifying features."
|
||||
"Avoid making predictions if a model is more than `expiration_hours` "
|
||||
"old. Defaults to 0 (no expiration)."
|
||||
),
|
||||
"type": "string",
|
||||
"default": "example",
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
},
|
||||
"save_backtest_models": {
|
||||
"description": "Save models to disk when running backtesting.",
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"fit_live_predictions_candles": {
|
||||
"description": (
|
||||
"Number of historical candles to use for computing target (label) "
|
||||
"statistics from prediction data, instead of from the training dataset."
|
||||
),
|
||||
"type": "integer",
|
||||
},
|
||||
"data_kitchen_thread_count": {
|
||||
"description": (
|
||||
"Designate the number of threads you want to use for data processing "
|
||||
"(outlier methods, normalization, etc.)."
|
||||
),
|
||||
"type": "integer",
|
||||
},
|
||||
"activate_tensorboard": {
|
||||
"description": "Indicate whether or not to activate tensorboard",
|
||||
"type": "boolean",
|
||||
"default": True,
|
||||
},
|
||||
"wait_for_training_iteration_on_reload": {
|
||||
"description": (
|
||||
@@ -1015,6 +1079,20 @@ CONF_SCHEMA = {
|
||||
"type": "boolean",
|
||||
"default": True,
|
||||
},
|
||||
"continual_learning": {
|
||||
"description": (
|
||||
"Use the final state of the most recently trained model "
|
||||
"as starting point for the new model, allowing for "
|
||||
"incremental learning."
|
||||
),
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"keras": {
|
||||
"description": "Use Keras for model training.",
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"feature_parameters": {
|
||||
"description": "The parameters used to engineer the feature set",
|
||||
"type": "object",
|
||||
@@ -1068,6 +1146,14 @@ CONF_SCHEMA = {
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"indicator_periods_candles": {
|
||||
"description": (
|
||||
"Time periods to calculate indicators for. "
|
||||
"The indicators are added to the base indicator dataset."
|
||||
),
|
||||
"type": "array",
|
||||
"items": {"type": "number", "minimum": 1},
|
||||
},
|
||||
"use_SVM_to_remove_outliers": {
|
||||
"description": "Use SVM to remove outliers from the features.",
|
||||
"type": "boolean",
|
||||
@@ -1260,7 +1346,8 @@ SCHEMA_BACKTEST_REQUIRED = [
|
||||
"dataformat_ohlcv",
|
||||
"dataformat_trades",
|
||||
]
|
||||
SCHEMA_BACKTEST_REQUIRED_FINAL = SCHEMA_BACKTEST_REQUIRED + [
|
||||
SCHEMA_BACKTEST_REQUIRED_FINAL = [
|
||||
*SCHEMA_BACKTEST_REQUIRED,
|
||||
"stoploss",
|
||||
"minimal_roi",
|
||||
"max_open_trades",
|
||||
@@ -1272,6 +1359,4 @@ SCHEMA_MINIMAL_REQUIRED = [
|
||||
"dataformat_ohlcv",
|
||||
"dataformat_trades",
|
||||
]
|
||||
SCHEMA_MINIMAL_WEBSERVER = SCHEMA_MINIMAL_REQUIRED + [
|
||||
"api_server",
|
||||
]
|
||||
SCHEMA_MINIMAL_WEBSERVER = [*SCHEMA_MINIMAL_REQUIRED, "api_server"]
|
||||
@@ -6,7 +6,7 @@ from typing import Any
|
||||
from jsonschema import Draft4Validator, validators
|
||||
from jsonschema.exceptions import ValidationError, best_match
|
||||
|
||||
from freqtrade.configuration.config_schema import (
|
||||
from freqtrade.config_schema.config_schema import (
|
||||
CONF_SCHEMA,
|
||||
SCHEMA_BACKTEST_REQUIRED,
|
||||
SCHEMA_BACKTEST_REQUIRED_FINAL,
|
||||
@@ -361,7 +361,7 @@ def _validate_freqai_include_timeframes(conf: dict[str, Any], preliminary: bool)
|
||||
# Ensure that the base timeframe is included in the include_timeframes list
|
||||
if not preliminary and main_tf not in freqai_include_timeframes:
|
||||
feature_parameters = conf.get("freqai", {}).get("feature_parameters", {})
|
||||
include_timeframes = [main_tf] + freqai_include_timeframes
|
||||
include_timeframes = [main_tf, *freqai_include_timeframes]
|
||||
conf.get("freqai", {}).get("feature_parameters", {}).update(
|
||||
{**feature_parameters, "include_timeframes": include_timeframes}
|
||||
)
|
||||
|
||||
@@ -135,7 +135,7 @@ class Configuration:
|
||||
{"verbosity": safe_value_fallback(self.args, "verbosity", default_value=0)}
|
||||
)
|
||||
|
||||
if "logfile" in self.args and self.args["logfile"]:
|
||||
if self.args.get("logfile"):
|
||||
config.update({"logfile": self.args["logfile"]})
|
||||
|
||||
if "print_colorized" in self.args and not self.args["print_colorized"]:
|
||||
@@ -187,7 +187,7 @@ class Configuration:
|
||||
logger.warning("`force_entry_enable` RPC message enabled.")
|
||||
|
||||
# Support for sd_notify
|
||||
if "sd_notify" in self.args and self.args["sd_notify"]:
|
||||
if self.args.get("sd_notify"):
|
||||
config["internals"].update({"sd_notify": True})
|
||||
|
||||
def _process_datadir_options(self, config: Config) -> None:
|
||||
@@ -196,14 +196,14 @@ class Configuration:
|
||||
--user-data, --datadir
|
||||
"""
|
||||
# Check exchange parameter here - otherwise `datadir` might be wrong.
|
||||
if "exchange" in self.args and self.args["exchange"]:
|
||||
if self.args.get("exchange"):
|
||||
config["exchange"]["name"] = self.args["exchange"]
|
||||
logger.info(f"Using exchange {config['exchange']['name']}")
|
||||
|
||||
if "pair_whitelist" not in config["exchange"]:
|
||||
config["exchange"]["pair_whitelist"] = []
|
||||
|
||||
if "user_data_dir" in self.args and self.args["user_data_dir"]:
|
||||
if self.args.get("user_data_dir"):
|
||||
config.update({"user_data_dir": self.args["user_data_dir"]})
|
||||
elif "user_data_dir" not in config:
|
||||
# Default to cwd/user_data (legacy option ...)
|
||||
@@ -251,7 +251,7 @@ class Configuration:
|
||||
logstring="Parameter --enable-protections detected, enabling Protections. ...",
|
||||
)
|
||||
|
||||
if "max_open_trades" in self.args and self.args["max_open_trades"]:
|
||||
if self.args.get("max_open_trades"):
|
||||
config.update({"max_open_trades": self.args["max_open_trades"]})
|
||||
logger.info(
|
||||
"Parameter --max-open-trades detected, overriding max_open_trades to: %s ...",
|
||||
@@ -314,7 +314,7 @@ class Configuration:
|
||||
self._args_to_config_loop(config, configurations)
|
||||
|
||||
# Edge section:
|
||||
if "stoploss_range" in self.args and self.args["stoploss_range"]:
|
||||
if self.args.get("stoploss_range"):
|
||||
txt_range = ast.literal_eval(self.args["stoploss_range"])
|
||||
config["edge"].update({"stoploss_range_min": txt_range[0]})
|
||||
config["edge"].update({"stoploss_range_max": txt_range[1]})
|
||||
@@ -493,7 +493,7 @@ class Configuration:
|
||||
config["exchange"]["pair_whitelist"] = config["pairs"]
|
||||
return
|
||||
|
||||
if "pairs_file" in self.args and self.args["pairs_file"]:
|
||||
if self.args.get("pairs_file"):
|
||||
pairs_file = Path(self.args["pairs_file"])
|
||||
logger.info(f'Reading pairs file "{pairs_file}".')
|
||||
# Download pairs from the pairs file if no config is specified
|
||||
@@ -505,7 +505,7 @@ class Configuration:
|
||||
config["pairs"].sort()
|
||||
return
|
||||
|
||||
if "config" in self.args and self.args["config"]:
|
||||
if self.args.get("config"):
|
||||
logger.info("Using pairlist from configuration.")
|
||||
config["pairs"] = config.get("exchange", {}).get("pair_whitelist")
|
||||
else:
|
||||
|
||||
@@ -37,7 +37,7 @@ def chown_user_directory(directory: Path) -> None:
|
||||
"""
|
||||
if running_in_docker():
|
||||
try:
|
||||
import subprocess # noqa: S404
|
||||
import subprocess # noqa: S404, RUF100
|
||||
|
||||
subprocess.check_output(["sudo", "chown", "-R", "ftuser:", str(directory.resolve())])
|
||||
except Exception:
|
||||
|
||||
@@ -37,6 +37,7 @@ HYPEROPT_LOSS_BUILTIN = [
|
||||
"CalmarHyperOptLoss",
|
||||
"MaxDrawDownHyperOptLoss",
|
||||
"MaxDrawDownRelativeHyperOptLoss",
|
||||
"MaxDrawDownPerPairHyperOptLoss",
|
||||
"ProfitDrawDownHyperOptLoss",
|
||||
"MultiMetricHyperOptLoss",
|
||||
]
|
||||
@@ -59,7 +60,7 @@ AVAILABLE_PAIRLISTS = [
|
||||
"VolatilityFilter",
|
||||
]
|
||||
AVAILABLE_DATAHANDLERS = ["json", "jsongz", "feather", "parquet"]
|
||||
BACKTEST_BREAKDOWNS = ["day", "week", "month"]
|
||||
BACKTEST_BREAKDOWNS = ["day", "week", "month", "year"]
|
||||
BACKTEST_CACHE_AGE = ["none", "day", "week", "month"]
|
||||
BACKTEST_CACHE_DEFAULT = "day"
|
||||
DRY_RUN_WALLET = 1000
|
||||
@@ -99,7 +100,7 @@ DL_DATA_TIMEFRAMES = ["1m", "5m"]
|
||||
ENV_VAR_PREFIX = "FREQTRADE__"
|
||||
|
||||
CANCELED_EXCHANGE_STATES = ("cancelled", "canceled", "expired", "rejected")
|
||||
NON_OPEN_EXCHANGE_STATES = CANCELED_EXCHANGE_STATES + ("closed",)
|
||||
NON_OPEN_EXCHANGE_STATES = (*CANCELED_EXCHANGE_STATES, "closed")
|
||||
|
||||
# Define decimals per coin for outputs
|
||||
# Only used for outputs.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# flake8: noqa: F401
|
||||
from .bt_fileutils import (
|
||||
BT_DATA_COLUMNS,
|
||||
delete_backtest_result,
|
||||
extract_trades_of_period,
|
||||
find_existing_backtest_stats,
|
||||
get_backtest_market_change,
|
||||
get_backtest_result,
|
||||
get_backtest_resultlist,
|
||||
get_latest_backtest_filename,
|
||||
get_latest_hyperopt_file,
|
||||
get_latest_hyperopt_filename,
|
||||
get_latest_optimize_filename,
|
||||
load_and_merge_backtest_result,
|
||||
load_backtest_analysis_data,
|
||||
load_backtest_data,
|
||||
load_backtest_metadata,
|
||||
load_backtest_stats,
|
||||
load_exit_signal_candles,
|
||||
load_file_from_zip,
|
||||
load_rejected_signals,
|
||||
load_signal_candles,
|
||||
load_trades,
|
||||
load_trades_from_db,
|
||||
trade_list_to_dataframe,
|
||||
update_backtest_metadata,
|
||||
)
|
||||
from .trade_parallelism import (
|
||||
analyze_trade_parallelism,
|
||||
evaluate_result_multi,
|
||||
)
|
||||
@@ -13,7 +13,7 @@ from typing import Any, Literal
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from freqtrade.constants import LAST_BT_RESULT_FN, IntOrInf
|
||||
from freqtrade.constants import LAST_BT_RESULT_FN
|
||||
from freqtrade.exceptions import ConfigurationError, OperationalException
|
||||
from freqtrade.ft_types import BacktestHistoryEntryType, BacktestResultType
|
||||
from freqtrade.misc import file_dump_json, json_load
|
||||
@@ -376,7 +376,7 @@ def load_backtest_data(filename: Path | str, strategy: str | None = None) -> pd.
|
||||
|
||||
if not strategy:
|
||||
if len(data["strategy"]) == 1:
|
||||
strategy = list(data["strategy"].keys())[0]
|
||||
strategy = next(iter(data["strategy"].keys()))
|
||||
else:
|
||||
raise ValueError(
|
||||
"Detected backtest result with more than one strategy. "
|
||||
@@ -491,55 +491,6 @@ def load_exit_signal_candles(backtest_dir: Path) -> dict[str, dict[str, pd.DataF
|
||||
return load_backtest_analysis_data(backtest_dir, "exited")
|
||||
|
||||
|
||||
def analyze_trade_parallelism(results: pd.DataFrame, timeframe: str) -> pd.DataFrame:
|
||||
"""
|
||||
Find overlapping trades by expanding each trade once per period it was open
|
||||
and then counting overlaps.
|
||||
:param results: Results Dataframe - can be loaded
|
||||
:param timeframe: Timeframe used for backtest
|
||||
:return: dataframe with open-counts per time-period in timeframe
|
||||
"""
|
||||
from freqtrade.exchange import timeframe_to_resample_freq
|
||||
|
||||
timeframe_freq = timeframe_to_resample_freq(timeframe)
|
||||
dates = [
|
||||
pd.Series(
|
||||
pd.date_range(
|
||||
row[1]["open_date"],
|
||||
row[1]["close_date"],
|
||||
freq=timeframe_freq,
|
||||
# Exclude right boundary - the date is the candle open date.
|
||||
inclusive="left",
|
||||
)
|
||||
)
|
||||
for row in results[["open_date", "close_date"]].iterrows()
|
||||
]
|
||||
deltas = [len(x) for x in dates]
|
||||
dates = pd.Series(pd.concat(dates).values, name="date")
|
||||
df2 = pd.DataFrame(np.repeat(results.values, deltas, axis=0), columns=results.columns)
|
||||
|
||||
df2 = pd.concat([dates, df2], axis=1)
|
||||
df2 = df2.set_index("date")
|
||||
df_final = df2.resample(timeframe_freq)[["pair"]].count()
|
||||
df_final = df_final.rename({"pair": "open_trades"}, axis=1)
|
||||
return df_final
|
||||
|
||||
|
||||
def evaluate_result_multi(
|
||||
results: pd.DataFrame, timeframe: str, max_open_trades: IntOrInf
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
Find overlapping trades by expanding each trade once per period it was open
|
||||
and then counting overlaps
|
||||
:param results: Results Dataframe - can be loaded
|
||||
:param timeframe: Frequency used for the backtest
|
||||
:param max_open_trades: parameter max_open_trades used during backtest run
|
||||
:return: dataframe with open-counts per time-period in freq
|
||||
"""
|
||||
df_final = analyze_trade_parallelism(results, timeframe)
|
||||
return df_final[df_final["open_trades"] > max_open_trades]
|
||||
|
||||
|
||||
def trade_list_to_dataframe(trades: list[Trade] | list[LocalTrade]) -> pd.DataFrame:
|
||||
"""
|
||||
Convert list of Trade objects to pandas Dataframe
|
||||
@@ -0,0 +1,60 @@
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from freqtrade.constants import IntOrInf
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def analyze_trade_parallelism(trades: pd.DataFrame, timeframe: str) -> pd.DataFrame:
|
||||
"""
|
||||
Find overlapping trades by expanding each trade once per period it was open
|
||||
and then counting overlaps.
|
||||
:param trades: Trades Dataframe - can be loaded from backtest, or created
|
||||
via trade_list_to_dataframe
|
||||
:param timeframe: Timeframe used for backtest
|
||||
:return: dataframe with open-counts per time-period in timeframe
|
||||
"""
|
||||
from freqtrade.exchange import timeframe_to_resample_freq
|
||||
|
||||
timeframe_freq = timeframe_to_resample_freq(timeframe)
|
||||
dates = [
|
||||
pd.Series(
|
||||
pd.date_range(
|
||||
row[1]["open_date"],
|
||||
row[1]["close_date"],
|
||||
freq=timeframe_freq,
|
||||
# Exclude right boundary - the date is the candle open date.
|
||||
inclusive="left",
|
||||
)
|
||||
)
|
||||
for row in trades[["open_date", "close_date"]].iterrows()
|
||||
]
|
||||
deltas = [len(x) for x in dates]
|
||||
dates = pd.Series(pd.concat(dates).values, name="date")
|
||||
df2 = pd.DataFrame(np.repeat(trades.values, deltas, axis=0), columns=trades.columns)
|
||||
|
||||
df2 = pd.concat([dates, df2], axis=1)
|
||||
df2 = df2.set_index("date")
|
||||
df_final = df2.resample(timeframe_freq)[["pair"]].count()
|
||||
df_final = df_final.rename({"pair": "open_trades"}, axis=1)
|
||||
return df_final
|
||||
|
||||
|
||||
def evaluate_result_multi(
|
||||
trades: pd.DataFrame, timeframe: str, max_open_trades: IntOrInf
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
Find overlapping trades by expanding each trade once per period it was open
|
||||
and then counting overlaps
|
||||
:param trades: Trades Dataframe - can be loaded from backtest, or created
|
||||
via trade_list_to_dataframe
|
||||
:param timeframe: Frequency used for the backtest
|
||||
:param max_open_trades: parameter max_open_trades used during backtest run
|
||||
:return: dataframe with open-counts per time-period in freq
|
||||
"""
|
||||
df_final = analyze_trade_parallelism(trades, timeframe)
|
||||
return df_final[df_final["open_trades"] > max_open_trades]
|
||||
@@ -49,7 +49,7 @@ class DataProvider:
|
||||
self._pairlists = pairlists
|
||||
self.__rpc = rpc
|
||||
self.__cached_pairs: dict[PairWithTimeframe, tuple[DataFrame, datetime]] = {}
|
||||
self.__slice_index: int | None = None
|
||||
self.__slice_index: dict[str, int] = {}
|
||||
self.__slice_date: datetime | None = None
|
||||
|
||||
self.__cached_pairs_backtesting: dict[PairWithTimeframe, DataFrame] = {}
|
||||
@@ -69,13 +69,13 @@ class DataProvider:
|
||||
self.producers = self._config.get("external_message_consumer", {}).get("producers", [])
|
||||
self.external_data_enabled = len(self.producers) > 0
|
||||
|
||||
def _set_dataframe_max_index(self, limit_index: int):
|
||||
def _set_dataframe_max_index(self, pair: str, limit_index: int):
|
||||
"""
|
||||
Limit analyzed dataframe to max specified index.
|
||||
Only relevant in backtesting.
|
||||
:param limit_index: dataframe index.
|
||||
"""
|
||||
self.__slice_index = limit_index
|
||||
self.__slice_index[pair] = limit_index
|
||||
|
||||
def _set_dataframe_max_date(self, limit_date: datetime):
|
||||
"""
|
||||
@@ -393,9 +393,10 @@ class DataProvider:
|
||||
df, date = self.__cached_pairs[pair_key]
|
||||
else:
|
||||
df, date = self.__cached_pairs[pair_key]
|
||||
if self.__slice_index is not None:
|
||||
max_index = self.__slice_index
|
||||
if (max_index := self.__slice_index.get(pair)) is not None:
|
||||
df = df.iloc[max(0, max_index - MAX_DATAFRAME_CANDLES) : max_index]
|
||||
else:
|
||||
return (DataFrame(), datetime.fromtimestamp(0, tz=timezone.utc))
|
||||
return df, date
|
||||
else:
|
||||
return (DataFrame(), datetime.fromtimestamp(0, tz=timezone.utc))
|
||||
@@ -430,7 +431,7 @@ class DataProvider:
|
||||
# Don't reset backtesting pairs -
|
||||
# otherwise they're reloaded each time during hyperopt due to with analyze_per_epoch
|
||||
# self.__cached_pairs_backtesting = {}
|
||||
self.__slice_index = 0
|
||||
self.__slice_index = {}
|
||||
|
||||
# Exchange functions
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ def _merge_dfs(
|
||||
):
|
||||
merge_on = ["pair", "open_date"]
|
||||
signal_wide_indicators = list(set(available_inds) - set(BT_DATA_COLUMNS))
|
||||
columns_to_keep = merge_on + ["enter_reason", "exit_reason"]
|
||||
columns_to_keep = [*merge_on, "enter_reason", "exit_reason"]
|
||||
|
||||
if exit_df is None or exit_df.empty or entry_only is True:
|
||||
return entry_df[columns_to_keep + available_inds]
|
||||
|
||||
@@ -116,7 +116,7 @@ def load_data(
|
||||
result[pair] = hist
|
||||
else:
|
||||
if candle_type is CandleType.FUNDING_RATE and user_futures_funding_rate is not None:
|
||||
logger.warn(f"{pair} using user specified [{user_futures_funding_rate}]")
|
||||
logger.warning(f"{pair} using user specified [{user_futures_funding_rate}]")
|
||||
elif candle_type not in (CandleType.SPOT, CandleType.FUTURES):
|
||||
result[pair] = DataFrame(columns=["date", "open", "close", "high", "low", "volume"])
|
||||
|
||||
|
||||
+49
-10
@@ -10,7 +10,9 @@ import pandas as pd
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def calculate_market_change(data: dict[str, pd.DataFrame], column: str = "close") -> float:
|
||||
def calculate_market_change(
|
||||
data: dict[str, pd.DataFrame], column: str = "close", min_date: datetime | None = None
|
||||
) -> float:
|
||||
"""
|
||||
Calculate market change based on "column".
|
||||
Calculation is done by taking the first non-null and the last non-null element of each column
|
||||
@@ -19,14 +21,24 @@ def calculate_market_change(data: dict[str, pd.DataFrame], column: str = "close"
|
||||
|
||||
:param data: Dict of Dataframes, dict key should be pair.
|
||||
:param column: Column in the original dataframes to use
|
||||
:param min_date: Minimum date to consider for calculations. Market change should only be
|
||||
calculated for data actually backtested, excluding startup periods.
|
||||
:return:
|
||||
"""
|
||||
tmp_means = []
|
||||
for pair, df in data.items():
|
||||
start = df[column].dropna().iloc[0]
|
||||
end = df[column].dropna().iloc[-1]
|
||||
df1 = df
|
||||
if min_date is not None:
|
||||
df1 = df1[df1["date"] >= min_date]
|
||||
if df1.empty:
|
||||
logger.warning(f"Pair {pair} has no data after {min_date}.")
|
||||
continue
|
||||
start = df1[column].dropna().iloc[0]
|
||||
end = df1[column].dropna().iloc[-1]
|
||||
tmp_means.append((end - start) / start)
|
||||
|
||||
if not tmp_means:
|
||||
return 0.0
|
||||
return float(np.mean(tmp_means))
|
||||
|
||||
|
||||
@@ -118,7 +130,7 @@ def _calc_drawdown_series(
|
||||
) -> pd.DataFrame:
|
||||
max_drawdown_df = pd.DataFrame()
|
||||
max_drawdown_df["cumulative"] = profit_results[value_col].cumsum()
|
||||
max_drawdown_df["high_value"] = max_drawdown_df["cumulative"].cummax()
|
||||
max_drawdown_df["high_value"] = np.maximum(0, max_drawdown_df["cumulative"].cummax())
|
||||
max_drawdown_df["drawdown"] = max_drawdown_df["cumulative"] - max_drawdown_df["high_value"]
|
||||
max_drawdown_df["date"] = profit_results.loc[:, date_col]
|
||||
if starting_balance:
|
||||
@@ -201,13 +213,11 @@ def calculate_max_drawdown(
|
||||
if relative
|
||||
else max_drawdown_df["drawdown"].idxmin()
|
||||
)
|
||||
if idxmin == 0:
|
||||
raise ValueError("No losing trade, therefore no drawdown.")
|
||||
high_date = profit_results.loc[max_drawdown_df.iloc[:idxmin]["high_value"].idxmax(), date_col]
|
||||
|
||||
high_idx = max_drawdown_df.iloc[: idxmin + 1]["high_value"].idxmax()
|
||||
high_date = profit_results.loc[high_idx, date_col]
|
||||
low_date = profit_results.loc[idxmin, date_col]
|
||||
high_val = max_drawdown_df.loc[
|
||||
max_drawdown_df.iloc[:idxmin]["high_value"].idxmax(), "cumulative"
|
||||
]
|
||||
high_val = max_drawdown_df.loc[high_idx, "cumulative"]
|
||||
low_val = max_drawdown_df.loc[idxmin, "cumulative"]
|
||||
max_drawdown_rel = max_drawdown_df.loc[idxmin, "drawdown_relative"]
|
||||
|
||||
@@ -375,3 +385,32 @@ def calculate_calmar(
|
||||
|
||||
# print(expected_returns_mean, max_drawdown, calmar_ratio)
|
||||
return calmar_ratio
|
||||
|
||||
|
||||
def calculate_sqn(trades: pd.DataFrame, starting_balance: float) -> float:
|
||||
"""
|
||||
Calculate System Quality Number (SQN) - Van K. Tharp.
|
||||
SQN measures systematic trading quality and takes into account both
|
||||
the number of trades and their standard deviation.
|
||||
|
||||
:param trades: DataFrame containing trades (requires column profit_abs)
|
||||
:param starting_balance: Starting balance of the trading system
|
||||
:return: SQN value
|
||||
"""
|
||||
if len(trades) == 0:
|
||||
return 0.0
|
||||
|
||||
total_profit = trades["profit_abs"] / starting_balance
|
||||
number_of_trades = len(trades)
|
||||
|
||||
# Calculate average trade and standard deviation
|
||||
average_profits = total_profit.mean()
|
||||
profits_std = total_profit.std()
|
||||
|
||||
if profits_std != 0 and not np.isnan(profits_std):
|
||||
sqn = math.sqrt(number_of_trades) * (average_profits / profits_std)
|
||||
else:
|
||||
# Define negative SQN to indicate this is NOT optimal
|
||||
sqn = -100.0
|
||||
|
||||
return round(sqn, 4)
|
||||
|
||||
@@ -7,8 +7,9 @@ class State(Enum):
|
||||
"""
|
||||
|
||||
RUNNING = 1
|
||||
STOPPED = 2
|
||||
RELOAD_CONFIG = 3
|
||||
PAUSED = 2
|
||||
STOPPED = 3
|
||||
RELOAD_CONFIG = 4
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name.lower()}"
|
||||
|
||||
@@ -11,7 +11,11 @@ from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS
|
||||
from freqtrade.enums import CandleType, MarginMode, PriceType, TradingMode
|
||||
from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError
|
||||
from freqtrade.exchange import Exchange
|
||||
from freqtrade.exchange.binance_public_data import concat_safe, download_archive_ohlcv
|
||||
from freqtrade.exchange.binance_public_data import (
|
||||
concat_safe,
|
||||
download_archive_ohlcv,
|
||||
download_archive_trades,
|
||||
)
|
||||
from freqtrade.exchange.common import retrier
|
||||
from freqtrade.exchange.exchange_types import FtHas, Tickers
|
||||
from freqtrade.exchange.exchange_utils_timeframe import timeframe_to_msecs
|
||||
@@ -139,7 +143,7 @@ class Binance(Exchange):
|
||||
Does not work for other exchanges, which don't return the earliest data when called with "0"
|
||||
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
||||
"""
|
||||
if is_new_pair:
|
||||
if is_new_pair and candle_type in (CandleType.SPOT, CandleType.FUTURES, CandleType.MARK):
|
||||
with self._loop_lock:
|
||||
x = self.loop.run_until_complete(
|
||||
self._async_get_candle_history(pair, timeframe, candle_type, 0)
|
||||
@@ -270,12 +274,12 @@ class Binance(Exchange):
|
||||
def dry_run_liquidation_price(
|
||||
self,
|
||||
pair: str,
|
||||
open_rate: float, # Entry price of position
|
||||
open_rate: float,
|
||||
is_short: bool,
|
||||
amount: float,
|
||||
stake_amount: float,
|
||||
leverage: float,
|
||||
wallet_balance: float, # Or margin balance
|
||||
wallet_balance: float,
|
||||
open_trades: list,
|
||||
) -> float | None:
|
||||
"""
|
||||
@@ -289,8 +293,6 @@ class Binance(Exchange):
|
||||
:param amount: Absolute value of position size incl. leverage (in base currency)
|
||||
:param stake_amount: Stake amount - Collateral in settle currency.
|
||||
:param leverage: Leverage used for this position.
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param margin_mode: Either ISOLATED or CROSS
|
||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||
Cross-Margin Mode: crossWalletBalance
|
||||
Isolated-Margin Mode: isolatedWalletBalance
|
||||
@@ -379,3 +381,48 @@ class Binance(Exchange):
|
||||
if not t:
|
||||
return [], "0"
|
||||
return t, from_id
|
||||
|
||||
async def _async_get_trade_history_id(
|
||||
self, pair: str, until: int, since: int, from_id: str | None = None
|
||||
) -> tuple[str, list[list]]:
|
||||
logger.info(f"Fetching trades from Binance, {from_id=}, {since=}, {until=}")
|
||||
|
||||
if not self._config["exchange"].get("only_from_ccxt", False):
|
||||
if from_id is None or not since:
|
||||
trades = await self._api_async.fetch_trades(
|
||||
pair,
|
||||
params={
|
||||
self._trades_pagination_arg: "0",
|
||||
},
|
||||
limit=5,
|
||||
)
|
||||
listing_date: int = trades[0]["timestamp"]
|
||||
since = max(since, listing_date)
|
||||
|
||||
_, res = await download_archive_trades(
|
||||
CandleType.SPOT,
|
||||
pair,
|
||||
since_ms=since,
|
||||
until_ms=until,
|
||||
markets=self.markets,
|
||||
)
|
||||
|
||||
if not res:
|
||||
end_time = since
|
||||
end_id = from_id
|
||||
else:
|
||||
end_time = res[-1][0]
|
||||
end_id = res[-1][1]
|
||||
|
||||
if end_time and end_time >= until:
|
||||
return pair, res
|
||||
else:
|
||||
_, res2 = await super()._async_get_trade_history_id(
|
||||
pair, until=until, since=end_time, from_id=end_id
|
||||
)
|
||||
res.extend(res2)
|
||||
return pair, res
|
||||
|
||||
return await super()._async_get_trade_history_id(
|
||||
pair, until=until, since=since, from_id=from_id
|
||||
)
|
||||
|
||||
+31271
-23918
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
"""
|
||||
Fetch daily-archived OHLCV data from https://data.binance.vision/
|
||||
Documentation can be found in https://github.com/binance/binance-public-data
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -10,9 +11,11 @@ from io import BytesIO
|
||||
from typing import Any
|
||||
|
||||
import aiohttp
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.constants import DEFAULT_TRADES_COLUMNS
|
||||
from freqtrade.enums import CandleType
|
||||
from freqtrade.misc import chunks
|
||||
from freqtrade.util.datetime_helpers import dt_from_ts, dt_now
|
||||
@@ -157,8 +160,8 @@ async def _download_archive_ohlcv(
|
||||
return concat_safe(dfs)
|
||||
else:
|
||||
dfs.append(None)
|
||||
except BaseException as e:
|
||||
logger.warning(f"An exception raised: : {e}")
|
||||
except Exception as e:
|
||||
logger.warning(f"An exception raised: {e}")
|
||||
# Directly return the existing data, do not allow the gap within the data
|
||||
await cancel_and_await_tasks(tasks[tasks.index(task) + 1 :])
|
||||
return concat_safe(dfs)
|
||||
@@ -212,6 +215,20 @@ def binance_vision_ohlcv_zip_url(
|
||||
return url
|
||||
|
||||
|
||||
def binance_vision_trades_zip_url(symbol: str, candle_type: CandleType, date: date) -> str:
|
||||
"""
|
||||
example urls:
|
||||
https://data.binance.vision/data/spot/daily/aggTrades/BTCUSDT/BTCUSDT-aggTrades-2023-10-27.zip
|
||||
https://data.binance.vision/data/futures/um/daily/aggTrades/BTCUSDT/BTCUSDT-aggTrades-2023-10-27.zip
|
||||
"""
|
||||
asset_type_url_segment = candle_type_to_url_segment(candle_type)
|
||||
url = (
|
||||
f"https://data.binance.vision/data/{asset_type_url_segment}/daily/aggTrades/{symbol}"
|
||||
f"/{symbol}-aggTrades-{date.strftime('%Y-%m-%d')}.zip"
|
||||
)
|
||||
return url
|
||||
|
||||
|
||||
async def get_daily_ohlcv(
|
||||
symbol: str,
|
||||
timeframe: str,
|
||||
@@ -268,7 +285,11 @@ async def get_daily_ohlcv(
|
||||
names=["date", "open", "high", "low", "close", "volume"],
|
||||
header=header,
|
||||
)
|
||||
df["date"] = pd.to_datetime(df["date"], unit="ms", utc=True)
|
||||
df["date"] = pd.to_datetime(
|
||||
np.where(df["date"] > 1e13, df["date"] // 1000, df["date"]),
|
||||
unit="ms",
|
||||
utc=True,
|
||||
)
|
||||
return df
|
||||
elif resp.status == 404:
|
||||
logger.debug(f"Failed to download {url}")
|
||||
@@ -280,3 +301,203 @@ async def get_daily_ohlcv(
|
||||
if isinstance(e, Http404) or retry > retry_count:
|
||||
logger.debug(f"Failed to get data from {url}: {e}")
|
||||
raise
|
||||
|
||||
|
||||
async def download_archive_trades(
|
||||
candle_type: CandleType,
|
||||
pair: str,
|
||||
*,
|
||||
since_ms: int,
|
||||
until_ms: int | None,
|
||||
markets: dict[str, Any],
|
||||
stop_on_404: bool = True,
|
||||
) -> tuple[str, list[list]]:
|
||||
try:
|
||||
symbol = markets[pair]["id"]
|
||||
|
||||
last_available_date = dt_now() - timedelta(days=2)
|
||||
|
||||
start = dt_from_ts(since_ms)
|
||||
end = dt_from_ts(until_ms) if until_ms else dt_now()
|
||||
end = min(end, last_available_date)
|
||||
if start >= end:
|
||||
return pair, []
|
||||
result_list = await _download_archive_trades(
|
||||
symbol, pair, candle_type, start, end, stop_on_404
|
||||
)
|
||||
return pair, result_list
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"An exception occurred during fast trades download from Binance, falling back to "
|
||||
"the slower REST API, this can take a lot more time.",
|
||||
exc_info=e,
|
||||
)
|
||||
return pair, []
|
||||
|
||||
|
||||
def parse_trades_from_zip(csvf):
|
||||
# https://github.com/binance/binance-public-data/issues/283
|
||||
first_byte = csvf.read(1)[0]
|
||||
if chr(first_byte).isdigit():
|
||||
# spot
|
||||
header = None
|
||||
names = [
|
||||
"id",
|
||||
"price",
|
||||
"amount",
|
||||
"first_trade_id",
|
||||
"last_trade_id",
|
||||
"timestamp",
|
||||
"is_buyer_maker",
|
||||
"is_best_match",
|
||||
]
|
||||
else:
|
||||
# futures
|
||||
header = 0
|
||||
names = [
|
||||
"id",
|
||||
"price",
|
||||
"amount",
|
||||
"first_trade_id",
|
||||
"last_trade_id",
|
||||
"timestamp",
|
||||
"is_buyer_maker",
|
||||
]
|
||||
csvf.seek(0)
|
||||
|
||||
df = pd.read_csv(
|
||||
csvf,
|
||||
names=names,
|
||||
header=header,
|
||||
)
|
||||
df.loc[:, "cost"] = df["price"] * df["amount"]
|
||||
# Side is reversed intentionally
|
||||
# based on ccxt parseTrade logic.
|
||||
df.loc[:, "side"] = np.where(df["is_buyer_maker"], "sell", "buy")
|
||||
df.loc[:, "type"] = None
|
||||
# Convert timestamp to ms
|
||||
df.loc[:, "timestamp"] = np.where(
|
||||
df["timestamp"] > 1e13,
|
||||
df["timestamp"] // 1000,
|
||||
df["timestamp"],
|
||||
)
|
||||
return df.loc[:, DEFAULT_TRADES_COLUMNS].to_records(index=False).tolist()
|
||||
|
||||
|
||||
async def get_daily_trades(
|
||||
symbol: str,
|
||||
candle_type: CandleType,
|
||||
date: date,
|
||||
session: aiohttp.ClientSession,
|
||||
retry_count: int = 3,
|
||||
retry_delay: float = 0.0,
|
||||
) -> list[list]:
|
||||
"""
|
||||
Get daily OHLCV from https://data.binance.vision
|
||||
See https://github.com/binance/binance-public-data
|
||||
|
||||
:symbol: binance symbol name, e.g. BTCUSDT
|
||||
:candle_type: SPOT or FUTURES
|
||||
:date: the returned DataFrame will cover the entire day of `date` in UTC
|
||||
:session: an aiohttp.ClientSession instance
|
||||
:retry_count: times to retry before returning the exceptions
|
||||
:retry_delay: the time to wait before every retry
|
||||
:return: a list containing trades in DEFAULT_TRADES_COLUMNS format
|
||||
"""
|
||||
|
||||
url = binance_vision_trades_zip_url(symbol, candle_type, date)
|
||||
|
||||
logger.debug(f"download trades data from binance: {url}")
|
||||
|
||||
retry = 0
|
||||
while True:
|
||||
if retry > 0:
|
||||
sleep_secs = retry * retry_delay
|
||||
logger.debug(
|
||||
f"[{retry}/{retry_count}] retry to download {url} after {sleep_secs} seconds"
|
||||
)
|
||||
await asyncio.sleep(sleep_secs)
|
||||
try:
|
||||
async with session.get(url) as resp:
|
||||
if resp.status == 200:
|
||||
content = await resp.read()
|
||||
logger.debug(f"Successfully downloaded {url}")
|
||||
with zipfile.ZipFile(BytesIO(content)) as zipf:
|
||||
with zipf.open(zipf.namelist()[0]) as csvf:
|
||||
return parse_trades_from_zip(csvf)
|
||||
elif resp.status == 404:
|
||||
logger.debug(f"Failed to download {url}")
|
||||
raise Http404(f"404: {url}", date, url)
|
||||
else:
|
||||
raise BadHttpStatus(f"{resp.status} - {resp.reason}")
|
||||
except Exception as e:
|
||||
logger.info("download Daily_trades raised: %s", e)
|
||||
retry += 1
|
||||
if isinstance(e, Http404) or retry > retry_count:
|
||||
logger.debug(f"Failed to get data from {url}: {e}")
|
||||
raise
|
||||
|
||||
|
||||
async def _download_archive_trades(
|
||||
symbol: str,
|
||||
pair: str,
|
||||
candle_type: CandleType,
|
||||
start: date,
|
||||
end: date,
|
||||
stop_on_404: bool,
|
||||
) -> list[list]:
|
||||
# daily dataframes, `None` indicates missing data in that day (when `stop_on_404` is False)
|
||||
results: list[list] = []
|
||||
# the current day being processing, starting at 1.
|
||||
current_day = 0
|
||||
|
||||
connector = aiohttp.TCPConnector(limit=100)
|
||||
async with aiohttp.ClientSession(connector=connector, trust_env=True) as session:
|
||||
# the HTTP connections has been throttled by TCPConnector
|
||||
for dates in chunks(list(date_range(start, end)), 30):
|
||||
tasks = [
|
||||
asyncio.create_task(get_daily_trades(symbol, candle_type, date, session))
|
||||
for date in dates
|
||||
]
|
||||
for task in tasks:
|
||||
current_day += 1
|
||||
try:
|
||||
result = await task
|
||||
except Http404 as e:
|
||||
if stop_on_404:
|
||||
logger.debug(f"Failed to download {e.url} due to 404.")
|
||||
|
||||
# A 404 error on the first day indicates missing data
|
||||
# on https://data.binance.vision, we provide the warning and the advice.
|
||||
# https://github.com/freqtrade/freqtrade/blob/acc53065e5fa7ab5197073276306dc9dc3adbfa3/tests/exchange_online/test_binance_compare_ohlcv.py#L7
|
||||
if current_day == 1:
|
||||
logger.warning(
|
||||
f"Fast download is unavailable due to missing data: "
|
||||
f"{e.url}. Falling back to the slower REST API, "
|
||||
"which may take more time."
|
||||
)
|
||||
if pair in ["BTC/USDT:USDT", "ETH/USDT:USDT", "BCH/USDT:USDT"]:
|
||||
logger.warning(
|
||||
f"To avoid the delay, you can first download {pair} using "
|
||||
"`--timerange <start date>-20200101`, and then download the "
|
||||
"remaining data with `--timerange 20200101-<end date>`."
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
f"Binance fast download for {pair} stopped at {e.date} due to "
|
||||
f"missing data: {e.url}, falling back to rest API for the "
|
||||
"remaining data, this can take more time."
|
||||
)
|
||||
await cancel_and_await_tasks(tasks[tasks.index(task) + 1 :])
|
||||
return results
|
||||
except Exception as e:
|
||||
logger.warning(f"An exception raised: {e}")
|
||||
# Directly return the existing data, do not allow the gap within the data
|
||||
await cancel_and_await_tasks(tasks[tasks.index(task) + 1 :])
|
||||
return results
|
||||
else:
|
||||
# Happy case
|
||||
results.extend(result)
|
||||
|
||||
return results
|
||||
|
||||
@@ -166,15 +166,16 @@ class Bybit(Exchange):
|
||||
PERPETUAL:
|
||||
bybit:
|
||||
https://www.bybithelp.com/HelpCenterKnowledge/bybitHC_Article?language=en_US&id=000001067
|
||||
https://www.bybit.com/en/help-center/article/Liquidation-Price-Calculation-under-Isolated-Mode-Unified-Trading-Account#b
|
||||
|
||||
Long:
|
||||
Liquidation Price = (
|
||||
Entry Price * (1 - Initial Margin Rate + Maintenance Margin Rate)
|
||||
- Extra Margin Added/ Contract)
|
||||
Entry Price - [(Initial Margin - Maintenance Margin)/Contract Quantity]
|
||||
- (Extra Margin Added/Contract Quantity))
|
||||
Short:
|
||||
Liquidation Price = (
|
||||
Entry Price * (1 + Initial Margin Rate - Maintenance Margin Rate)
|
||||
+ Extra Margin Added/ Contract)
|
||||
Entry Price + [(Initial Margin - Maintenance Margin)/Contract Quantity]
|
||||
+ (Extra Margin Added/Contract Quantity))
|
||||
|
||||
Implementation Note: Extra margin is currently not used.
|
||||
|
||||
@@ -184,8 +185,6 @@ class Bybit(Exchange):
|
||||
:param amount: Absolute value of position size incl. leverage (in base currency)
|
||||
:param stake_amount: Stake amount - Collateral in settle currency.
|
||||
:param leverage: Leverage used for this position.
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param margin_mode: Either ISOLATED or CROSS
|
||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||
Cross-Margin Mode: crossWalletBalance
|
||||
Isolated-Margin Mode: isolatedWalletBalance
|
||||
@@ -198,13 +197,16 @@ class Bybit(Exchange):
|
||||
if self.trading_mode == TradingMode.FUTURES and self.margin_mode == MarginMode.ISOLATED:
|
||||
if market["inverse"]:
|
||||
raise OperationalException("Freqtrade does not yet support inverse contracts")
|
||||
initial_margin_rate = 1 / leverage
|
||||
position_value = amount * open_rate
|
||||
initial_margin = position_value / leverage
|
||||
maintenance_margin = position_value * mm_ratio
|
||||
margin_diff_per_contract = (initial_margin - maintenance_margin) / amount
|
||||
|
||||
# See docstring - ignores extra margin!
|
||||
if is_short:
|
||||
return open_rate * (1 + initial_margin_rate - mm_ratio)
|
||||
return open_rate + margin_diff_per_contract
|
||||
else:
|
||||
return open_rate * (1 - initial_margin_rate + mm_ratio)
|
||||
return open_rate - margin_diff_per_contract
|
||||
|
||||
else:
|
||||
raise OperationalException(
|
||||
|
||||
@@ -148,6 +148,7 @@ class Exchange:
|
||||
"trades_has_history": False,
|
||||
"l2_limit_range": None,
|
||||
"l2_limit_range_required": True, # Allow Empty L2 limit (kucoin)
|
||||
"l2_limit_upper": None, # Upper limit for L2 limit
|
||||
"mark_ohlcv_price": "mark",
|
||||
"mark_ohlcv_timeframe": "8h",
|
||||
"funding_fee_timeframe": "8h",
|
||||
@@ -960,7 +961,7 @@ class Exchange:
|
||||
return 1 / pow(10, precision)
|
||||
|
||||
def get_min_pair_stake_amount(
|
||||
self, pair: str, price: float, stoploss: float, leverage: float | None = 1.0
|
||||
self, pair: str, price: float, stoploss: float, leverage: float = 1.0
|
||||
) -> float | None:
|
||||
return self._get_stake_amount_limit(pair, price, stoploss, "min", leverage)
|
||||
|
||||
@@ -979,7 +980,7 @@ class Exchange:
|
||||
price: float,
|
||||
stoploss: float,
|
||||
limit: Literal["min", "max"],
|
||||
leverage: float | None = 1.0,
|
||||
leverage: float = 1.0,
|
||||
) -> float | None:
|
||||
isMin = limit == "min"
|
||||
|
||||
@@ -988,6 +989,8 @@ class Exchange:
|
||||
except KeyError:
|
||||
raise ValueError(f"Can't get market information for symbol {pair}")
|
||||
|
||||
stake_limits = []
|
||||
limits = market["limits"]
|
||||
if isMin:
|
||||
# reserve some percent defined in config (5% default) + stoploss
|
||||
margin_reserve: float = 1.0 + self._config.get(
|
||||
@@ -997,11 +1000,12 @@ class Exchange:
|
||||
# it should not be more than 50%
|
||||
stoploss_reserve = max(min(stoploss_reserve, 1.5), 1)
|
||||
else:
|
||||
# is_max
|
||||
margin_reserve = 1.0
|
||||
stoploss_reserve = 1.0
|
||||
if max_from_tiers := self._get_max_notional_from_tiers(pair, leverage=leverage):
|
||||
stake_limits.append(max_from_tiers)
|
||||
|
||||
stake_limits = []
|
||||
limits = market["limits"]
|
||||
if limits["cost"][limit] is not None:
|
||||
stake_limits.append(
|
||||
self._contracts_to_amount(pair, limits["cost"][limit]) * stoploss_reserve
|
||||
@@ -1365,8 +1369,8 @@ class Exchange:
|
||||
ordertype = available_order_Types[user_order_type]
|
||||
else:
|
||||
# Otherwise pick only one available
|
||||
ordertype = list(available_order_Types.values())[0]
|
||||
user_order_type = list(available_order_Types.keys())[0]
|
||||
ordertype = next(iter(available_order_Types.values()))
|
||||
user_order_type = next(iter(available_order_Types.keys()))
|
||||
return ordertype, user_order_type
|
||||
|
||||
def _get_stop_limit_rate(self, stop_price: float, order_types: dict, side: str) -> float:
|
||||
@@ -1955,14 +1959,18 @@ class Exchange:
|
||||
|
||||
@staticmethod
|
||||
def get_next_limit_in_list(
|
||||
limit: int, limit_range: list[int] | None, range_required: bool = True
|
||||
limit: int,
|
||||
limit_range: list[int] | None,
|
||||
range_required: bool = True,
|
||||
upper_limit: int | None = None,
|
||||
):
|
||||
"""
|
||||
Get next greater value in the list.
|
||||
Used by fetch_l2_order_book if the api only supports a limited range
|
||||
if both limit_range and upper_limit is provided, limit_range wins.
|
||||
"""
|
||||
if not limit_range:
|
||||
return limit
|
||||
return min(limit, upper_limit) if upper_limit else limit
|
||||
|
||||
result = min([x for x in limit_range if limit <= x] + [max(limit_range)])
|
||||
if not range_required and limit > result:
|
||||
@@ -1979,7 +1987,10 @@ class Exchange:
|
||||
{'asks': [price, volume], 'bids': [price, volume]}
|
||||
"""
|
||||
limit1 = self.get_next_limit_in_list(
|
||||
limit, self._ft_has["l2_limit_range"], self._ft_has["l2_limit_range_required"]
|
||||
limit,
|
||||
self._ft_has["l2_limit_range"],
|
||||
self._ft_has["l2_limit_range_required"],
|
||||
self._ft_has["l2_limit_upper"],
|
||||
)
|
||||
try:
|
||||
return self._api.fetch_l2_order_book(pair, limit1)
|
||||
@@ -2351,6 +2362,7 @@ class Exchange:
|
||||
since_ms=since_ms,
|
||||
until_ms=until_ms,
|
||||
candle_type=candle_type,
|
||||
raise_=True,
|
||||
)
|
||||
)
|
||||
logger.debug(f"Downloaded data for {pair} from ccxt with length {len(data)}.")
|
||||
@@ -2391,7 +2403,7 @@ class Exchange:
|
||||
if isinstance(res, BaseException):
|
||||
logger.warning(f"Async code raised an exception: {repr(res)}")
|
||||
if raise_:
|
||||
raise
|
||||
raise res
|
||||
continue
|
||||
else:
|
||||
# Deconstruct tuple if it's not an exception
|
||||
@@ -2440,8 +2452,8 @@ class Exchange:
|
||||
|
||||
return self._exchange_ws.get_ohlcv(pair, timeframe, candle_type, candle_ts)
|
||||
logger.info(
|
||||
f"Failed to reuse watch {pair}, {timeframe}, {candle_ts < last_refresh_time},"
|
||||
f" {candle_ts}, {last_refresh_time}, "
|
||||
f"Couldn't reuse watch for {pair}, {timeframe}, falling back to REST api. "
|
||||
f"{candle_ts < last_refresh_time}, {candle_ts}, {last_refresh_time}, "
|
||||
f"{format_ms_time(candle_ts)}, {format_ms_time(last_refresh_time)} "
|
||||
)
|
||||
|
||||
@@ -2789,7 +2801,7 @@ class Exchange:
|
||||
pair, timeframe, candle_type = pairwt
|
||||
since_ms = None
|
||||
new_ticks: list = []
|
||||
all_stored_ticks_df = DataFrame(columns=DEFAULT_TRADES_COLUMNS + ["date"])
|
||||
all_stored_ticks_df = DataFrame(columns=[*DEFAULT_TRADES_COLUMNS, "date"])
|
||||
first_candle_ms = self.needed_candle_for_trades_ms(timeframe, candle_type)
|
||||
# refresh, if
|
||||
# a. not in _trades
|
||||
@@ -2834,7 +2846,7 @@ class Exchange:
|
||||
else:
|
||||
# Skip cache, it's too old
|
||||
all_stored_ticks_df = DataFrame(
|
||||
columns=DEFAULT_TRADES_COLUMNS + ["date"]
|
||||
columns=[*DEFAULT_TRADES_COLUMNS, "date"]
|
||||
)
|
||||
|
||||
# from_id overrules with exchange set to id paginate
|
||||
@@ -3352,42 +3364,22 @@ class Exchange:
|
||||
pair_tiers = self._leverage_tiers[pair]
|
||||
|
||||
if stake_amount == 0:
|
||||
return self._leverage_tiers[pair][0]["maxLeverage"] # Max lev for lowest amount
|
||||
return pair_tiers[0]["maxLeverage"] # Max lev for lowest amount
|
||||
|
||||
for tier_index in range(len(pair_tiers)):
|
||||
tier = pair_tiers[tier_index]
|
||||
lev = tier["maxLeverage"]
|
||||
# Find the appropriate tier based on stake_amount
|
||||
prior_max_lev = None
|
||||
for tier in pair_tiers:
|
||||
min_stake = tier["minNotional"] / (prior_max_lev or tier["maxLeverage"])
|
||||
max_stake = tier["maxNotional"] / tier["maxLeverage"]
|
||||
prior_max_lev = tier["maxLeverage"]
|
||||
# Adjust notional by leverage to do a proper comparison
|
||||
if min_stake <= stake_amount <= max_stake:
|
||||
return tier["maxLeverage"]
|
||||
|
||||
if tier_index < len(pair_tiers) - 1:
|
||||
next_tier = pair_tiers[tier_index + 1]
|
||||
next_floor = next_tier["minNotional"] / next_tier["maxLeverage"]
|
||||
if next_floor > stake_amount: # Next tier min too high for stake amount
|
||||
return min((tier["maxNotional"] / stake_amount), lev)
|
||||
#
|
||||
# With the two leverage tiers below,
|
||||
# - a stake amount of 150 would mean a max leverage of (10000 / 150) = 66.66
|
||||
# - stakes below 133.33 = max_lev of 75
|
||||
# - stakes between 133.33-200 = max_lev of 10000/stake = 50.01-74.99
|
||||
# - stakes from 200 + 1000 = max_lev of 50
|
||||
#
|
||||
# {
|
||||
# "min": 0, # stake = 0.0
|
||||
# "max": 10000, # max_stake@75 = 10000/75 = 133.33333333333334
|
||||
# "lev": 75,
|
||||
# },
|
||||
# {
|
||||
# "min": 10000, # stake = 200.0
|
||||
# "max": 50000, # max_stake@50 = 50000/50 = 1000.0
|
||||
# "lev": 50,
|
||||
# }
|
||||
#
|
||||
|
||||
else: # if on the last tier
|
||||
if stake_amount > tier["maxNotional"]:
|
||||
# If stake is > than max tradeable amount
|
||||
raise InvalidOrderException(f"Amount {stake_amount} too high for {pair}")
|
||||
else:
|
||||
return tier["maxLeverage"]
|
||||
# else: # if on the last tier
|
||||
if stake_amount > max_stake:
|
||||
# If stake is > than max tradeable amount
|
||||
raise InvalidOrderException(f"Amount {stake_amount} too high for {pair}")
|
||||
|
||||
raise OperationalException(
|
||||
"Looped through all tiers without finding a max leverage. Should never be reached"
|
||||
@@ -3402,6 +3394,23 @@ class Exchange:
|
||||
else:
|
||||
return 1.0
|
||||
|
||||
def _get_max_notional_from_tiers(self, pair: str, leverage: float) -> float | None:
|
||||
"""
|
||||
get max_notional from leverage_tiers
|
||||
:param pair: The base/quote currency pair being traded
|
||||
:param leverage: The leverage to be used
|
||||
:return: The maximum notional value for the given leverage or None if not found
|
||||
"""
|
||||
if self.trading_mode != TradingMode.FUTURES:
|
||||
return None
|
||||
if pair not in self._leverage_tiers:
|
||||
return None
|
||||
pair_tiers = self._leverage_tiers[pair]
|
||||
for tier in reversed(pair_tiers):
|
||||
if leverage <= tier["maxLeverage"]:
|
||||
return tier["maxNotional"]
|
||||
return None
|
||||
|
||||
@retrier
|
||||
def _set_leverage(
|
||||
self,
|
||||
@@ -3687,12 +3696,12 @@ class Exchange:
|
||||
def dry_run_liquidation_price(
|
||||
self,
|
||||
pair: str,
|
||||
open_rate: float, # Entry price of position
|
||||
open_rate: float,
|
||||
is_short: bool,
|
||||
amount: float,
|
||||
stake_amount: float,
|
||||
leverage: float,
|
||||
wallet_balance: float, # Or margin balance
|
||||
wallet_balance: float,
|
||||
open_trades: list,
|
||||
) -> float | None:
|
||||
"""
|
||||
@@ -3713,8 +3722,6 @@ class Exchange:
|
||||
:param amount: Absolute value of position size incl. leverage (in base currency)
|
||||
:param stake_amount: Stake amount - Collateral in settle currency.
|
||||
:param leverage: Leverage used for this position.
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param margin_mode: Either ISOLATED or CROSS
|
||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||
Cross-Margin Mode: crossWalletBalance
|
||||
Isolated-Margin Mode: isolatedWalletBalance
|
||||
|
||||
@@ -37,6 +37,7 @@ class FtHas(TypedDict, total=False):
|
||||
# Orderbook
|
||||
l2_limit_range: list[int] | None
|
||||
l2_limit_range_required: bool
|
||||
l2_limit_upper: int | None
|
||||
# Futures
|
||||
ccxt_futures_name: str # usually swap
|
||||
mark_ohlcv_price: str
|
||||
@@ -44,6 +45,7 @@ class FtHas(TypedDict, total=False):
|
||||
funding_fee_timeframe: str
|
||||
funding_fee_candle_limit: int
|
||||
floor_leverage: bool
|
||||
uses_leverage_tiers: bool
|
||||
needs_trading_fees: bool
|
||||
order_props_in_contracts: list[Literal["amount", "cost", "filled", "remaining"]]
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class Gate(Exchange):
|
||||
"stoploss_order_types": {"limit": "limit"},
|
||||
"stop_price_param": "stopPrice",
|
||||
"stop_price_prop": "stopPrice",
|
||||
"l2_limit_upper": 1000,
|
||||
"marketOrderRequiresPrice": True,
|
||||
"trades_has_history": False, # Endpoint would support this - but ccxt doesn't.
|
||||
}
|
||||
@@ -44,6 +45,7 @@ class Gate(Exchange):
|
||||
"marketOrderRequiresPrice": False,
|
||||
"funding_fee_candle_limit": 90,
|
||||
"stop_price_type_field": "price_type",
|
||||
"l2_limit_upper": 300,
|
||||
"stop_price_type_value_mapping": {
|
||||
PriceType.LAST: 0,
|
||||
PriceType.MARK: 1,
|
||||
|
||||
@@ -35,6 +35,7 @@ class Hyperliquid(Exchange):
|
||||
"stop_price_prop": "stopPrice",
|
||||
"funding_fee_timeframe": "1h",
|
||||
"funding_fee_candle_limit": 500,
|
||||
"uses_leverage_tiers": False,
|
||||
}
|
||||
|
||||
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
|
||||
|
||||
@@ -69,7 +69,7 @@ class Kraken(Exchange):
|
||||
consolidated: CcxtBalances = {}
|
||||
for currency, balance in balances.items():
|
||||
base_currency = currency[:-2] if currency.endswith(".F") else currency
|
||||
base_currency = self._api.commonCurrencies.get(base_currency, base_currency)
|
||||
|
||||
if base_currency in consolidated:
|
||||
consolidated[base_currency]["free"] += balance["free"]
|
||||
consolidated[base_currency]["used"] += balance["used"]
|
||||
|
||||
@@ -46,19 +46,20 @@ class BaseEnvironment(gym.Env):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
df: DataFrame = DataFrame(),
|
||||
prices: DataFrame = DataFrame(),
|
||||
reward_kwargs: dict = {},
|
||||
*,
|
||||
df: DataFrame,
|
||||
prices: DataFrame,
|
||||
reward_kwargs: dict,
|
||||
window_size=10,
|
||||
starting_point=True,
|
||||
id: str = "baseenv-1", # noqa: A002
|
||||
seed: int = 1,
|
||||
config: dict = {},
|
||||
config: dict,
|
||||
live: bool = False,
|
||||
fee: float = 0.0015,
|
||||
can_short: bool = False,
|
||||
pair: str = "",
|
||||
df_raw: DataFrame = DataFrame(),
|
||||
df_raw: DataFrame,
|
||||
):
|
||||
"""
|
||||
Initializes the training/eval environment.
|
||||
|
||||
@@ -488,7 +488,7 @@ def make_env(
|
||||
seed: int,
|
||||
train_df: DataFrame,
|
||||
price: DataFrame,
|
||||
env_info: dict[str, Any] = {},
|
||||
env_info: dict[str, Any],
|
||||
) -> Callable:
|
||||
"""
|
||||
Utility function for multiprocessed env.
|
||||
|
||||
@@ -569,7 +569,7 @@ class FreqaiDataDrawer:
|
||||
dk.training_features_list = dk.data["training_features_list"]
|
||||
dk.label_list = dk.data["label_list"]
|
||||
|
||||
def load_data(self, coin: str, dk: FreqaiDataKitchen) -> Any: # noqa: C901
|
||||
def load_data(self, coin: str, dk: FreqaiDataKitchen) -> Any:
|
||||
"""
|
||||
loads all data required to make a prediction on a sub-train time range
|
||||
:returns:
|
||||
|
||||
@@ -214,7 +214,7 @@ class FreqaiDataKitchen:
|
||||
self,
|
||||
unfiltered_df: DataFrame,
|
||||
training_feature_list: list,
|
||||
label_list: list = list(),
|
||||
label_list: list | None = None,
|
||||
training_filter: bool = True,
|
||||
) -> tuple[DataFrame, DataFrame]:
|
||||
"""
|
||||
@@ -244,7 +244,7 @@ class FreqaiDataKitchen:
|
||||
# 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, axis=1)
|
||||
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(copy=False)
|
||||
@@ -654,8 +654,8 @@ class FreqaiDataKitchen:
|
||||
pair: str,
|
||||
tf: str,
|
||||
strategy: IStrategy,
|
||||
corr_dataframes: dict = {},
|
||||
base_dataframes: dict = {},
|
||||
corr_dataframes: dict,
|
||||
base_dataframes: dict,
|
||||
is_corr_pairs: bool = False,
|
||||
) -> DataFrame:
|
||||
"""
|
||||
@@ -773,10 +773,10 @@ class FreqaiDataKitchen:
|
||||
def use_strategy_to_populate_indicators( # noqa: C901
|
||||
self,
|
||||
strategy: IStrategy,
|
||||
corr_dataframes: dict = {},
|
||||
base_dataframes: dict = {},
|
||||
corr_dataframes: dict[str, DataFrame] | None = None,
|
||||
base_dataframes: dict[str, dict[str, DataFrame]] | None = None,
|
||||
pair: str = "",
|
||||
prediction_dataframe: DataFrame = pd.DataFrame(),
|
||||
prediction_dataframe: DataFrame | None = None,
|
||||
do_corr_pairs: bool = True,
|
||||
) -> DataFrame:
|
||||
"""
|
||||
@@ -793,6 +793,10 @@ class FreqaiDataKitchen:
|
||||
:return:
|
||||
dataframe: DataFrame = dataframe containing populated indicators
|
||||
"""
|
||||
if not corr_dataframes:
|
||||
corr_dataframes = {}
|
||||
if not base_dataframes:
|
||||
base_dataframes = {}
|
||||
|
||||
# check if the user is using the deprecated populate_any_indicators function
|
||||
new_version = inspect.getsource(strategy.populate_any_indicators) == (
|
||||
@@ -822,7 +826,7 @@ class FreqaiDataKitchen:
|
||||
if tf not in corr_dataframes[p]:
|
||||
corr_dataframes[p][tf] = pd.DataFrame()
|
||||
|
||||
if not prediction_dataframe.empty:
|
||||
if prediction_dataframe is not None and not prediction_dataframe.empty:
|
||||
dataframe = prediction_dataframe.copy()
|
||||
base_dataframes[self.config["timeframe"]] = dataframe.copy()
|
||||
else:
|
||||
|
||||
@@ -618,7 +618,7 @@ class IFreqaiModel(ABC):
|
||||
)
|
||||
|
||||
unfiltered_dataframe = dk.use_strategy_to_populate_indicators(
|
||||
strategy, corr_dataframes, base_dataframes, pair
|
||||
strategy, corr_dataframes=corr_dataframes, base_dataframes=base_dataframes, pair=pair
|
||||
)
|
||||
|
||||
trained_timestamp = new_trained_timerange.stopts
|
||||
|
||||
@@ -4,8 +4,8 @@ from typing import Any
|
||||
from xgboost import XGBRegressor
|
||||
|
||||
from freqtrade.freqai.base_models.BaseRegressionModel import BaseRegressionModel
|
||||
from freqtrade.freqai.base_models.FreqaiMultiOutputRegressor import FreqaiMultiOutputRegressor
|
||||
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
|
||||
from freqtrade.freqai.tensorboard import TBCallback
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -19,6 +19,7 @@ class XGBoostRegressorMultiTarget(BaseRegressionModel):
|
||||
`predict()` methods to add their custom data handling tools or change
|
||||
various aspects of the training that cannot be configured via the
|
||||
top level config.json file.
|
||||
This is an exact copy of XGBoostRegressor kept for compatibility reasons.
|
||||
"""
|
||||
|
||||
def fit(self, data_dictionary: dict, dk: FreqaiDataKitchen, **kwargs) -> Any:
|
||||
@@ -29,45 +30,32 @@ class XGBoostRegressorMultiTarget(BaseRegressionModel):
|
||||
:param dk: The datakitchen object for the current coin/model
|
||||
"""
|
||||
|
||||
xgb = XGBRegressor(**self.model_training_parameters)
|
||||
|
||||
X = data_dictionary["train_features"]
|
||||
y = data_dictionary["train_labels"]
|
||||
|
||||
if self.freqai_info.get("data_split_parameters", {}).get("test_size", 0.1) == 0:
|
||||
eval_set = None
|
||||
eval_weights = None
|
||||
else:
|
||||
eval_set = [(data_dictionary["test_features"], data_dictionary["test_labels"]), (X, y)]
|
||||
eval_weights = [data_dictionary["test_weights"], data_dictionary["train_weights"]]
|
||||
|
||||
sample_weight = data_dictionary["train_weights"]
|
||||
|
||||
eval_weights = None
|
||||
eval_sets = [None] * y.shape[1]
|
||||
xgb_model = self.get_init_model(dk.pair)
|
||||
|
||||
if self.freqai_info.get("data_split_parameters", {}).get("test_size", 0.1) != 0:
|
||||
eval_weights = [data_dictionary["test_weights"]]
|
||||
for i in range(data_dictionary["test_labels"].shape[1]):
|
||||
eval_sets[i] = [ # type: ignore
|
||||
(
|
||||
data_dictionary["test_features"],
|
||||
data_dictionary["test_labels"].iloc[:, i],
|
||||
)
|
||||
]
|
||||
model = XGBRegressor(**self.model_training_parameters)
|
||||
|
||||
init_model = self.get_init_model(dk.pair)
|
||||
if init_model:
|
||||
init_models = init_model.estimators_
|
||||
else:
|
||||
init_models = [None] * y.shape[1]
|
||||
|
||||
fit_params = []
|
||||
for i in range(len(eval_sets)):
|
||||
fit_params.append(
|
||||
{
|
||||
"eval_set": eval_sets[i],
|
||||
"sample_weight_eval_set": eval_weights,
|
||||
"xgb_model": init_models[i],
|
||||
}
|
||||
)
|
||||
|
||||
model = FreqaiMultiOutputRegressor(estimator=xgb)
|
||||
thread_training = self.freqai_info.get("multitarget_parallel_training", False)
|
||||
if thread_training:
|
||||
model.n_jobs = y.shape[1]
|
||||
model.fit(X=X, y=y, sample_weight=sample_weight, fit_params=fit_params)
|
||||
model.set_params(callbacks=[TBCallback(dk.data_path)])
|
||||
model.fit(
|
||||
X=X,
|
||||
y=y,
|
||||
sample_weight=sample_weight,
|
||||
eval_set=eval_set,
|
||||
sample_weight_eval_set=eval_weights,
|
||||
xgb_model=xgb_model,
|
||||
)
|
||||
# set the callbacks to empty so that we can serialize to disk later
|
||||
model.set_params(callbacks=[])
|
||||
|
||||
return model
|
||||
|
||||
@@ -25,7 +25,7 @@ class PyTorchModelTrainer(PyTorchTrainerInterface):
|
||||
criterion: nn.Module,
|
||||
device: str,
|
||||
data_convertor: PyTorchDataConvertor,
|
||||
model_meta_data: dict[str, Any] = {},
|
||||
model_meta_data: dict[str, Any] | None = None,
|
||||
window_size: int = 1,
|
||||
tb_logger: Any = None,
|
||||
**kwargs,
|
||||
@@ -45,6 +45,8 @@ class PyTorchModelTrainer(PyTorchTrainerInterface):
|
||||
:param n_epochs: The maximum number batches to use for evaluation.
|
||||
:param batch_size: The size of the batches to use during training.
|
||||
"""
|
||||
if model_meta_data is None:
|
||||
model_meta_data = {}
|
||||
self.model = model
|
||||
self.optimizer = optimizer
|
||||
self.criterion = criterion
|
||||
|
||||
+91
-48
@@ -293,6 +293,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
trades = Trade.get_open_trades()
|
||||
# First process current opened trades (positions)
|
||||
self.exit_positions(trades)
|
||||
Trade.commit()
|
||||
|
||||
# Check if we need to adjust our current positions before attempting to enter new trades.
|
||||
if self.strategy.position_adjustment_enable:
|
||||
@@ -300,7 +301,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
self.process_open_trade_positions()
|
||||
|
||||
# Then looking for entry opportunities
|
||||
if self.get_free_open_trades():
|
||||
if self.state == State.RUNNING and self.get_free_open_trades():
|
||||
self.enter_positions()
|
||||
self._schedule.run_pending()
|
||||
Trade.commit()
|
||||
@@ -759,12 +760,14 @@ class FreqtradeBot(LoggingMixin):
|
||||
current_exit_profit = trade.calc_profit_ratio(current_exit_rate)
|
||||
|
||||
min_entry_stake = self.exchange.get_min_pair_stake_amount(
|
||||
trade.pair, current_entry_rate, 0.0
|
||||
trade.pair, current_entry_rate, 0.0, trade.leverage
|
||||
)
|
||||
min_exit_stake = self.exchange.get_min_pair_stake_amount(
|
||||
trade.pair, current_exit_rate, self.strategy.stoploss
|
||||
trade.pair, current_exit_rate, self.strategy.stoploss, trade.leverage
|
||||
)
|
||||
max_entry_stake = self.exchange.get_max_pair_stake_amount(
|
||||
trade.pair, current_entry_rate, trade.leverage
|
||||
)
|
||||
max_entry_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_entry_rate)
|
||||
stake_available = self.wallets.get_available_stake_amount()
|
||||
logger.debug(f"Calling adjust_trade_position for pair {trade.pair}")
|
||||
stake_amount, order_tag = self.strategy._adjust_trade_position_internal(
|
||||
@@ -781,6 +784,10 @@ class FreqtradeBot(LoggingMixin):
|
||||
)
|
||||
|
||||
if stake_amount is not None and stake_amount > 0.0:
|
||||
if self.state == State.PAUSED:
|
||||
logger.debug("Position adjustment aborted because the bot is in PAUSED state")
|
||||
return
|
||||
|
||||
# We should increase our position
|
||||
if self.strategy.max_entry_position_adjustment > -1:
|
||||
count_of_entries = trade.nr_of_successful_entries
|
||||
@@ -789,6 +796,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
return
|
||||
else:
|
||||
logger.debug("Max adjustment entries is set to unlimited.")
|
||||
|
||||
self.execute_entry(
|
||||
trade.pair,
|
||||
stake_amount,
|
||||
@@ -903,14 +911,14 @@ class FreqtradeBot(LoggingMixin):
|
||||
|
||||
msg = (
|
||||
f"Position adjust: about to create a new order for {pair} with stake_amount: "
|
||||
f"{stake_amount} for {trade}"
|
||||
f"{stake_amount} and price: {enter_limit_requested} for {trade}"
|
||||
if mode == "pos_adjust"
|
||||
else (
|
||||
f"Replacing {side} order: about create a new order for {pair} with stake_amount: "
|
||||
f"{stake_amount} ..."
|
||||
f"{stake_amount} and price: {enter_limit_requested} ..."
|
||||
if mode == "replace"
|
||||
else f"{name} signal found: about create a new trade for {pair} with stake_amount: "
|
||||
f"{stake_amount} ..."
|
||||
f"{stake_amount} and price: {enter_limit_requested} ..."
|
||||
)
|
||||
)
|
||||
logger.info(msg)
|
||||
@@ -1711,47 +1719,68 @@ class FreqtradeBot(LoggingMixin):
|
||||
cancel_reason = constants.CANCEL_REASON["USER_CANCEL"]
|
||||
|
||||
if order_obj.safe_placement_price != adjusted_price:
|
||||
# cancel existing order if new price is supplied or None
|
||||
res = self.handle_cancel_order(
|
||||
order, order_obj, trade, cancel_reason, replacing=replacing
|
||||
self.handle_replace_order(
|
||||
order,
|
||||
order_obj,
|
||||
trade,
|
||||
adjusted_price,
|
||||
is_entry,
|
||||
cancel_reason,
|
||||
replacing=replacing,
|
||||
)
|
||||
if not res:
|
||||
self.replace_order_failed(
|
||||
trade, f"Could not fully cancel order for {trade}, therefore not replacing."
|
||||
|
||||
def handle_replace_order(
|
||||
self,
|
||||
order: CcxtOrder | None,
|
||||
order_obj: Order,
|
||||
trade: Trade,
|
||||
new_order_price: float | None,
|
||||
is_entry: bool,
|
||||
cancel_reason: str,
|
||||
replacing: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Cancel existing order if new price is supplied, and if the cancel is successful,
|
||||
places a new order with the remaining capital.
|
||||
"""
|
||||
if not order:
|
||||
order = self.exchange.fetch_order(order_obj.order_id, trade.pair)
|
||||
res = self.handle_cancel_order(order, order_obj, trade, cancel_reason, replacing=replacing)
|
||||
if not res:
|
||||
self.replace_order_failed(
|
||||
trade, f"Could not fully cancel order for {trade}, therefore not replacing."
|
||||
)
|
||||
return
|
||||
if new_order_price:
|
||||
# place new order only if new price is supplied
|
||||
try:
|
||||
if is_entry:
|
||||
succeeded = self.execute_entry(
|
||||
pair=trade.pair,
|
||||
stake_amount=(
|
||||
order_obj.safe_remaining * order_obj.safe_price / trade.leverage
|
||||
),
|
||||
price=new_order_price,
|
||||
trade=trade,
|
||||
is_short=trade.is_short,
|
||||
mode="replace",
|
||||
)
|
||||
return
|
||||
if adjusted_price:
|
||||
# place new order only if new price is supplied
|
||||
try:
|
||||
if is_entry:
|
||||
succeeded = self.execute_entry(
|
||||
pair=trade.pair,
|
||||
stake_amount=(
|
||||
order_obj.safe_remaining * order_obj.safe_price / trade.leverage
|
||||
),
|
||||
price=adjusted_price,
|
||||
trade=trade,
|
||||
is_short=trade.is_short,
|
||||
mode="replace",
|
||||
)
|
||||
else:
|
||||
succeeded = self.execute_trade_exit(
|
||||
trade,
|
||||
adjusted_price,
|
||||
exit_check=ExitCheckTuple(
|
||||
exit_type=ExitType.CUSTOM_EXIT,
|
||||
exit_reason=order_obj.ft_order_tag or "order_replaced",
|
||||
),
|
||||
ordertype="limit",
|
||||
sub_trade_amt=order_obj.safe_remaining,
|
||||
)
|
||||
if not succeeded:
|
||||
self.replace_order_failed(
|
||||
trade, f"Could not replace order for {trade}."
|
||||
)
|
||||
except DependencyException as exception:
|
||||
logger.warning(f"Unable to replace order for {trade.pair}: {exception}")
|
||||
self.replace_order_failed(trade, f"Could not replace order for {trade}.")
|
||||
else:
|
||||
succeeded = self.execute_trade_exit(
|
||||
trade,
|
||||
new_order_price,
|
||||
exit_check=ExitCheckTuple(
|
||||
exit_type=ExitType.CUSTOM_EXIT,
|
||||
exit_reason=order_obj.ft_order_tag or "order_replaced",
|
||||
),
|
||||
ordertype="limit",
|
||||
sub_trade_amt=order_obj.safe_remaining,
|
||||
)
|
||||
if not succeeded:
|
||||
self.replace_order_failed(trade, f"Could not replace order for {trade}.")
|
||||
except DependencyException as exception:
|
||||
logger.warning(f"Unable to replace order for {trade.pair}: {exception}")
|
||||
self.replace_order_failed(trade, f"Could not replace order for {trade}.")
|
||||
|
||||
def cancel_open_orders_of_trade(
|
||||
self, trade: Trade, sides: list[str], reason: str, replacing: bool = False
|
||||
@@ -1901,7 +1930,10 @@ class FreqtradeBot(LoggingMixin):
|
||||
# to the trade object
|
||||
self.update_trade_state(trade, order_id, corder)
|
||||
|
||||
logger.info(f"Partial {trade.entry_side} order timeout for {trade}.")
|
||||
logger.info(
|
||||
f"Partial {trade.entry_side} order timeout for {trade}. Filled: {filled_amount}, "
|
||||
f"total: {order_obj.ft_amount}"
|
||||
)
|
||||
order_obj.ft_cancel_reason += f", {constants.CANCEL_REASON['PARTIALLY_FILLED']}"
|
||||
|
||||
self.wallets.update()
|
||||
@@ -2587,4 +2619,15 @@ class FreqtradeBot(LoggingMixin):
|
||||
max_custom_price_allowed = proposed_price + (proposed_price * cust_p_max_dist_r)
|
||||
|
||||
# Bracket between min_custom_price_allowed and max_custom_price_allowed
|
||||
return max(min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed)
|
||||
final_price = max(
|
||||
min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed
|
||||
)
|
||||
|
||||
# Log a warning if the custom price was adjusted by clamping.
|
||||
if final_price != valid_custom_price:
|
||||
logger.info(
|
||||
f"Custom price adjusted from {valid_custom_price} to {final_price} based on "
|
||||
"custom_price_max_distance_ratio of {cust_p_max_dist_r}."
|
||||
)
|
||||
|
||||
return final_price
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# flake8: noqa: F401
|
||||
from freqtrade.ft_types.backtest_result_type import (
|
||||
BacktestContentType,
|
||||
BacktestContentTypeIcomplete,
|
||||
BacktestHistoryEntryType,
|
||||
BacktestMetadataType,
|
||||
BacktestResultType,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from typing import Any
|
||||
from copy import deepcopy
|
||||
from typing import Any, cast
|
||||
|
||||
from pandas import DataFrame
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from freqtrade.constants import Config
|
||||
|
||||
|
||||
class BacktestMetadataType(TypedDict):
|
||||
run_id: str
|
||||
@@ -15,11 +19,16 @@ class BacktestResultType(TypedDict):
|
||||
|
||||
|
||||
def get_BacktestResultType_default() -> BacktestResultType:
|
||||
return {
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
return cast(
|
||||
BacktestResultType,
|
||||
deepcopy(
|
||||
{
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class BacktestHistoryEntryType(BacktestMetadataType):
|
||||
@@ -30,3 +39,23 @@ class BacktestHistoryEntryType(BacktestMetadataType):
|
||||
backtest_end_ts: int | None
|
||||
timeframe: str | None
|
||||
timeframe_detail: str | None
|
||||
|
||||
|
||||
class BacktestContentTypeIcomplete(TypedDict, total=False):
|
||||
results: DataFrame
|
||||
config: Config
|
||||
locks: Any
|
||||
rejected_signals: int
|
||||
timedout_entry_orders: int
|
||||
timedout_exit_orders: int
|
||||
canceled_trade_entries: int
|
||||
canceled_entry_orders: int
|
||||
replaced_entry_orders: int
|
||||
final_balance: float
|
||||
backtest_start_time: int
|
||||
backtest_end_time: int
|
||||
run_id: str
|
||||
|
||||
|
||||
class BacktestContentType(BacktestContentTypeIcomplete, total=True):
|
||||
pass
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user