From adde1cfee2591820fb09db55b0957f57880be05b Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 1 Jun 2020 10:53:02 +0200 Subject: [PATCH 1/3] Add stoplosss_ratio and initial_stoploss_ratio --- freqtrade/persistence.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index 111ccfe2a..2fe93f440 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -249,32 +249,40 @@ class Trade(_DECL_BASE): 'trade_id': self.id, 'pair': self.pair, 'is_open': self.is_open, + 'exchange': self.exchange, + 'amount': round(self.amount, 8), + 'stake_amount': round(self.stake_amount, 8), + 'strategy': self.strategy, + 'ticker_interval': self.ticker_interval, + 'fee_open': self.fee_open, 'fee_open_cost': self.fee_open_cost, 'fee_open_currency': self.fee_open_currency, 'fee_close': self.fee_close, 'fee_close_cost': self.fee_close_cost, 'fee_close_currency': self.fee_close_currency, + 'open_date_hum': arrow.get(self.open_date).humanize(), 'open_date': self.open_date.strftime("%Y-%m-%d %H:%M:%S"), 'open_timestamp': int(self.open_date.timestamp() * 1000), + 'open_rate': self.open_rate, + 'open_rate_requested': self.open_rate_requested, + 'open_trade_price': self.open_trade_price, + 'close_date_hum': (arrow.get(self.close_date).humanize() if self.close_date else None), 'close_date': (self.close_date.strftime("%Y-%m-%d %H:%M:%S") if self.close_date else None), 'close_timestamp': int(self.close_date.timestamp() * 1000) if self.close_date else None, - 'open_rate': self.open_rate, - 'open_rate_requested': self.open_rate_requested, - 'open_trade_price': self.open_trade_price, 'close_rate': self.close_rate, 'close_rate_requested': self.close_rate_requested, - 'amount': round(self.amount, 8), - 'stake_amount': round(self.stake_amount, 8), 'close_profit': self.close_profit, 'close_profit_abs': self.close_profit_abs, + 'sell_reason': self.sell_reason, 'sell_order_status': self.sell_order_status, 'stop_loss': self.stop_loss, + 'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None, 'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None, 'stoploss_order_id': self.stoploss_order_id, 'stoploss_last_update': (self.stoploss_last_update.strftime("%Y-%m-%d %H:%M:%S") @@ -282,14 +290,14 @@ class Trade(_DECL_BASE): 'stoploss_last_update_timestamp': (int(self.stoploss_last_update.timestamp() * 1000) if self.stoploss_last_update else None), 'initial_stop_loss': self.initial_stop_loss, + 'initial_stop_loss_ratio': (self.initial_stop_loss_pct + if self.initial_stop_loss_pct else None), 'initial_stop_loss_pct': (self.initial_stop_loss_pct * 100 if self.initial_stop_loss_pct else None), 'min_rate': self.min_rate, 'max_rate': self.max_rate, - 'strategy': self.strategy, - 'ticker_interval': self.ticker_interval, + 'open_order_id': self.open_order_id, - 'exchange': self.exchange, } def adjust_min_max_rates(self, current_price: float) -> None: From 6dec508c5eb3a0106525f16428f27d4cc7b99b6f Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 1 Jun 2020 10:56:05 +0200 Subject: [PATCH 2/3] Add new fields to tests --- tests/rpc/test_rpc.py | 4 ++++ tests/rpc/test_rpc_apiserver.py | 14 +++++++++----- tests/test_persistence.py | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 7b7824310..dcd525574 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -82,11 +82,13 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'current_profit_pct': -0.41, 'stop_loss': 0.0, 'stop_loss_pct': None, + 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': 0.0, 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'open_order': '(limit buy rem=0.00000000)', 'exchange': 'bittrex', @@ -136,11 +138,13 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'current_profit_pct': ANY, 'stop_loss': 0.0, 'stop_loss_pct': None, + 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': 0.0, 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'open_order': '(limit buy rem=0.00000000)', 'exchange': 'bittrex', } == results[0] diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index c7f937b0c..13914fab0 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -510,8 +510,6 @@ def test_api_status(botclient, mocker, ticker, fee, markets): 'current_profit': -0.00408133, 'current_profit_pct': -0.41, 'current_rate': 1.099e-05, - 'initial_stop_loss': 0.0, - 'initial_stop_loss_pct': None, 'open_date': ANY, 'open_date_hum': 'just now', 'open_timestamp': ANY, @@ -521,9 +519,13 @@ def test_api_status(botclient, mocker, ticker, fee, markets): 'stake_amount': 0.001, 'stop_loss': 0.0, 'stop_loss_pct': None, + 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, + 'initial_stop_loss': 0.0, + 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'trade_id': 1, 'close_rate_requested': None, 'current_rate': 1.099e-05, @@ -622,12 +624,11 @@ def test_api_forcebuy(botclient, mocker, fee): data='{"pair": "ETH/BTC"}') assert_response(rc) assert rc.json == {'amount': 1, + 'trade_id': None, 'close_date': None, 'close_date_hum': None, 'close_timestamp': None, 'close_rate': 0.265441, - 'initial_stop_loss': None, - 'initial_stop_loss_pct': None, 'open_date': ANY, 'open_date_hum': 'just now', 'open_timestamp': ANY, @@ -636,10 +637,13 @@ def test_api_forcebuy(botclient, mocker, fee): 'stake_amount': 1, 'stop_loss': None, 'stop_loss_pct': None, + 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, - 'trade_id': None, + 'initial_stop_loss': None, + 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'close_profit': None, 'close_profit_abs': None, 'close_rate_requested': None, diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 3b1041fd8..942e22a19 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -762,12 +762,14 @@ def test_to_json(default_conf, fee): 'sell_reason': None, 'sell_order_status': None, 'stop_loss': None, + 'stop_loss_ratio': None, 'stop_loss_pct': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': None, 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'min_rate': None, 'max_rate': None, 'strategy': None, @@ -805,11 +807,13 @@ def test_to_json(default_conf, fee): 'stake_amount': 0.001, 'stop_loss': None, 'stop_loss_pct': None, + 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': None, 'initial_stop_loss_pct': None, + 'initial_stop_loss_ratio': None, 'close_profit': None, 'close_profit_abs': None, 'close_rate_requested': None, From d2b7016dffe40d0581427f7cbdb00915838759b0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 1 Jun 2020 11:05:37 +0200 Subject: [PATCH 3/3] Add stop_loss_abs ... --- freqtrade/persistence.py | 6 ++++-- tests/rpc/test_rpc.py | 4 ++++ tests/rpc/test_rpc_apiserver.py | 4 ++++ tests/test_persistence.py | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index 2fe93f440..823bf6dc0 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -281,7 +281,8 @@ class Trade(_DECL_BASE): 'sell_reason': self.sell_reason, 'sell_order_status': self.sell_order_status, - 'stop_loss': self.stop_loss, + 'stop_loss': self.stop_loss, # Deprecated - should not be used + 'stop_loss_abs': self.stop_loss, 'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None, 'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None, 'stoploss_order_id': self.stoploss_order_id, @@ -289,7 +290,8 @@ class Trade(_DECL_BASE): if self.stoploss_last_update else None), 'stoploss_last_update_timestamp': (int(self.stoploss_last_update.timestamp() * 1000) if self.stoploss_last_update else None), - 'initial_stop_loss': self.initial_stop_loss, + 'initial_stop_loss': self.initial_stop_loss, # Deprecated - should not be used + 'initial_stop_loss_abs': self.initial_stop_loss, 'initial_stop_loss_ratio': (self.initial_stop_loss_pct if self.initial_stop_loss_pct else None), 'initial_stop_loss_pct': (self.initial_stop_loss_pct * 100 diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index dcd525574..eb20e3903 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -81,12 +81,14 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'current_profit': -0.00408133, 'current_profit_pct': -0.41, 'stop_loss': 0.0, + 'stop_loss_abs': 0.0, 'stop_loss_pct': None, 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': 0.0, + 'initial_stop_loss_abs': 0.0, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'open_order': '(limit buy rem=0.00000000)', @@ -137,12 +139,14 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'current_profit': ANY, 'current_profit_pct': ANY, 'stop_loss': 0.0, + 'stop_loss_abs': 0.0, 'stop_loss_pct': None, 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': 0.0, + 'initial_stop_loss_abs': 0.0, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'open_order': '(limit buy rem=0.00000000)', diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 13914fab0..4e4dd7dfd 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -518,12 +518,14 @@ def test_api_status(botclient, mocker, ticker, fee, markets): 'pair': 'ETH/BTC', 'stake_amount': 0.001, 'stop_loss': 0.0, + 'stop_loss_abs': 0.0, 'stop_loss_pct': None, 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': 0.0, + 'initial_stop_loss_abs': 0.0, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'trade_id': 1, @@ -636,12 +638,14 @@ def test_api_forcebuy(botclient, mocker, fee): 'pair': 'ETH/ETH', 'stake_amount': 1, 'stop_loss': None, + 'stop_loss_abs': None, 'stop_loss_pct': None, 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': None, + 'initial_stop_loss_abs': None, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'close_profit': None, diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 942e22a19..ae639511b 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -762,12 +762,14 @@ def test_to_json(default_conf, fee): 'sell_reason': None, 'sell_order_status': None, 'stop_loss': None, + 'stop_loss_abs': None, 'stop_loss_ratio': None, 'stop_loss_pct': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': None, + 'initial_stop_loss_abs': None, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'min_rate': None, @@ -806,12 +808,14 @@ def test_to_json(default_conf, fee): 'amount': 100.0, 'stake_amount': 0.001, 'stop_loss': None, + 'stop_loss_abs': None, 'stop_loss_pct': None, 'stop_loss_ratio': None, 'stoploss_order_id': None, 'stoploss_last_update': None, 'stoploss_last_update_timestamp': None, 'initial_stop_loss': None, + 'initial_stop_loss_abs': None, 'initial_stop_loss_pct': None, 'initial_stop_loss_ratio': None, 'close_profit': None,