ADd optional to class _fiat_convert

This commit is contained in:
Matthias 2018-07-22 14:35:29 +02:00
parent f297d22edb
commit 6cc0a72bca
2 changed files with 10 additions and 8 deletions

View File

@ -6,7 +6,7 @@ from abc import abstractmethod
from datetime import timedelta, datetime, date
from decimal import Decimal
from enum import Enum
from typing import Dict, Any, List
from typing import Dict, Any, List, Optional
import arrow
import sqlalchemy as sql
@ -51,7 +51,7 @@ class RPC(object):
RPC class can be used to have extra feature, like bot data, and access to DB data
"""
# Initialize _fiat_converter if needed in each RPC handler
_fiat_converter: CryptoToFiatConverter = None
_fiat_converter: Optional[CryptoToFiatConverter] = None
def __init__(self, freqtrade) -> None:
"""
@ -146,7 +146,6 @@ class RPC(object):
if not (isinstance(timescale, int) and timescale > 0):
raise RPCException('timescale must be an integer greater than 0')
fiat = self._fiat_converter
for day in range(0, timescale):
profitday = today - timedelta(days=day)
trades = Trade.query \
@ -169,7 +168,7 @@ class RPC(object):
symbol=stake_currency
),
'{value:.3f} {symbol}'.format(
value=fiat.convert_amount(
value=self._fiat_converter.convert_amount(
value['amount'],
stake_currency,
fiat_display_currency

View File

@ -116,8 +116,11 @@ class Telegram(RPC):
""" Send a message to telegram channel """
if msg['type'] == RPCMessageType.BUY_NOTIFICATION:
msg['stake_amount_fiat'] = self._fiat_converter.convert_amount(
msg['stake_amount'], msg['stake_currency'], msg['fiat_currency'])
if self._fiat_converter:
msg['stake_amount_fiat'] = self._fiat_converter.convert_amount(
msg['stake_amount'], msg['stake_currency'], msg['fiat_currency'])
else:
msg['stake_amount_fiat'] = 0
message = "*{exchange}:* Buying [{pair}]({market_url})\n" \
"with limit `{limit:.8f}\n" \
@ -138,8 +141,8 @@ class Telegram(RPC):
# Check if all sell properties are available.
# This might not be the case if the message origin is triggered by /forcesell
if all(prop in msg for prop in ['gain', 'profit_fiat',
'fiat_currency', 'stake_currency']):
if (all(prop in msg for prop in ['gain', 'fiat_currency', 'stake_currency'])
and self._fiat_converter):
msg['profit_fiat'] = self._fiat_converter.convert_amount(
msg['profit_amount'], msg['stake_currency'], msg['fiat_currency'])
message += '` ({gain}: {profit_amount:.8f} {stake_currency}`' \