Move trade jsonification to trade class
This commit is contained in:
parent
4ae743ecb6
commit
1e056ee415
@ -213,6 +213,23 @@ class Trade(_DECL_BASE):
|
|||||||
return (f'Trade(id={self.id}, pair={self.pair}, amount={self.amount:.8f}, '
|
return (f'Trade(id={self.id}, pair={self.pair}, amount={self.amount:.8f}, '
|
||||||
f'open_rate={self.open_rate:.8f}, open_since={open_since})')
|
f'open_rate={self.open_rate:.8f}, open_since={open_since})')
|
||||||
|
|
||||||
|
def to_json(self) -> Dict[str, Any]:
|
||||||
|
|
||||||
|
return {
|
||||||
|
'trade_id': self.id,
|
||||||
|
'pair': self.pair,
|
||||||
|
'date': arrow.get(self.open_date),
|
||||||
|
'open_rate': self.open_rate,
|
||||||
|
'close_rate': self.close_rate,
|
||||||
|
'amount': round(self.amount, 8),
|
||||||
|
'stake_amount': round(self.stake_amount, 8),
|
||||||
|
'stop_loss': self.stop_loss,
|
||||||
|
'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None,
|
||||||
|
'initial_stop_loss': self.initial_stop_loss,
|
||||||
|
'initial_stop_loss_pct': (self.initial_stop_loss_pct * 100)
|
||||||
|
if self.initial_stop_loss_pct else None,
|
||||||
|
}
|
||||||
|
|
||||||
def adjust_min_max_rates(self, current_price: float):
|
def adjust_min_max_rates(self, current_price: float):
|
||||||
"""
|
"""
|
||||||
Adjust the max_rate and min_rate.
|
Adjust the max_rate and min_rate.
|
||||||
|
@ -100,28 +100,17 @@ class RPC(object):
|
|||||||
current_profit = trade.calc_profit_percent(current_rate)
|
current_profit = trade.calc_profit_percent(current_rate)
|
||||||
fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%'
|
fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%'
|
||||||
if trade.close_profit else None)
|
if trade.close_profit else None)
|
||||||
results.append(dict(
|
trade_dict = trade.to_json()
|
||||||
trade_id=trade.id,
|
trade_dict.update(dict(
|
||||||
pair=trade.pair,
|
|
||||||
base_currency=self._freqtrade.config['stake_currency'],
|
base_currency=self._freqtrade.config['stake_currency'],
|
||||||
date=arrow.get(trade.open_date),
|
|
||||||
open_rate=trade.open_rate,
|
|
||||||
close_rate=trade.close_rate,
|
|
||||||
current_rate=current_rate,
|
|
||||||
amount=round(trade.amount, 8),
|
|
||||||
stake_amount=round(trade.stake_amount, 8),
|
|
||||||
close_profit=fmt_close_profit,
|
close_profit=fmt_close_profit,
|
||||||
|
current_rate=current_rate,
|
||||||
current_profit=round(current_profit * 100, 2),
|
current_profit=round(current_profit * 100, 2),
|
||||||
stop_loss=trade.stop_loss,
|
|
||||||
stop_loss_pct=(trade.stop_loss_pct * 100)
|
|
||||||
if trade.stop_loss_pct else None,
|
|
||||||
initial_stop_loss=trade.initial_stop_loss,
|
|
||||||
initial_stop_loss_pct=(trade.initial_stop_loss_pct * 100)
|
|
||||||
if trade.initial_stop_loss_pct else None,
|
|
||||||
open_order='({} {} rem={:.8f})'.format(
|
open_order='({} {} rem={:.8f})'.format(
|
||||||
order['type'], order['side'], order['remaining']
|
order['type'], order['side'], order['remaining']
|
||||||
) if order else None,
|
) if order else None,
|
||||||
))
|
))
|
||||||
|
results.append(trade_dict)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _rpc_status_table(self) -> DataFrame:
|
def _rpc_status_table(self) -> DataFrame:
|
||||||
|
Loading…
Reference in New Issue
Block a user