|
|
|
@ -43,17 +43,19 @@ class CryptoRatesTask(WowletTask):
|
|
|
|
|
|
|
|
|
|
# additional coins as defined by `settings.CRYPTO_RATES_COINS_EXTRA`
|
|
|
|
|
for coin, symbol in settings.CRYPTO_RATES_COINS_EXTRA.items():
|
|
|
|
|
obj = {}
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
results = {}
|
|
|
|
|
for vs_currency in ["usd", "btc"]:
|
|
|
|
|
url = f"{self._http_api_gecko}/simple/price?ids={coin}&vs_currencies={vs_currency}"
|
|
|
|
|
data = await httpget(url, json=True)
|
|
|
|
|
data = await httpget(url, json=True, timeout=15)
|
|
|
|
|
results[vs_currency] = data[coin][vs_currency]
|
|
|
|
|
|
|
|
|
|
price_btc = "{:.8f}".format(results["btc"])
|
|
|
|
|
price_sat = int(price_btc.replace(".", "").lstrip("0")) # yolo
|
|
|
|
|
|
|
|
|
|
rates.append({
|
|
|
|
|
obj = {
|
|
|
|
|
"id": coin,
|
|
|
|
|
"symbol": symbol,
|
|
|
|
|
"image": "",
|
|
|
|
@ -62,9 +64,19 @@ class CryptoRatesTask(WowletTask):
|
|
|
|
|
"current_price_btc": price_btc,
|
|
|
|
|
"current_price_satoshi": price_sat,
|
|
|
|
|
"price_change_percentage_24h": 0.0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
app.logger.error(f"extra coin: {coin}; {ex}")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# additional call to fetch 24h pct change
|
|
|
|
|
url = f"{self._http_api_gecko}/coins/{coin}?tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"
|
|
|
|
|
blob = await httpget(url, json=True, timeout=15)
|
|
|
|
|
obj["price_change_percentage_24h"] = blob.get("market_data", {}).get("price_change_percentage_24h")
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
rates.append(obj)
|
|
|
|
|
|
|
|
|
|
return rates
|
|
|
|
|