2022-01-07 22:46:30 +00:00
|
|
|
|
|
|
|
from decouple import config
|
|
|
|
import requests
|
2022-01-10 01:12:58 +00:00
|
|
|
import ring
|
2022-01-07 22:46:30 +00:00
|
|
|
|
2022-01-10 01:12:58 +00:00
|
|
|
storage = {}
|
|
|
|
|
2022-01-10 12:10:32 +00:00
|
|
|
@ring.dict(storage, expire=30) #keeps in cache for 30 seconds
|
2022-01-07 22:46:30 +00:00
|
|
|
def get_exchange_rate(currency):
|
|
|
|
# TODO Add fallback Public APIs and error handling
|
|
|
|
# Think about polling price data in a different way (e.g. store locally every t seconds)
|
|
|
|
|
|
|
|
market_prices = requests.get(config('MARKET_PRICE_API')).json()
|
|
|
|
exchange_rate = float(market_prices[currency]['last'])
|
|
|
|
|
|
|
|
return exchange_rate
|