Added realized profit
Co-Authored-By: மனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com>
This commit is contained in:
parent
6fa6542935
commit
117e966f34
@ -401,7 +401,6 @@ class Backtesting:
|
|||||||
|
|
||||||
if stake_amount is not None and stake_amount < 0.0:
|
if stake_amount is not None and stake_amount < 0.0:
|
||||||
amount = -stake_amount / current_rate
|
amount = -stake_amount / current_rate
|
||||||
logger.info("partial_sell_bt")
|
|
||||||
if amount > trade.amount:
|
if amount > trade.amount:
|
||||||
logger.info(f"Amount is higher than available. {amount} > {trade.amount}")
|
logger.info(f"Amount is higher than available. {amount} > {trade.amount}")
|
||||||
return trade
|
return trade
|
||||||
|
@ -127,6 +127,7 @@ class Order(_DECL_BASE):
|
|||||||
side = Column(String(25), nullable=True)
|
side = Column(String(25), nullable=True)
|
||||||
price = Column(Float, nullable=True)
|
price = Column(Float, nullable=True)
|
||||||
average = Column(Float, nullable=True)
|
average = Column(Float, nullable=True)
|
||||||
|
initial_average = Column(Float, nullable=True)
|
||||||
amount = Column(Float, nullable=True)
|
amount = Column(Float, nullable=True)
|
||||||
filled = Column(Float, nullable=True)
|
filled = Column(Float, nullable=True)
|
||||||
remaining = Column(Float, nullable=True)
|
remaining = Column(Float, nullable=True)
|
||||||
@ -179,6 +180,7 @@ class Order(_DECL_BASE):
|
|||||||
self.amount = order.get('amount', self.amount)
|
self.amount = order.get('amount', self.amount)
|
||||||
self.filled = order.get('filled', self.filled)
|
self.filled = order.get('filled', self.filled)
|
||||||
self.average = order.get('average', self.average)
|
self.average = order.get('average', self.average)
|
||||||
|
self.initial_average = order.get('average', self.initial_average)
|
||||||
self.remaining = order.get('remaining', self.remaining)
|
self.remaining = order.get('remaining', self.remaining)
|
||||||
self.cost = order.get('cost', self.cost)
|
self.cost = order.get('cost', self.cost)
|
||||||
if 'timestamp' in order and order['timestamp'] is not None:
|
if 'timestamp' in order and order['timestamp'] is not None:
|
||||||
@ -269,6 +271,7 @@ class LocalTrade():
|
|||||||
trades: List['LocalTrade'] = []
|
trades: List['LocalTrade'] = []
|
||||||
trades_open: List['LocalTrade'] = []
|
trades_open: List['LocalTrade'] = []
|
||||||
total_profit: float = 0
|
total_profit: float = 0
|
||||||
|
realized_profit: float = 0
|
||||||
|
|
||||||
id: int = 0
|
id: int = 0
|
||||||
|
|
||||||
@ -521,12 +524,14 @@ class LocalTrade():
|
|||||||
if is_non_bt:
|
if is_non_bt:
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
return
|
return
|
||||||
|
realized_profit = 0.0
|
||||||
profit = 0.0
|
profit = 0.0
|
||||||
idx = -1
|
idx = -1
|
||||||
while sell_amount:
|
while sell_amount:
|
||||||
b_order = orders[idx]
|
b_order = orders[idx]
|
||||||
buy_amount = b_order.safe_amount_after_fee
|
buy_amount = b_order.safe_amount_after_fee
|
||||||
buy_rate = b_order.safe_price
|
avg_rate = b_order.safe_price
|
||||||
|
buy_rate = b_order.initial_average or b_order.price
|
||||||
if sell_amount < buy_amount:
|
if sell_amount < buy_amount:
|
||||||
amount = sell_amount
|
amount = sell_amount
|
||||||
else:
|
else:
|
||||||
@ -536,7 +541,8 @@ class LocalTrade():
|
|||||||
b_order.filled -= amount
|
b_order.filled -= amount
|
||||||
b_order.order_update_date = datetime.now(timezone.utc)
|
b_order.order_update_date = datetime.now(timezone.utc)
|
||||||
sell_amount -= amount
|
sell_amount -= amount
|
||||||
profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
profit += self.calc_profit2(avg_rate, sell_rate, amount)
|
||||||
|
realized_profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
||||||
if is_closed:
|
if is_closed:
|
||||||
b_order2 = orders[idx]
|
b_order2 = orders[idx]
|
||||||
amount2 = b_order2.safe_amount_after_fee
|
amount2 = b_order2.safe_amount_after_fee
|
||||||
@ -545,6 +551,7 @@ class LocalTrade():
|
|||||||
if is_non_bt:
|
if is_non_bt:
|
||||||
Order.query.session.commit()
|
Order.query.session.commit()
|
||||||
self.recalc_trade_from_orders()
|
self.recalc_trade_from_orders()
|
||||||
|
self.realized_profit += realized_profit
|
||||||
|
|
||||||
self.close_profit_abs = profit
|
self.close_profit_abs = profit
|
||||||
self.close_profit = sell_stake_amount / (sell_stake_amount - profit) - 1
|
self.close_profit = sell_stake_amount / (sell_stake_amount - profit) - 1
|
||||||
@ -873,6 +880,7 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
open_trade_value = Column(Float)
|
open_trade_value = Column(Float)
|
||||||
close_rate: Optional[float] = Column(Float)
|
close_rate: Optional[float] = Column(Float)
|
||||||
close_rate_requested = Column(Float)
|
close_rate_requested = Column(Float)
|
||||||
|
realized_profit = Column(Float)
|
||||||
close_profit = Column(Float)
|
close_profit = Column(Float)
|
||||||
close_profit_abs = Column(Float)
|
close_profit_abs = Column(Float)
|
||||||
stake_amount = Column(Float, nullable=False)
|
stake_amount = Column(Float, nullable=False)
|
||||||
|
@ -195,8 +195,9 @@ class RPC:
|
|||||||
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 not trade.is_open else None,
|
||||||
current_rate=current_rate,
|
current_rate=current_rate,
|
||||||
|
realized_profit=trade.realized_profit,
|
||||||
current_profit=current_profit, # Deprecated
|
current_profit=current_profit, # Deprecated
|
||||||
current_profit_pct=round(current_profit * 100, 2), # Deprecated
|
current_profit_pct=round(current_profit * 100, 2), # Deprecated
|
||||||
current_profit_abs=current_profit_abs, # Deprecated
|
current_profit_abs=current_profit_abs, # Deprecated
|
||||||
|
@ -500,6 +500,7 @@ class Telegram(RPCHandler):
|
|||||||
])
|
])
|
||||||
|
|
||||||
if r['is_open']:
|
if r['is_open']:
|
||||||
|
lines.append("*Realized Prodir:* `{realized_profit:.8f}`")
|
||||||
if (r['stop_loss_abs'] != r['initial_stop_loss_abs']
|
if (r['stop_loss_abs'] != r['initial_stop_loss_abs']
|
||||||
and r['initial_stop_loss_ratio'] is not None):
|
and r['initial_stop_loss_ratio'] is not None):
|
||||||
# Adding initial stoploss only if it is different from stoploss
|
# Adding initial stoploss only if it is different from stoploss
|
||||||
|
Loading…
Reference in New Issue
Block a user