From 412b50dac5471e5392395c771298fbb118dcc8bb Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 4 Jun 2020 06:56:59 +0200 Subject: [PATCH] Add current stoploss calculations --- freqtrade/rpc/rpc.py | 13 +++++++++++++ tests/rpc/test_rpc_apiserver.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 91b35e9ad..dd6b084a2 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -130,6 +130,14 @@ class RPC: except DependencyException: current_rate = NAN current_profit = trade.calc_profit_ratio(current_rate) + current_profit_abs = trade.calc_profit(current_rate) + # Calculate guaranteed profit (in case of trailing stop) + stoploss_entrypoint_dist = trade.open_rate - trade.stop_loss + stoploss_entrypoint_dist_ratio = stoploss_entrypoint_dist / trade.stop_loss + # calculate distance to stoploss + stoploss_current_dist = trade.stop_loss - current_rate + stoploss_current_dist_ratio = stoploss_current_dist / current_rate + fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%' if trade.close_profit is not None else None) trade_dict = trade.to_json() @@ -140,6 +148,11 @@ class RPC: current_rate=current_rate, current_profit=current_profit, current_profit_pct=round(current_profit * 100, 2), + current_profit_abs=current_profit_abs, + stoploss_current_dist=stoploss_current_dist, + stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8), + stoploss_entrypoint_dist=stoploss_entrypoint_dist, + stoploss_entrypoint_dist_ratio=round(stoploss_entrypoint_dist_ratio, 8), open_order='({} {} rem={:.8f})'.format( order['type'], order['side'], order['remaining'] ) if order else None, diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 8743ec7ba..906e9f2fe 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -533,6 +533,10 @@ def test_api_status(botclient, mocker, ticker, fee, markets): 'initial_stop_loss_abs': 9.882e-06, 'initial_stop_loss_pct': -10.0, 'initial_stop_loss_ratio': -0.1, + 'stoploss_current_dist': -1.1080000000000002e-06, + 'stoploss_current_dist_ratio': -0.10081893, + 'stoploss_entrypoint_dist': 1.0980000000000003e-06, + 'stoploss_entrypoint_dist_ratio': 0.11111111, 'trade_id': 1, 'close_rate_requested': None, 'current_rate': 1.099e-05,