From 7a47500b22ae5781f643fc6584662ed0e01af505 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 14:57:13 +0200 Subject: [PATCH 1/8] Add "is_bot_managed" flag to API --- freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/rpc/api_server/api_v1.py | 3 ++- freqtrade/rpc/rpc.py | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 53bf7558f..a9dc6243e 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -43,6 +43,7 @@ class Balance(BaseModel): leverage: float is_position: bool position: float + is_bot_managed: bool class Balances(BaseModel): diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index 8aa706e62..5ee5e36c4 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -43,7 +43,8 @@ logger = logging.getLogger(__name__) # 2.23: Allow plot config request in webserver mode # 2.24: Add cancel_open_order endpoint # 2.25: Add several profit values to /status endpoint -API_VERSION = 2.25 +# 2.26: increase /balance output +API_VERSION = 2.26 # Public API, requires no auth. router_public = APIRouter() diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 814f0d6a8..a0b588bfa 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -631,7 +631,8 @@ class RPC: continue total += est_stake - if coin == stake_currency or coin in open_assets: + is_bot_managed = coin == stake_currency or coin in open_assets + if is_bot_managed: total_bot += est_stake currencies.append({ 'currency': coin, @@ -643,6 +644,7 @@ class RPC: 'side': 'long', 'leverage': 1, 'position': 0, + 'is_bot_managed': is_bot_managed, 'is_position': False, }) symbol: str @@ -660,6 +662,7 @@ class RPC: 'stake': stake_currency, 'leverage': position.leverage, 'side': position.side, + 'is_bot_managed': True, 'is_position': True }) From dbf1f0897e2bbcb2dd220d20f8d05af5cc8eb99d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 15:51:28 +0200 Subject: [PATCH 2/8] Add /balance full, reduce regular balance output closes #4497 --- docs/telegram-usage.md | 4 ++-- freqtrade/rpc/rpc.py | 2 ++ freqtrade/rpc/telegram.py | 23 +++++++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index fe990790a..e6017e271 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -191,7 +191,8 @@ official commands. You can ask at any moment for help with `/help`. | **Metrics** | | `/profit []` | Display a summary of your profit/loss from close trades and some stats about your performance, over the last n days (all trades by default) | `/performance` | Show performance of each finished trade grouped by pair -| `/balance` | Show account balance per currency +| `/balance` | Show bot managed balance per currency +| `/balance full` | Show account balance per currency | `/daily ` | Shows profit or loss per day, over the last n days (n defaults to 7) | `/weekly ` | Shows profit or loss per week, over the last n weeks (n defaults to 8) | `/monthly ` | Shows profit or loss per month, over the last n months (n defaults to 6) @@ -202,7 +203,6 @@ official commands. You can ask at any moment for help with `/help`. | `/blacklist [pair]` | Show the current blacklist, or adds a pair to the blacklist. | `/edge` | Show validated pairs by Edge if it is enabled. - ## Telegram commands in action Below, example of Telegram message you will receive for each command. diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index a0b588bfa..addd2bd02 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -678,8 +678,10 @@ class RPC: return { 'currencies': currencies, 'total': total, + 'total_bot': total_bot, 'symbol': fiat_display_currency, 'value': value, + 'value_bot': value_bot, 'stake': stake_currency, 'starting_capital': starting_capital, 'starting_capital_ratio': starting_capital_ratio, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index e626ee598..c4feb588a 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -905,6 +905,7 @@ class Telegram(RPCHandler): @authorized_only def _balance(self, update: Update, context: CallbackContext) -> None: """ Handler for /balance """ + full_result = context.args and 'full' in context.args result = self._rpc._rpc_balance(self._config['stake_currency'], self._config.get('fiat_display_currency', '')) @@ -928,7 +929,7 @@ class Telegram(RPCHandler): total_dust_currencies = 0 for curr in result['currencies']: curr_output = '' - if curr['est_stake'] > balance_dust_level: + if curr['est_stake'] > balance_dust_level and (full_result or curr['is_bot_managed']): if curr['is_position']: curr_output = ( f"*{curr['currency']}:*\n" @@ -965,14 +966,15 @@ class Telegram(RPCHandler): tc = result['trade_count'] > 0 stake_improve = f" `({result['starting_capital_ratio']:.2%})`" if tc else '' fiat_val = f" `({result['starting_capital_fiat_ratio']:.2%})`" if tc else '' - - output += ("\n*Estimated Value*:\n" - f"\t`{result['stake']}: " - f"{round_coin_value(result['total'], result['stake'], False)}`" - f"{stake_improve}\n" - f"\t`{result['symbol']}: " - f"{round_coin_value(result['value'], result['symbol'], False)}`" - f"{fiat_val}\n") + value = round_coin_value( + result['value' if full_result else 'value_bot'], result['symbol'], False) + total_stake = round_coin_value( + result['total' if full_result else 'total_bot'], result['stake'], False) + output += ( + f"\n*Estimated Value{' (Bot managed assets only)' if not full_result else ''}*:\n" + f"\t`{result['stake']}: {total_stake}`{stake_improve}\n" + f"\t`{result['symbol']}: {value}`{fiat_val}\n" + ) self._send_msg(output, reload_able=True, callback_path="update_balance", query=update.callback_query) @@ -1528,7 +1530,8 @@ class Telegram(RPCHandler): "------------\n" "*/show_config:* `Show running configuration` \n" "*/locks:* `Show currently locked pairs`\n" - "*/balance:* `Show account balance per currency`\n" + "*/balance:* `Show bot managed balance per currency`\n" + "*/balance total:* `Show account balance per currency`\n" "*/logs [limit]:* `Show latest logs - defaults to 10` \n" "*/count:* `Show number of active trades compared to allowed number of trades`\n" "*/edge:* `Shows validated pairs by Edge if it is enabled` \n" From c4f8ff95ddd263e2c2f49a066889598c92d98e74 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 16:13:27 +0200 Subject: [PATCH 3/8] Update tests --- freqtrade/rpc/api_server/api_schemas.py | 2 ++ tests/rpc/test_rpc.py | 7 ++++++- tests/rpc/test_rpc_apiserver.py | 3 +++ tests/rpc/test_rpc_telegram.py | 15 +++++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index a9dc6243e..20144d2c8 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -49,8 +49,10 @@ class Balance(BaseModel): class Balances(BaseModel): currencies: List[Balance] total: float + total_bot: float symbol: str value: float + value_bot: float stake: str note: str starting_capital: float diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 5a84eaa48..d675ffe4e 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -552,6 +552,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'leverage': 1.0, 'position': 0.0, 'side': 'long', + 'is_bot_managed': True, }, { 'free': 1.0, @@ -564,7 +565,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'leverage': 1.0, 'position': 0.0, 'side': 'long', - + 'is_bot_managed': False, }, { 'free': 5.0, @@ -577,6 +578,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'leverage': 1.0, 'position': 0.0, 'side': 'long', + 'is_bot_managed': False, }, { 'free': 0.0, @@ -589,8 +591,11 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'leverage': 5.0, 'position': 1000.0, 'side': 'short', + 'is_bot_managed': True, } ] + assert pytest.approx(result['total_bot']) == 10 + assert pytest.approx(result['total']) == 30.309096 assert result['starting_capital'] == 10 assert result['starting_capital_ratio'] == 0.0 diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 58c904838..ad7543430 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -486,7 +486,10 @@ def test_api_balance(botclient, mocker, rpc_balance, tickers): 'leverage': 1.0, 'position': 0.0, 'side': 'long', + 'is_bot_managed': True, } + assert response['total'] == 12.159513094 + assert response['total_bot'] == 12.0 assert 'starting_capital' in response assert 'starting_capital_fiat' in response assert 'starting_capital_pct' in response diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 7978a2a23..a672c62f6 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -783,19 +783,27 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick patch_get_signal(freqtradebot) telegram._balance(update=update, context=MagicMock()) + context = MagicMock() + context.args = ["full"] + telegram._balance(update=update, context=context) result = msg_mock.call_args_list[0][0][0] - assert msg_mock.call_count == 1 + result_full = msg_mock.call_args_list[1][0][0] + assert msg_mock.call_count == 2 assert '*BTC:*' in result assert '*ETH:*' not in result assert '*USDT:*' not in result assert '*EUR:*' not in result - assert '*LTC:*' in result + assert '*LTC:*' not in result + + assert '*LTC:*' in result_full assert '*XRP:*' not in result assert 'Balance:' in result assert 'Est. BTC:' in result assert 'BTC: 12' in result assert "*3 Other Currencies (< 0.0001 BTC):*" in result assert 'BTC: 0.00000309' in result + assert '*Estimated Value*:' in result_full + assert '*Estimated Value (Bot managed assets only)*:' in result def test_balance_handle_empty_response(default_conf, update, mocker) -> None: @@ -840,12 +848,15 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None 'leverage': 1.0, 'position': 0.0, 'side': 'long', + 'is_bot_managed': True, }) mocker.patch('freqtrade.rpc.rpc.RPC._rpc_balance', return_value={ 'currencies': balances, 'total': 100.0, + 'total_bot': 100.0, 'symbol': 100.0, 'value': 1000.0, + 'value_bot': 1000.0, 'starting_capital': 1000, 'starting_capital_fiat': 1000, }) From f937818b800343cf94d7f70d6368ab7b12c8677c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 17:13:53 +0200 Subject: [PATCH 4/8] Add "owned" fields to balance --- freqtrade/rpc/api_server/api_schemas.py | 2 ++ freqtrade/rpc/rpc.py | 24 ++++++++++++++++++------ freqtrade/rpc/telegram.py | 11 +++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 20144d2c8..dd5ca3a62 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -36,7 +36,9 @@ class Balance(BaseModel): free: float balance: float used: float + bot_owned: Optional[float] est_stake: float + est_stake_bot: Optional[float] stake: str # Starting with 2.x side: str diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index addd2bd02..06cf61dff 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -583,13 +583,16 @@ class RPC: } def __balance_get_est_stake( - self, coin: str, stake_currency: str, balance: Wallet, tickers) -> float: + self, coin: str, stake_currency: str, amount: float, + balance: Wallet, tickers) -> Tuple[float, float]: est_stake = 0.0 + est_bot_stake = 0.0 if coin == stake_currency: est_stake = balance.total if self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT: # in Futures, "total" includes the locked stake, and therefore all positions est_stake = balance.free + est_bot_stake = est_stake else: try: pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) @@ -598,11 +601,12 @@ class RPC: if pair.startswith(stake_currency) and not pair.endswith(stake_currency): rate = 1.0 / rate est_stake = rate * balance.total + est_bot_stake = rate * amount except (ExchangeError): logger.warning(f"Could not get rate for pair {coin}.") raise ValueError() - return est_stake + return est_stake, est_bot_stake def _rpc_balance(self, stake_currency: str, fiat_display_currency: str) -> Dict: """ Returns current account balance per crypto """ @@ -615,7 +619,7 @@ class RPC: raise RPCException('Error getting current tickers.') open_trades: List[Trade] = Trade.get_open_trades() - open_assets = [t.base_currency for t in open_trades] + open_assets: Dict[str, Trade] = {t.safe_base_currency: t for t in open_trades} self._freqtrade.wallets.update(require_update=False) starting_capital = self._freqtrade.wallets.get_starting_balance() starting_cap_fiat = self._fiat_converter.convert_amount( @@ -625,21 +629,29 @@ class RPC: for coin, balance in self._freqtrade.wallets.get_all_balances().items(): if not balance.total: continue + + trade = open_assets.get(coin, None) + is_bot_managed = coin == stake_currency or trade is not None + trade_amount = trade.amount if trade else 0 + try: - est_stake = self.__balance_get_est_stake(coin, stake_currency, balance, tickers) + est_stake, est_stake_bot = self.__balance_get_est_stake( + coin, stake_currency, trade_amount, balance, tickers) except ValueError: continue total += est_stake - is_bot_managed = coin == stake_currency or coin in open_assets + if is_bot_managed: - total_bot += est_stake + total_bot += est_stake_bot currencies.append({ 'currency': coin, 'free': balance.free, 'balance': balance.total, 'used': balance.used, + 'bot_owned': trade_amount, 'est_stake': est_stake or 0, + 'est_stake_bot': est_stake_bot if is_bot_managed else 0, 'stake': stake_currency, 'side': 'long', 'leverage': 1, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index c4feb588a..2b997efac 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -916,8 +916,7 @@ class Telegram(RPCHandler): output = '' if self._config['dry_run']: output += "*Warning:* Simulated balances in Dry Mode.\n" - starting_cap = round_coin_value( - result['starting_capital'], self._config['stake_currency']) + starting_cap = round_coin_value(result['starting_capital'], self._config['stake_currency']) output += f"Starting capital: `{starting_cap}`" starting_cap_fiat = round_coin_value( result['starting_capital_fiat'], self._config['fiat_display_currency'] @@ -938,13 +937,17 @@ class Telegram(RPCHandler): f"\t`Est. {curr['stake']}: " f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n") else: + est_stake = round_coin_value( + curr['est_stake' if full_result else 'est_stake_bot'], curr['stake'], False) + curr_output = ( f"*{curr['currency']}:*\n" f"\t`Available: {curr['free']:.8f}`\n" f"\t`Balance: {curr['balance']:.8f}`\n" f"\t`Pending: {curr['used']:.8f}`\n" - f"\t`Est. {curr['stake']}: " - f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n") + f"\t`Bot Owned: {curr['bot_owned']:.8f}`\n" + f"\t`Est. {curr['stake']}: {est_stake}`\n") + elif curr['est_stake'] <= balance_dust_level: total_dust_balance += curr['est_stake'] total_dust_currencies += 1 From 741834301f24630a209663b375cdb2326913fb27 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 17:21:03 +0200 Subject: [PATCH 5/8] Update tests --- tests/rpc/test_rpc.py | 6 ++++++ tests/rpc/test_rpc_telegram.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index d675ffe4e..34095f4f2 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -546,7 +546,9 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'free': 10.0, 'balance': 12.0, 'used': 2.0, + 'bot_owned': 0, 'est_stake': 10.0, # In futures mode, "free" is used here. + 'est_stake_bot': 10, 'stake': 'BTC', 'is_position': False, 'leverage': 1.0, @@ -558,7 +560,9 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'free': 1.0, 'balance': 5.0, 'currency': 'ETH', + 'bot_owned': 0, 'est_stake': 0.30794, + 'est_stake_bot': 0, 'used': 4.0, 'stake': 'BTC', 'is_position': False, @@ -571,7 +575,9 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'free': 5.0, 'balance': 10.0, 'currency': 'USDT', + 'bot_owned': 0, 'est_stake': 0.0011562404610161968, + 'est_stake_bot': 0, 'used': 5.0, 'stake': 'BTC', 'is_position': False, diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index a672c62f6..97ac03c9f 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -842,7 +842,9 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None 'free': 1.0, 'used': 0.5, 'balance': i, + 'bot_owned': 0.5, 'est_stake': 1, + 'est_stake_bot': 1, 'stake': 'BTC', 'is_position': False, 'leverage': 1.0, From 94a6bc608ca78cb8eff7a0bc46cab3e254b72fa0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 17:42:09 +0200 Subject: [PATCH 6/8] Update stake-currency behavior --- freqtrade/rpc/rpc.py | 2 ++ tests/rpc/test_rpc.py | 2 +- tests/rpc/test_rpc_apiserver.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 06cf61dff..222912aa0 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -633,6 +633,8 @@ class RPC: trade = open_assets.get(coin, None) is_bot_managed = coin == stake_currency or trade is not None trade_amount = trade.amount if trade else 0 + if coin == stake_currency: + trade_amount = self._freqtrade.wallets.get_available_stake_amount() try: est_stake, est_stake_bot = self.__balance_get_est_stake( diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 34095f4f2..5335cebf9 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -546,7 +546,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'free': 10.0, 'balance': 12.0, 'used': 2.0, - 'bot_owned': 0, + 'bot_owned': 9.9, # available stake - reducing by reserved amount 'est_stake': 10.0, # In futures mode, "free" is used here. 'est_stake_bot': 10, 'stake': 'BTC', diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index ad7543430..a4638a07e 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -480,7 +480,9 @@ def test_api_balance(botclient, mocker, rpc_balance, tickers): 'free': 12.0, 'balance': 12.0, 'used': 0.0, + 'bot_owned': pytest.approx(11.879999), 'est_stake': 12.0, + 'est_stake_bot': 12.0, 'stake': 'BTC', 'is_position': False, 'leverage': 1.0, From 68a8c79c08fab763605c6ea2ee4acd8e093d7608 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 24 Apr 2023 12:03:00 +0200 Subject: [PATCH 7/8] Improve output for futures --- freqtrade/rpc/rpc.py | 4 +++- freqtrade/rpc/telegram.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 222912aa0..35e08cbc0 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -592,7 +592,7 @@ class RPC: if self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT: # in Futures, "total" includes the locked stake, and therefore all positions est_stake = balance.free - est_bot_stake = est_stake + est_bot_stake = amount else: try: pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) @@ -665,6 +665,7 @@ class RPC: position: PositionWallet for symbol, position in self._freqtrade.wallets.get_all_positions().items(): total += position.collateral + total_bot += position.collateral currencies.append({ 'currency': symbol, @@ -673,6 +674,7 @@ class RPC: 'used': 0, 'position': position.position, 'est_stake': position.collateral, + 'est_stake_bot': position.collateral, 'stake': stake_currency, 'leverage': position.leverage, 'side': position.side, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 2b997efac..e99501cc0 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -928,7 +928,10 @@ class Telegram(RPCHandler): total_dust_currencies = 0 for curr in result['currencies']: curr_output = '' - if curr['est_stake'] > balance_dust_level and (full_result or curr['is_bot_managed']): + if ( + (curr['is_position'] or curr['est_stake'] > balance_dust_level) + and (full_result or curr['is_bot_managed']) + ): if curr['is_position']: curr_output = ( f"*{curr['currency']}:*\n" From 8086d9053573b7c4aef6afdc1ab18e9085d1eac0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 24 Apr 2023 12:12:45 +0200 Subject: [PATCH 8/8] Update some tests for balance updates --- tests/rpc/test_rpc.py | 9 ++++++--- tests/rpc/test_rpc_apiserver.py | 4 ++-- tests/rpc/test_rpc_telegram.py | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 5335cebf9..bb84ff8e9 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -548,7 +548,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'used': 2.0, 'bot_owned': 9.9, # available stake - reducing by reserved amount 'est_stake': 10.0, # In futures mode, "free" is used here. - 'est_stake_bot': 10, + 'est_stake_bot': 9.9, 'stake': 'BTC', 'is_position': False, 'leverage': 1.0, @@ -591,6 +591,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'balance': 0.0, 'currency': 'ETH/USDT:USDT', 'est_stake': 20, + 'est_stake_bot': 20, 'used': 0, 'stake': 'BTC', 'is_position': True, @@ -600,10 +601,12 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): 'is_bot_managed': True, } ] - assert pytest.approx(result['total_bot']) == 10 + assert pytest.approx(result['total_bot']) == 29.9 assert pytest.approx(result['total']) == 30.309096 assert result['starting_capital'] == 10 - assert result['starting_capital_ratio'] == 0.0 + # Very high starting capital ratio, because the futures position really has the wrong unit. + # TODO: improve this test (see comment above) + assert result['starting_capital_ratio'] == pytest.approx(1.98999999) def test_rpc_start(mocker, default_conf) -> None: diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index a4638a07e..e045bf487 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -482,7 +482,7 @@ def test_api_balance(botclient, mocker, rpc_balance, tickers): 'used': 0.0, 'bot_owned': pytest.approx(11.879999), 'est_stake': 12.0, - 'est_stake_bot': 12.0, + 'est_stake_bot': pytest.approx(11.879999), 'stake': 'BTC', 'is_position': False, 'leverage': 1.0, @@ -491,7 +491,7 @@ def test_api_balance(botclient, mocker, rpc_balance, tickers): 'is_bot_managed': True, } assert response['total'] == 12.159513094 - assert response['total_bot'] == 12.0 + assert response['total_bot'] == pytest.approx(11.879999) assert 'starting_capital' in response assert 'starting_capital_fiat' in response assert 'starting_capital_pct' in response diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 97ac03c9f..9b22b73c0 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -799,7 +799,8 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick assert '*XRP:*' not in result assert 'Balance:' in result assert 'Est. BTC:' in result - assert 'BTC: 12' in result + assert 'BTC: 11' in result + assert 'BTC: 12' in result_full assert "*3 Other Currencies (< 0.0001 BTC):*" in result assert 'BTC: 0.00000309' in result assert '*Estimated Value*:' in result_full