exchange_rate: guard against garbage hist data coming from exchange
See discussion at 583089d57b (r104678577)
CoinGecko for PLN gives "None" str as rate (instead of null) for two months mid-2014:
```
2.29 | D | exchange_rate.CoinGecko | found corrupted historical_rate: rate='None'. for ccy='PLN' at 2014-05-10
```
Thanks to @lukasz1992 for reporting.
This commit is contained in:
@@ -161,8 +161,13 @@ class ExchangeBase(Logger):
|
||||
return []
|
||||
|
||||
def historical_rate(self, ccy: str, d_t: datetime) -> Decimal:
|
||||
rate = self._history.get(ccy, {}).get(d_t.strftime('%Y-%m-%d')) or 'NaN'
|
||||
return Decimal(rate)
|
||||
date_str = d_t.strftime('%Y-%m-%d')
|
||||
rate = self._history.get(ccy, {}).get(date_str) or 'NaN'
|
||||
try:
|
||||
return Decimal(rate)
|
||||
except Exception: # guard against garbage coming from exchange
|
||||
#self.logger.debug(f"found corrupted historical_rate: {rate=!r}. for {ccy=} at {date_str}")
|
||||
return Decimal('NaN')
|
||||
|
||||
async def request_history(self, ccy: str) -> Dict[str, Union[str, float]]:
|
||||
raise NotImplementedError() # implemented by subclasses
|
||||
|
||||
Reference in New Issue
Block a user