Standardize trade api outputs
there should be no difference between current_profit and close_profit it's always profit, and the information if it's a closed trade is available elsewhere
This commit is contained in:
parent
887d78171c
commit
cf89a773da
@ -295,8 +295,13 @@ class Trade(_DECL_BASE):
|
|||||||
tzinfo=timezone.utc).timestamp() * 1000) if self.close_date else None,
|
tzinfo=timezone.utc).timestamp() * 1000) if self.close_date else None,
|
||||||
'close_rate': self.close_rate,
|
'close_rate': self.close_rate,
|
||||||
'close_rate_requested': self.close_rate_requested,
|
'close_rate_requested': self.close_rate_requested,
|
||||||
'close_profit': self.close_profit,
|
'close_profit': self.close_profit, # Deprecated
|
||||||
'close_profit_abs': self.close_profit_abs,
|
'close_profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None,
|
||||||
|
'close_profit_abs': self.close_profit_abs, # Deprecated
|
||||||
|
|
||||||
|
'profit_ratio': self.close_profit,
|
||||||
|
'profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None,
|
||||||
|
'profit_abs': self.close_profit_abs,
|
||||||
|
|
||||||
'sell_reason': self.sell_reason,
|
'sell_reason': self.sell_reason,
|
||||||
'sell_order_status': self.sell_order_status,
|
'sell_order_status': self.sell_order_status,
|
||||||
|
@ -152,17 +152,18 @@ class RPC:
|
|||||||
stoploss_current_dist = trade.stop_loss - current_rate
|
stoploss_current_dist = trade.stop_loss - current_rate
|
||||||
stoploss_current_dist_ratio = stoploss_current_dist / 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()
|
trade_dict = trade.to_json()
|
||||||
trade_dict.update(dict(
|
trade_dict.update(dict(
|
||||||
base_currency=self._freqtrade.config['stake_currency'],
|
base_currency=self._freqtrade.config['stake_currency'],
|
||||||
close_profit=trade.close_profit if trade.close_profit is not None else None,
|
close_profit=trade.close_profit if trade.close_profit is not None else None,
|
||||||
close_profit_pct=fmt_close_profit,
|
|
||||||
current_rate=current_rate,
|
current_rate=current_rate,
|
||||||
current_profit=current_profit,
|
current_profit=current_profit, # Deprectated
|
||||||
current_profit_pct=round(current_profit * 100, 2),
|
current_profit_pct=round(current_profit * 100, 2), # Deprectated
|
||||||
current_profit_abs=current_profit_abs,
|
current_profit_abs=current_profit_abs, # Deprectated
|
||||||
|
profit_ratio=current_profit,
|
||||||
|
profit_pct=round(current_profit * 100, 2),
|
||||||
|
profit_abs=current_profit_abs,
|
||||||
|
|
||||||
stoploss_current_dist=stoploss_current_dist,
|
stoploss_current_dist=stoploss_current_dist,
|
||||||
stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8),
|
stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8),
|
||||||
stoploss_current_dist_pct=round(stoploss_current_dist_ratio * 100, 2),
|
stoploss_current_dist_pct=round(stoploss_current_dist_ratio * 100, 2),
|
||||||
|
@ -70,7 +70,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
'max_rate': ANY,
|
'max_rate': ANY,
|
||||||
'strategy': ANY,
|
'strategy': ANY,
|
||||||
'ticker_interval': ANY,
|
'ticker_interval': ANY,
|
||||||
'timeframe': ANY,
|
'timeframe': 5,
|
||||||
'open_order_id': ANY,
|
'open_order_id': ANY,
|
||||||
'close_date': None,
|
'close_date': None,
|
||||||
'close_date_hum': None,
|
'close_date_hum': None,
|
||||||
@ -87,6 +87,9 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
'current_profit': -0.00408133,
|
'current_profit': -0.00408133,
|
||||||
'current_profit_pct': -0.41,
|
'current_profit_pct': -0.41,
|
||||||
'current_profit_abs': -4.09e-06,
|
'current_profit_abs': -4.09e-06,
|
||||||
|
'profit_ratio': -0.00408133,
|
||||||
|
'profit_pct': -0.41,
|
||||||
|
'profit_abs': -4.09e-06,
|
||||||
'stop_loss': 9.882e-06,
|
'stop_loss': 9.882e-06,
|
||||||
'stop_loss_abs': 9.882e-06,
|
'stop_loss_abs': 9.882e-06,
|
||||||
'stop_loss_pct': -10.0,
|
'stop_loss_pct': -10.0,
|
||||||
@ -152,6 +155,9 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
'current_profit': ANY,
|
'current_profit': ANY,
|
||||||
'current_profit_pct': ANY,
|
'current_profit_pct': ANY,
|
||||||
'current_profit_abs': ANY,
|
'current_profit_abs': ANY,
|
||||||
|
'profit_ratio': ANY,
|
||||||
|
'profit_pct': ANY,
|
||||||
|
'profit_abs': ANY,
|
||||||
'stop_loss': 9.882e-06,
|
'stop_loss': 9.882e-06,
|
||||||
'stop_loss_abs': 9.882e-06,
|
'stop_loss_abs': 9.882e-06,
|
||||||
'stop_loss_pct': -10.0,
|
'stop_loss_pct': -10.0,
|
||||||
|
@ -639,6 +639,9 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
|
|||||||
'current_profit': -0.00408133,
|
'current_profit': -0.00408133,
|
||||||
'current_profit_pct': -0.41,
|
'current_profit_pct': -0.41,
|
||||||
'current_profit_abs': -4.09e-06,
|
'current_profit_abs': -4.09e-06,
|
||||||
|
'profit_ratio': -0.00408133,
|
||||||
|
'profit_pct': -0.41,
|
||||||
|
'profit_abs': -4.09e-06,
|
||||||
'current_rate': 1.099e-05,
|
'current_rate': 1.099e-05,
|
||||||
'open_date': ANY,
|
'open_date': ANY,
|
||||||
'open_date_hum': 'just now',
|
'open_date_hum': 'just now',
|
||||||
@ -791,8 +794,12 @@ def test_api_forcebuy(botclient, mocker, fee):
|
|||||||
'initial_stop_loss_pct': None,
|
'initial_stop_loss_pct': None,
|
||||||
'initial_stop_loss_ratio': None,
|
'initial_stop_loss_ratio': None,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
|
'close_profit_pct': None,
|
||||||
'close_profit_abs': None,
|
'close_profit_abs': None,
|
||||||
'close_rate_requested': None,
|
'close_rate_requested': None,
|
||||||
|
'profit_ratio': None,
|
||||||
|
'profit_pct': None,
|
||||||
|
'profit_abs': None,
|
||||||
'fee_close': 0.0025,
|
'fee_close': 0.0025,
|
||||||
'fee_close_cost': None,
|
'fee_close_cost': None,
|
||||||
'fee_close_currency': None,
|
'fee_close_currency': None,
|
||||||
|
@ -816,7 +816,11 @@ def test_to_json(default_conf, fee):
|
|||||||
'amount_requested': 123.0,
|
'amount_requested': 123.0,
|
||||||
'stake_amount': 0.001,
|
'stake_amount': 0.001,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
|
'close_profit_pct': None,
|
||||||
'close_profit_abs': None,
|
'close_profit_abs': None,
|
||||||
|
'profit_ratio': None,
|
||||||
|
'profit_pct': None,
|
||||||
|
'profit_abs': None,
|
||||||
'sell_reason': None,
|
'sell_reason': None,
|
||||||
'sell_order_status': None,
|
'sell_order_status': None,
|
||||||
'stop_loss': None,
|
'stop_loss': None,
|
||||||
@ -880,7 +884,11 @@ def test_to_json(default_conf, fee):
|
|||||||
'initial_stop_loss_pct': None,
|
'initial_stop_loss_pct': None,
|
||||||
'initial_stop_loss_ratio': None,
|
'initial_stop_loss_ratio': None,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
|
'close_profit_pct': None,
|
||||||
'close_profit_abs': None,
|
'close_profit_abs': None,
|
||||||
|
'profit_ratio': None,
|
||||||
|
'profit_pct': None,
|
||||||
|
'profit_abs': None,
|
||||||
'close_rate_requested': None,
|
'close_rate_requested': None,
|
||||||
'fee_close': 0.0025,
|
'fee_close': 0.0025,
|
||||||
'fee_close_cost': None,
|
'fee_close_cost': None,
|
||||||
|
Loading…
Reference in New Issue
Block a user