From 806a56c7f95f532dce50932746307c2049baf686 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sat, 12 Mar 2022 06:55:29 -0800 Subject: [PATCH] Remodel price endpoint to only return latest markettick --- api/messages.py | 2 +- api/views.py | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/api/messages.py b/api/messages.py index cbdc0a58..c32f9f39 100644 --- a/api/messages.py +++ b/api/messages.py @@ -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 diff --git a/api/views.py b/api/views.py index fc5d42cf..1db6db9f 100644 --- a/api/views.py +++ b/api/views.py @@ -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) \ No newline at end of file