Add FIAT currency to status-table

This commit is contained in:
Matthias
2019-11-12 14:58:41 +01:00
parent ab9506df48
commit df9bfb6c2e
3 changed files with 43 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ from abc import abstractmethod
from datetime import date, datetime, timedelta
from decimal import Decimal
from enum import Enum
from math import isnan
from typing import Any, Dict, List, Optional, Tuple
import arrow
@@ -116,7 +117,7 @@ class RPC:
results.append(trade_dict)
return results
def _rpc_status_table(self, fiat_display_currency: str) -> Tuple[List, List]:
def _rpc_status_table(self, stake_currency, fiat_display_currency: str) -> Tuple[List, List]:
trades = Trade.get_open_trades()
if not trades:
raise RPCException('no active order')
@@ -129,15 +130,27 @@ class RPC:
except DependencyException:
current_rate = NAN
trade_perc = (100 * trade.calc_profit_percent(current_rate))
trade_profit = trade.calc_profit(current_rate)
profit_str = f'{trade_perc:.2f}%'
if self._fiat_converter:
fiat_profit = self._fiat_converter.convert_amount(
trade_profit,
stake_currency,
fiat_display_currency
)
if fiat_profit and not isnan(fiat_profit):
profit_str += f" ({fiat_profit:.2f})"
trades_list.append([
trade.id,
trade.pair,
shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)),
f'{trade_perc:.2f}%'
profit_str
])
profitcol = "Profit"
if self._fiat_converter:
profitcol += " (" + fiat_display_currency + ")"
columns = ['ID', 'Pair', 'Since', 'Profit']
columns = ['ID', 'Pair', 'Since', profitcol]
return trades_list, columns
def _rpc_daily_profit(

View File

@@ -234,7 +234,8 @@ class Telegram(RPC):
:return: None
"""
try:
statlist, head = self._rpc_status_table(self._config.get('fiat_display_currency', ''))
statlist, head = self._rpc_status_table(self._config['stake_currency'],
self._config.get('fiat_display_currency', ''))
message = tabulate(statlist, headers=head, tablefmt='simple')
self._send_msg(f"<pre>{message}</pre>", parse_mode=ParseMode.HTML)
except RPCException as e: