Remodel price endpoint to only return latest markettick

This commit is contained in:
Reckless_Satoshi 2022-03-12 06:55:29 -08:00
parent f383d20c37
commit 806a56c7f9
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
2 changed files with 12 additions and 17 deletions

View File

@ -86,7 +86,7 @@ class Telegram():
if lang == 'es':
text = f'¡Tu orden con ID {order.id} ha sido tomada por {taker_nick}!🥳 El tomador ya ha bloqueado su fianza. Visita http://{site}/order/{order.id} para continuar.'
else:
text = f'Your order with ID {order.id} was taken by {taker_nick}!🥳 The taker bond has been already locked. Visit http://{site}/order/{order.id} to proceed with the trade.'
text = f'Your order with ID {order.id} was taken by {taker_nick}!🥳 The taker bond has already been locked. Visit http://{site}/order/{order.id} to proceed with the trade.'
self.send_message(user, text)
return

View File

@ -730,25 +730,20 @@ class PriceView(CreateAPIView):
def get(self, request):
# Compute average premium and volume of last 24 h
start_datetime = timezone.now() - timedelta(days=1)
queryset = MarketTick.objects.filter(timestamp__gt=start_datetime)
if not len(queryset) == 0:
avg_premium, _ = compute_avg_premium(queryset)
# If no contracts exists in the last 24 h, fallback to lifetime average premium.
else:
queryset = MarketTick.objects.all()
avg_premium, _ = compute_avg_premium(queryset)
payload = {}
queryset = Currency.objects.all().order_by('currency')
for currency in queryset:
code = Currency.currency_dict[str(currency.currency)]
payload[code] = {'price': currency.exchange_rate * (1 + avg_premium / 100),
'premium': avg_premium}
# A hack here. BTC swaps have usually no premium (at least, they are totally different)
payload['BTC'] = {'price': 1, 'premium': 0}
try:
last_tick = MarketTick.objects.filter(currency=currency).latest('timestamp')
payload[code] = {
'price': last_tick.price,
'volume': last_tick.volume,
'premium': last_tick.premium,
'timestamp': last_tick.timestamp,
}
except:
payload[code] = None
return Response(payload, status.HTTP_200_OK)