mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Merge pull request 'Include 24h pct change for EXTRA_COINS' (#11) from include-24h-pct-change into master
Reviewed-on: https://git.wownero.com/wownero/wowlet-backend/pulls/11
This commit is contained in:
commit
ed952c1ec5
1 changed files with 15 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue