Merge pull request #3419 from freqtrade/api_trade_response

Api trade response
This commit is contained in:
hroff-1902 2020-06-02 15:53:58 +03:00 committed by GitHub
commit 4c82f127b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 15 deletions

View File

@ -249,47 +249,57 @@ class Trade(_DECL_BASE):
'trade_id': self.id, 'trade_id': self.id,
'pair': self.pair, 'pair': self.pair,
'is_open': self.is_open, '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': self.fee_open,
'fee_open_cost': self.fee_open_cost, 'fee_open_cost': self.fee_open_cost,
'fee_open_currency': self.fee_open_currency, 'fee_open_currency': self.fee_open_currency,
'fee_close': self.fee_close, 'fee_close': self.fee_close,
'fee_close_cost': self.fee_close_cost, 'fee_close_cost': self.fee_close_cost,
'fee_close_currency': self.fee_close_currency, 'fee_close_currency': self.fee_close_currency,
'open_date_hum': arrow.get(self.open_date).humanize(), 'open_date_hum': arrow.get(self.open_date).humanize(),
'open_date': self.open_date.strftime("%Y-%m-%d %H:%M:%S"), 'open_date': self.open_date.strftime("%Y-%m-%d %H:%M:%S"),
'open_timestamp': int(self.open_date.timestamp() * 1000), '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() 'close_date_hum': (arrow.get(self.close_date).humanize()
if self.close_date else None), if self.close_date else None),
'close_date': (self.close_date.strftime("%Y-%m-%d %H:%M:%S") 'close_date': (self.close_date.strftime("%Y-%m-%d %H:%M:%S")
if self.close_date else None), if self.close_date else None),
'close_timestamp': int(self.close_date.timestamp() * 1000) 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': self.close_rate,
'close_rate_requested': self.close_rate_requested, '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': self.close_profit,
'close_profit_abs': self.close_profit_abs, 'close_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,
'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, 'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None,
'stoploss_order_id': self.stoploss_order_id, 'stoploss_order_id': self.stoploss_order_id,
'stoploss_last_update': (self.stoploss_last_update.strftime("%Y-%m-%d %H:%M:%S") 'stoploss_last_update': (self.stoploss_last_update.strftime("%Y-%m-%d %H:%M:%S")
if self.stoploss_last_update else None), if self.stoploss_last_update else None),
'stoploss_last_update_timestamp': (int(self.stoploss_last_update.timestamp() * 1000) 'stoploss_last_update_timestamp': (int(self.stoploss_last_update.timestamp() * 1000)
if self.stoploss_last_update else None), 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 'initial_stop_loss_pct': (self.initial_stop_loss_pct * 100
if self.initial_stop_loss_pct else None), if self.initial_stop_loss_pct else None),
'min_rate': self.min_rate, 'min_rate': self.min_rate,
'max_rate': self.max_rate, 'max_rate': self.max_rate,
'strategy': self.strategy,
'ticker_interval': self.ticker_interval,
'open_order_id': self.open_order_id, 'open_order_id': self.open_order_id,
'exchange': self.exchange,
} }
def adjust_min_max_rates(self, current_price: float) -> None: def adjust_min_max_rates(self, current_price: float) -> None:

View File

@ -81,12 +81,16 @@ 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,
'stop_loss': 0.0, 'stop_loss': 0.0,
'stop_loss_abs': 0.0,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': None, 'stoploss_last_update_timestamp': None,
'initial_stop_loss': 0.0, 'initial_stop_loss': 0.0,
'initial_stop_loss_abs': 0.0,
'initial_stop_loss_pct': None, 'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'open_order': '(limit buy rem=0.00000000)', 'open_order': '(limit buy rem=0.00000000)',
'exchange': 'bittrex', 'exchange': 'bittrex',
@ -135,12 +139,16 @@ 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,
'stop_loss': 0.0, 'stop_loss': 0.0,
'stop_loss_abs': 0.0,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': None, 'stoploss_last_update_timestamp': None,
'initial_stop_loss': 0.0, 'initial_stop_loss': 0.0,
'initial_stop_loss_abs': 0.0,
'initial_stop_loss_pct': None, 'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'open_order': '(limit buy rem=0.00000000)', 'open_order': '(limit buy rem=0.00000000)',
'exchange': 'bittrex', 'exchange': 'bittrex',
} == results[0] } == results[0]

View File

@ -510,8 +510,6 @@ 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_rate': 1.099e-05, 'current_rate': 1.099e-05,
'initial_stop_loss': 0.0,
'initial_stop_loss_pct': None,
'open_date': ANY, 'open_date': ANY,
'open_date_hum': 'just now', 'open_date_hum': 'just now',
'open_timestamp': ANY, 'open_timestamp': ANY,
@ -520,10 +518,16 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'pair': 'ETH/BTC', 'pair': 'ETH/BTC',
'stake_amount': 0.001, 'stake_amount': 0.001,
'stop_loss': 0.0, 'stop_loss': 0.0,
'stop_loss_abs': 0.0,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': 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, 'trade_id': 1,
'close_rate_requested': None, 'close_rate_requested': None,
'current_rate': 1.099e-05, 'current_rate': 1.099e-05,
@ -626,12 +630,11 @@ def test_api_forcebuy(botclient, mocker, fee):
data='{"pair": "ETH/BTC"}') data='{"pair": "ETH/BTC"}')
assert_response(rc) assert_response(rc)
assert rc.json == {'amount': 1, assert rc.json == {'amount': 1,
'trade_id': None,
'close_date': None, 'close_date': None,
'close_date_hum': None, 'close_date_hum': None,
'close_timestamp': None, 'close_timestamp': None,
'close_rate': 0.265441, 'close_rate': 0.265441,
'initial_stop_loss': None,
'initial_stop_loss_pct': None,
'open_date': ANY, 'open_date': ANY,
'open_date_hum': 'just now', 'open_date_hum': 'just now',
'open_timestamp': ANY, 'open_timestamp': ANY,
@ -639,11 +642,16 @@ def test_api_forcebuy(botclient, mocker, fee):
'pair': 'ETH/ETH', 'pair': 'ETH/ETH',
'stake_amount': 1, 'stake_amount': 1,
'stop_loss': None, 'stop_loss': None,
'stop_loss_abs': None,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': None, 'stoploss_last_update_timestamp': None,
'trade_id': None, 'initial_stop_loss': None,
'initial_stop_loss_abs': None,
'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'close_profit': None, 'close_profit': None,
'close_profit_abs': None, 'close_profit_abs': None,
'close_rate_requested': None, 'close_rate_requested': None,

View File

@ -762,12 +762,16 @@ def test_to_json(default_conf, fee):
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'stop_loss': None, 'stop_loss': None,
'stop_loss_abs': None,
'stop_loss_ratio': None,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': None, 'stoploss_last_update_timestamp': None,
'initial_stop_loss': None, 'initial_stop_loss': None,
'initial_stop_loss_abs': None,
'initial_stop_loss_pct': None, 'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'min_rate': None, 'min_rate': None,
'max_rate': None, 'max_rate': None,
'strategy': None, 'strategy': None,
@ -804,12 +808,16 @@ def test_to_json(default_conf, fee):
'amount': 100.0, 'amount': 100.0,
'stake_amount': 0.001, 'stake_amount': 0.001,
'stop_loss': None, 'stop_loss': None,
'stop_loss_abs': None,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None, 'stoploss_order_id': None,
'stoploss_last_update': None, 'stoploss_last_update': None,
'stoploss_last_update_timestamp': None, 'stoploss_last_update_timestamp': None,
'initial_stop_loss': None, 'initial_stop_loss': None,
'initial_stop_loss_abs': None,
'initial_stop_loss_pct': None, 'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'close_profit': None, 'close_profit': None,
'close_profit_abs': None, 'close_profit_abs': None,
'close_rate_requested': None, 'close_rate_requested': None,