Don't use current rate for closed trades

This commit is contained in:
Matthias 2021-04-17 19:29:34 +02:00
parent 3b53c88dbe
commit 44bfb53668
3 changed files with 7 additions and 6 deletions

View File

@ -189,7 +189,6 @@ class OpenTradeSchema(TradeSchema):
stoploss_current_dist_ratio: Optional[float]
stoploss_entry_dist: Optional[float]
stoploss_entry_dist_ratio: Optional[float]
base_currency: str
current_profit: float
current_profit_abs: float
current_profit_pct: float

View File

@ -167,10 +167,13 @@ class RPC:
if trade.open_order_id:
order = self._freqtrade.exchange.fetch_order(trade.open_order_id, trade.pair)
# calculate profit and send message to user
try:
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
except (ExchangeError, PricingError):
current_rate = NAN
if trade.is_open:
try:
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
except (ExchangeError, PricingError):
current_rate = NAN
else:
current_rate = trade.close_rate
current_profit = trade.calc_profit_ratio(current_rate)
current_profit_abs = trade.calc_profit(current_rate)

View File

@ -773,7 +773,6 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
assert rc.json()[0] == {
'amount': 123.0,
'amount_requested': 123.0,
'base_currency': 'BTC',
'close_date': None,
'close_timestamp': None,
'close_profit': None,