add monero price stats

pull/3/head
lance 5 years ago
parent 3572fcaa29
commit a7b0450316

@ -1,3 +1,4 @@
from requests import get as r_get
from logging import getLogger from logging import getLogger
from huey import crontab from huey import crontab
from huey.contrib.djhuey import periodic_task from huey.contrib.djhuey import periodic_task
@ -8,10 +9,37 @@ from core.monero import AuctionDaemon, AuctionWallet
logger = getLogger('django.server') logger = getLogger('django.server')
@periodic_task(crontab(minute='*')) @periodic_task(crontab(minute='*/8'))
def retrieve_daemon_stats(): def retrieve_daemon_stats():
logger.info('[INFO] Retrieving daemon statistics') logger.info('[INFO] Retrieving daemon statistics')
ad = AuctionDaemon() ad = AuctionDaemon()
if ad.connected: if ad.connected:
daemon_info = ad.daemon.info() daemon_info = ad.daemon.info()
cache.set('daemon_info', daemon_info, settings.CACHE_TTL) cache.set('daemon_info', daemon_info, settings.CACHE_TTL)
@periodic_task(crontab(minute='*/20'))
def retrieve_monero_stats():
logger.info('[INFO] Retrieve Monero market statistics from Coin Gecko')
data = {
'localization': False,
'tickers': False,
'market_data': True,
'community_data': False,
'developer_data': False,
'sparkline': False
}
headers = {
'accept': 'application/json'
}
r = r_get('https://api.coingecko.com/api/v3/coins/monero', headers=headers, data=data)
monero_info = {
'genesis_date': r.json()['genesis_date'],
'market_cap_rank': r.json()['market_cap_rank'],
'current_price': r.json()['market_data']['current_price']['usd'],
'market_cap': r.json()['market_data']['market_cap']['usd'],
'market_cap_rank': r.json()['market_data']['market_cap_rank'],
'total_volume': r.json()['market_data']['total_volume']['usd'],
'last_updated': r.json()['last_updated']
}
logger.info(monero_info)
cache.set('monero_info', monero_info, settings.CACHE_TTL)

@ -10,15 +10,19 @@ from core.monero import AuctionDaemon, AuctionWallet
def home(request): def home(request):
daemon_info = cache.get('daemon_info', None) daemon_info = cache.get('daemon_info', None)
monero_info = cache.get('monero_info', None)
if daemon_info is None: if daemon_info is None:
d = AuctionDaemon() d = AuctionDaemon()
if d.connected: if d.connected:
daemon_info = AuctionDaemon().daemon.info() daemon_info = d.daemon.info()
else:
daemon_info = False context = {
'daemon_info': daemon_info,
'monero_info': monero_info
}
return render(request, 'home.html', {'daemon_info': daemon_info}) return render(request, 'home.html', context)
def health(request): def health(request):
daemon = AuctionDaemon() daemon = AuctionDaemon()

@ -46,6 +46,28 @@
<p>Difficulty:<br>{{ daemon_info.difficulty }}</p> <p>Difficulty:<br>{{ daemon_info.difficulty }}</p>
</section> </section>
</div> </div>
{% if monero_info %}
<div class="row 200%">
<section class="2u 12u$(small)">
<p>Genesis Date:<br>{{ monero_info.genesis_date }}</p>
</section>
<section class="2u 12u$(small)">
<p>Market Cap Rank:<br>{{ monero_info.market_cap_rank }}</p>
</section>
<section class="2u 12u$(small)">
<p>Current Price (USD):<br>$ {{ monero_info.current_price }}</p>
</section>
<section class="2u 12u$(small)">
<p>Market Cap (USD):<br>{{ monero_info.market_cap }}</p>
</section>
<section class="2u 12u$(small)">
<p>Total Volume (USD):<br>$ {{ monero_info.total_volume }}</p>
</section>
<section class="2u 12u$(small)">
<p>Last Updated:<br>{{ monero_info.last_updated }}</p>
</section>
</div>
{% endif %}
{% else %} {% else %}
<p class="text-muted">Daemon is not connected; statistics unavailable.</p> <p class="text-muted">Daemon is not connected; statistics unavailable.</p>
{% endif %} {% endif %}