From 0bdd238d7ff2ebf748b705f0cb239767925eeade Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:56:37 +0000 Subject: [PATCH 01/19] Bump orjson from 3.8.6 to 3.8.7 Bumps [orjson](https://github.com/ijl/orjson) from 3.8.6 to 3.8.7. - [Release notes](https://github.com/ijl/orjson/releases) - [Changelog](https://github.com/ijl/orjson/blob/master/CHANGELOG.md) - [Commits](https://github.com/ijl/orjson/compare/3.8.6...3.8.7) --- updated-dependencies: - dependency-name: orjson dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a6b3ddd51..8f5c2f46d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,7 +28,7 @@ py_find_1st==1.1.5 # Load ticker files 30% faster python-rapidjson==1.9 # Properly format api responses -orjson==3.8.6 +orjson==3.8.7 # Notify systemd sdnotify==0.3.2 From f4c17be8dec5dd176a73fa5fb07d752e79443087 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:56:44 +0000 Subject: [PATCH 02/19] Bump ruff from 0.0.253 to 0.0.254 Bumps [ruff](https://github.com/charliermarsh/ruff) from 0.0.253 to 0.0.254. - [Release notes](https://github.com/charliermarsh/ruff/releases) - [Changelog](https://github.com/charliermarsh/ruff/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/charliermarsh/ruff/compare/v0.0.253...v0.0.254) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 2ba004f8d..4c009fc42 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ -r docs/requirements-docs.txt coveralls==3.3.1 -ruff==0.0.253 +ruff==0.0.254 mypy==1.0.1 pre-commit==3.1.1 pytest==7.2.1 From 8484427cf879a4dae7aee02a504811d6c7e99b75 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:56:54 +0000 Subject: [PATCH 03/19] Bump cryptography from 39.0.1 to 39.0.2 Bumps [cryptography](https://github.com/pyca/cryptography) from 39.0.1 to 39.0.2. - [Release notes](https://github.com/pyca/cryptography/releases) - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/39.0.1...39.0.2) --- updated-dependencies: - dependency-name: cryptography dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a6b3ddd51..1f22bc033 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ pandas==1.5.3 pandas-ta==0.3.14b ccxt==2.8.98 -cryptography==39.0.1 +cryptography==39.0.2 aiohttp==3.8.4 SQLAlchemy==2.0.4 python-telegram-bot==13.15 From 57969f8b0164579df9f5bd1b80504598a2b84e70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:56:58 +0000 Subject: [PATCH 04/19] Bump prompt-toolkit from 3.0.37 to 3.0.38 Bumps [prompt-toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) from 3.0.37 to 3.0.38. - [Release notes](https://github.com/prompt-toolkit/python-prompt-toolkit/releases) - [Changelog](https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/CHANGELOG) - [Commits](https://github.com/prompt-toolkit/python-prompt-toolkit/compare/3.0.37...3.0.38) --- updated-dependencies: - dependency-name: prompt-toolkit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a6b3ddd51..efd858f45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,7 +45,7 @@ psutil==5.9.4 colorama==0.4.6 # Building config files interactively questionary==1.10.0 -prompt-toolkit==3.0.37 +prompt-toolkit==3.0.38 # Extensions to datetime library python-dateutil==2.8.2 From d1d9e25c2e8707edbbc905f53e7722bfe5b5af4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:57:03 +0000 Subject: [PATCH 05/19] Bump mkdocs-material from 9.0.15 to 9.1.1 Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.0.15 to 9.1.1. - [Release notes](https://github.com/squidfunk/mkdocs-material/releases) - [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG) - [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.0.15...9.1.1) --- updated-dependencies: - dependency-name: mkdocs-material dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs/requirements-docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 065411018..2ca11dabf 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,6 +1,6 @@ markdown==3.3.7 mkdocs==1.4.2 -mkdocs-material==9.0.15 +mkdocs-material==9.1.1 mdx_truly_sane_lists==1.3 pymdown-extensions==9.9.2 jinja2==3.1.2 From 48e16f6aba7a4d2ed33958a473144e62e3cac32d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:57:18 +0000 Subject: [PATCH 06/19] Bump sqlalchemy from 2.0.4 to 2.0.5.post1 Bumps [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy) from 2.0.4 to 2.0.5.post1. - [Release notes](https://github.com/sqlalchemy/sqlalchemy/releases) - [Changelog](https://github.com/sqlalchemy/sqlalchemy/blob/main/CHANGES.rst) - [Commits](https://github.com/sqlalchemy/sqlalchemy/commits) --- updated-dependencies: - dependency-name: sqlalchemy dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a6b3ddd51..6eeecfde6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ pandas-ta==0.3.14b ccxt==2.8.98 cryptography==39.0.1 aiohttp==3.8.4 -SQLAlchemy==2.0.4 +SQLAlchemy==2.0.5.post1 python-telegram-bot==13.15 arrow==1.2.3 cachetools==4.2.2 From a57b033745558bc6e61de9704dfab3e2e5f20e1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:57:27 +0000 Subject: [PATCH 07/19] Bump types-python-dateutil from 2.8.19.9 to 2.8.19.10 Bumps [types-python-dateutil](https://github.com/python/typeshed) from 2.8.19.9 to 2.8.19.10. - [Release notes](https://github.com/python/typeshed/releases) - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-python-dateutil dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 2ba004f8d..a945ffc63 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -29,4 +29,4 @@ types-cachetools==5.3.0.4 types-filelock==3.2.7 types-requests==2.28.11.15 types-tabulate==0.9.0.1 -types-python-dateutil==2.8.19.9 +types-python-dateutil==2.8.19.10 From 9750e9ca4ef54d11f4525b79ea3ff9664b4a43e5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 6 Mar 2023 06:32:33 +0100 Subject: [PATCH 08/19] pre-commit python-dateutil --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 565eb96f7..402e5641d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - types-filelock==3.2.7 - types-requests==2.28.11.15 - types-tabulate==0.9.0.1 - - types-python-dateutil==2.8.19.9 + - types-python-dateutil==2.8.19.10 - SQLAlchemy==2.0.4 # stages: [push] From 25fd4a04d6460ed2a00af144d7fcb291669a1943 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 6 Mar 2023 06:34:37 +0100 Subject: [PATCH 09/19] Update sqlalchemy QueryPropertyDescriptor to match latest version --- .pre-commit-config.yaml | 2 +- freqtrade/persistence/pairlock.py | 5 ++--- freqtrade/persistence/trade_model.py | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 565eb96f7..895916c15 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - types-requests==2.28.11.15 - types-tabulate==0.9.0.1 - types-python-dateutil==2.8.19.9 - - SQLAlchemy==2.0.4 + - SQLAlchemy==2.0.5.post1 # stages: [push] - repo: https://github.com/pycqa/isort diff --git a/freqtrade/persistence/pairlock.py b/freqtrade/persistence/pairlock.py index a6d1eeaf0..1e5699145 100644 --- a/freqtrade/persistence/pairlock.py +++ b/freqtrade/persistence/pairlock.py @@ -2,8 +2,7 @@ from datetime import datetime, timezone from typing import Any, ClassVar, Dict, Optional from sqlalchemy import String, or_ -from sqlalchemy.orm import Mapped, Query, mapped_column -from sqlalchemy.orm.scoping import _QueryDescriptorType +from sqlalchemy.orm import Mapped, Query, QueryPropertyDescriptor, mapped_column from freqtrade.constants import DATETIME_PRINT_FORMAT from freqtrade.persistence.base import ModelBase, SessionType @@ -14,7 +13,7 @@ class PairLock(ModelBase): Pair Locks database model. """ __tablename__ = 'pairlocks' - query: ClassVar[_QueryDescriptorType] + query: ClassVar[QueryPropertyDescriptor] _session: ClassVar[SessionType] id: Mapped[int] = mapped_column(primary_key=True) diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 21fe80819..8e8a414c8 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -8,8 +8,8 @@ from math import isclose from typing import Any, ClassVar, Dict, List, Optional, cast from sqlalchemy import Enum, Float, ForeignKey, Integer, String, UniqueConstraint, desc, func -from sqlalchemy.orm import Mapped, Query, lazyload, mapped_column, relationship -from sqlalchemy.orm.scoping import _QueryDescriptorType +from sqlalchemy.orm import (Mapped, Query, QueryPropertyDescriptor, lazyload, mapped_column, + relationship) from freqtrade.constants import (DATETIME_PRINT_FORMAT, MATH_CLOSE_PREC, NON_OPEN_EXCHANGE_STATES, BuySell, LongShort) @@ -36,7 +36,7 @@ class Order(ModelBase): Mirrors CCXT Order structure """ __tablename__ = 'orders' - query: ClassVar[_QueryDescriptorType] + query: ClassVar[QueryPropertyDescriptor] _session: ClassVar[SessionType] # Uniqueness should be ensured over pair, order_id @@ -1181,7 +1181,7 @@ class Trade(ModelBase, LocalTrade): Note: Fields must be aligned with LocalTrade class """ __tablename__ = 'trades' - query: ClassVar[_QueryDescriptorType] + query: ClassVar[QueryPropertyDescriptor] _session: ClassVar[SessionType] use_db: bool = True From 0fe72510d5cbaa8389070cf75e1e4cedf880008d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 05:36:16 +0000 Subject: [PATCH 10/19] Bump pymdown-extensions from 9.9.2 to 9.10 Bumps [pymdown-extensions](https://github.com/facelessuser/pymdown-extensions) from 9.9.2 to 9.10. - [Release notes](https://github.com/facelessuser/pymdown-extensions/releases) - [Commits](https://github.com/facelessuser/pymdown-extensions/compare/9.9.2...9.10) --- updated-dependencies: - dependency-name: pymdown-extensions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs/requirements-docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 2ca11dabf..1b9a1f9b7 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -2,5 +2,5 @@ markdown==3.3.7 mkdocs==1.4.2 mkdocs-material==9.1.1 mdx_truly_sane_lists==1.3 -pymdown-extensions==9.9.2 +pymdown-extensions==9.10 jinja2==3.1.2 From de015a2d7e23e4d006e1cd84c7e12e1cd2378dad Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 18:04:30 +0100 Subject: [PATCH 11/19] Improve telegram message formatting --- freqtrade/rpc/telegram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 1a96b1671..e8a8a941f 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -510,14 +510,14 @@ class Telegram(RPCHandler): if prev_avg_price: minus_on_entry = (cur_entry_average - prev_avg_price) / prev_avg_price - lines.append(f"*{wording} #{order_nr}:* at {minus_on_entry:.2%} avg profit") + lines.append(f"*{wording} #{order_nr}:* at {minus_on_entry:.2%} avg Profit") if is_open: lines.append("({})".format(cur_entry_datetime .humanize(granularity=["day", "hour", "minute"]))) lines.append(f"*Amount:* {cur_entry_amount} " f"({round_coin_value(order['cost'], quote_currency)})") lines.append(f"*Average {wording} Price:* {cur_entry_average} " - f"({price_to_1st_entry:.2%} from 1st entry rate)") + f"({price_to_1st_entry:.2%} from 1st entry Rate)") lines.append(f"*Order filled:* {order['order_filled_date']}") # TODO: is this really useful? From 11eea9b4e1cef0a9bfceb27b37cfe8b7a10cc89f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 18:05:42 +0100 Subject: [PATCH 12/19] Fix formatting for /status Realized profit --- freqtrade/rpc/telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index e8a8a941f..7452005db 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -602,7 +602,7 @@ class Telegram(RPCHandler): if r['is_open']: if r.get('realized_profit'): lines.append( - "*Realized Profit:* `{realized_profit_r} {realized_profit_ratio:.2%}`") + "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`") lines.append("*Total Profit:* `{total_profit_abs_r}` ") if (r['stop_loss_abs'] != r['initial_stop_loss_abs'] From ca789b3282926c3e40f2be1e905034be001c2abb Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 18:11:10 +0100 Subject: [PATCH 13/19] /status - whitespace --- freqtrade/rpc/telegram.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 7452005db..2e87eabc9 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -594,7 +594,7 @@ class Telegram(RPCHandler): "*Close Rate:* `{close_rate:.8f}`" if r['close_rate'] else "", "*Open Date:* `{open_date}`", "*Close Date:* `{close_date}`" if r['close_date'] else "", - "*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "", + "\n*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "", ("*Unrealized Profit:* " if r['is_open'] else "*Close Profit: *") + "`{profit_ratio:.2%}` `({profit_abs_r})`", ]) @@ -605,6 +605,8 @@ class Telegram(RPCHandler): "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`") lines.append("*Total Profit:* `{total_profit_abs_r}` ") + # Append empty line to improve readability + lines.append(" ") if (r['stop_loss_abs'] != r['initial_stop_loss_abs'] and r['initial_stop_loss_ratio'] is not None): # Adding initial stoploss only if it is different from stoploss From fff08f737f29471ada06a336c4b0aefe0ec6c621 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 19:17:39 +0100 Subject: [PATCH 14/19] /status msg - improve formatting further --- freqtrade/rpc/telegram.py | 11 ++++++++--- tests/rpc/test_rpc_telegram.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 2e87eabc9..19027f4d5 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -569,6 +569,8 @@ class Telegram(RPCHandler): and not o['ft_order_side'] == 'stoploss']) r['exit_reason'] = r.get('exit_reason', "") r['stake_amount_r'] = round_coin_value(r['stake_amount'], r['quote_currency']) + r['max_stake_amount_r'] = round_coin_value( + r['max_stake_amount'] or r['stake_amount'], r['quote_currency']) r['profit_abs_r'] = round_coin_value(r['profit_abs'], r['quote_currency']) r['realized_profit_r'] = round_coin_value(r['realized_profit'], r['quote_currency']) r['total_profit_abs_r'] = round_coin_value( @@ -580,21 +582,24 @@ class Telegram(RPCHandler): f"*Direction:* {'`Short`' if r.get('is_short') else '`Long`'}" + " ` ({leverage}x)`" if r.get('leverage') else "", "*Amount:* `{amount} ({stake_amount_r})`", + "*Total invested:* `{max_stake_amount_r}`" if position_adjust else "", "*Enter Tag:* `{enter_tag}`" if r['enter_tag'] else "", "*Exit Reason:* `{exit_reason}`" if r['exit_reason'] else "", ] if position_adjust: max_buy_str = (f"/{max_entries + 1}" if (max_entries > 0) else "") - lines.append("*Number of Entries:* `{num_entries}" + max_buy_str + "`") - lines.append("*Number of Exits:* `{num_exits}`") + lines.extend([ + "*Number of Entries:* `{num_entries}" + max_buy_str + "`", + "*Number of Exits:* `{num_exits}`" + ]) lines.extend([ "*Open Rate:* `{open_rate:.8f}`", "*Close Rate:* `{close_rate:.8f}`" if r['close_rate'] else "", "*Open Date:* `{open_date}`", "*Close Date:* `{close_date}`" if r['close_date'] else "", - "\n*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "", + " \n*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "", ("*Unrealized Profit:* " if r['is_open'] else "*Close Profit: *") + "`{profit_ratio:.2%}` `({profit_abs_r})`", ]) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 69d0f805d..1dc255b3e 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -198,6 +198,7 @@ def test_telegram_status(default_conf, update, mocker) -> None: 'current_rate': 1.098e-05, 'amount': 90.99181074, 'stake_amount': 90.99181074, + 'max_stake_amount': 90.99181074, 'buy_tag': None, 'enter_tag': None, 'close_profit_ratio': None, From 9d285e3dc04e1b4c2c0ae1d01a17198f4f0cac86 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 19:35:06 +0100 Subject: [PATCH 15/19] Add total_profit_ratio to telegram output part of #8234 --- freqtrade/rpc/rpc.py | 6 ++++++ freqtrade/rpc/telegram.py | 7 ++++--- tests/rpc/test_rpc.py | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 8692c477f..4b3f6209e 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -192,6 +192,11 @@ class RPC: current_profit = trade.close_profit or 0.0 current_profit_abs = trade.close_profit_abs or 0.0 total_profit_abs = trade.realized_profit + current_profit_abs + total_profit_ratio = 0.0 + if trade.max_stake_amount: + total_profit_ratio = ( + (total_profit_abs / trade.max_stake_amount) * trade.leverage + ) # Calculate fiat profit if not isnan(current_profit_abs) and self._fiat_converter: @@ -224,6 +229,7 @@ class RPC: total_profit_abs=total_profit_abs, total_profit_fiat=total_profit_fiat, + total_profit_ratio=total_profit_ratio, stoploss_current_dist=stoploss_current_dist, stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8), stoploss_current_dist_pct=round(stoploss_current_dist_ratio * 100, 2), diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 19027f4d5..ced1bb5ca 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -606,9 +606,10 @@ class Telegram(RPCHandler): if r['is_open']: if r.get('realized_profit'): - lines.append( - "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`") - lines.append("*Total Profit:* `{total_profit_abs_r}` ") + lines.extend([ + "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`" + "*Total Profit:* `{total_profit_ratio:.2%} ({total_profit_abs_r})`" + ]) # Append empty line to improve readability lines.append(" ") diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index cd72da763..cf7d2bdeb 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -79,6 +79,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'realized_profit_ratio': None, 'total_profit_abs': -4.09e-06, 'total_profit_fiat': ANY, + 'total_profit_ratio': ANY, 'exchange': 'binance', 'leverage': 1.0, 'interest_rate': 0.0, @@ -185,6 +186,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'profit_pct': ANY, 'profit_abs': ANY, 'total_profit_abs': ANY, + 'total_profit_ratio': ANY, 'current_rate': ANY, }) assert results[0] == response_norate From cab1b750b35f4d356d64206c2b20aa2cb338f167 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Mar 2023 19:45:04 +0100 Subject: [PATCH 16/19] Improve test accuracy --- freqtrade/rpc/rpc.py | 2 +- tests/rpc/test_rpc.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 4b3f6209e..c68ed2d48 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -192,7 +192,7 @@ class RPC: current_profit = trade.close_profit or 0.0 current_profit_abs = trade.close_profit_abs or 0.0 total_profit_abs = trade.realized_profit + current_profit_abs - total_profit_ratio = 0.0 + total_profit_ratio: Optional[float] = None if trade.max_stake_amount: total_profit_ratio = ( (total_profit_abs / trade.max_stake_amount) * trade.leverage diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index cf7d2bdeb..1a1802c68 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -50,7 +50,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'amount': 91.07468123, 'amount_requested': 91.07468124, 'stake_amount': 0.001, - 'max_stake_amount': ANY, + 'max_stake_amount': None, 'trade_duration': None, 'trade_duration_s': None, 'close_profit': None, @@ -79,7 +79,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'realized_profit_ratio': None, 'total_profit_abs': -4.09e-06, 'total_profit_fiat': ANY, - 'total_profit_ratio': ANY, + 'total_profit_ratio': None, 'exchange': 'binance', 'leverage': 1.0, 'interest_rate': 0.0, @@ -169,6 +169,10 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: results = rpc._rpc_trade_status() response = deepcopy(gen_response) + response.update({ + 'max_stake_amount': 0.001, + 'total_profit_ratio': pytest.approx(-0.00409), + }) assert results[0] == response mocker.patch(f'{EXMS}.get_rate', @@ -182,6 +186,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'stoploss_current_dist': ANY, 'stoploss_current_dist_ratio': ANY, 'stoploss_current_dist_pct': ANY, + 'max_stake_amount': 0.001, 'profit_ratio': ANY, 'profit_pct': ANY, 'profit_abs': ANY, From c4a80e33ea3e647fab91efd4ace1c8de3f4afc6b Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 6 Mar 2023 07:01:17 +0100 Subject: [PATCH 17/19] Fix missing newline in telegram /status --- freqtrade/rpc/telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index ced1bb5ca..30aa55359 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -607,7 +607,7 @@ class Telegram(RPCHandler): if r['is_open']: if r.get('realized_profit'): lines.extend([ - "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`" + "*Realized Profit:* `{realized_profit_ratio:.2%} ({realized_profit_r})`", "*Total Profit:* `{total_profit_ratio:.2%} ({total_profit_abs_r})`" ]) From d779d60812f29553d029182e7b8b7907c2d5fea0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 6 Mar 2023 07:10:02 +0100 Subject: [PATCH 18/19] Expose total_profit_ratio through API --- freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/rpc/api_server/api_v1.py | 3 ++- tests/rpc/test_rpc_apiserver.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index a751179b2..064a509fd 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -286,6 +286,7 @@ class OpenTradeSchema(TradeSchema): current_rate: float total_profit_abs: float total_profit_fiat: Optional[float] + total_profit_ratio: Optional[float] open_order: Optional[str] diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index f6bab3624..8ea70bb69 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -42,7 +42,8 @@ logger = logging.getLogger(__name__) # 2.22: Add FreqAI to backtesting # 2.23: Allow plot config request in webserver mode # 2.24: Add cancel_open_order endpoint -API_VERSION = 2.24 +# 2.25: Add several profit values to /status endpoint +API_VERSION = 2.25 # Public API, requires no auth. router_public = APIRouter() diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index e140a43f1..9c2c3ee3a 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1012,6 +1012,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short, 'profit_fiat': ANY, 'total_profit_abs': ANY, 'total_profit_fiat': ANY, + 'total_profit_ratio': ANY, 'realized_profit': 0.0, 'realized_profit_ratio': None, 'current_rate': current_rate, From 85e64cd1215b4ef2e0d323fe4be08db90d1d884c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 07:21:23 +0000 Subject: [PATCH 19/19] Bump ccxt from 2.8.98 to 2.9.4 Bumps [ccxt](https://github.com/ccxt/ccxt) from 2.8.98 to 2.9.4. - [Release notes](https://github.com/ccxt/ccxt/releases) - [Changelog](https://github.com/ccxt/ccxt/blob/master/CHANGELOG.md) - [Commits](https://github.com/ccxt/ccxt/compare/2.8.98...2.9.4) --- updated-dependencies: - dependency-name: ccxt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a702507f9..c972ae1d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ numpy==1.24.2 pandas==1.5.3 pandas-ta==0.3.14b -ccxt==2.8.98 +ccxt==2.9.4 cryptography==39.0.2 aiohttp==3.8.4 SQLAlchemy==2.0.5.post1