mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 12:11:35 +00:00
Premium percentile computing
This commit is contained in:
parent
f010fe9bb0
commit
980a385528
22
api/utils.py
22
api/utils.py
@ -3,6 +3,8 @@ import requests, ring, os
|
||||
from decouple import config
|
||||
import numpy as np
|
||||
|
||||
from api.models import Order
|
||||
|
||||
market_cache = {}
|
||||
|
||||
@ring.dict(market_cache, expire=3) #keeps in cache for 3 seconds
|
||||
@ -49,7 +51,6 @@ def get_exchange_rates(currencies):
|
||||
return median_rates.tolist()
|
||||
|
||||
lnd_v_cache = {}
|
||||
|
||||
@ring.dict(lnd_v_cache, expire=3600) #keeps in cache for 3600 seconds
|
||||
def get_lnd_version():
|
||||
|
||||
@ -59,7 +60,6 @@ def get_lnd_version():
|
||||
return lnd_version
|
||||
|
||||
robosats_commit_cache = {}
|
||||
|
||||
@ring.dict(robosats_commit_cache, expire=3600)
|
||||
def get_commit_robosats():
|
||||
|
||||
@ -67,4 +67,22 @@ def get_commit_robosats():
|
||||
lnd_version = stream.read()
|
||||
|
||||
return lnd_version
|
||||
|
||||
premium_percentile = {}
|
||||
@ring.dict(premium_percentile, expire=300)
|
||||
def compute_premium_percentile(order):
|
||||
|
||||
queryset = Order.objects.filter(currency=order.currency, status=Order.Status.PUB)
|
||||
|
||||
print(len(queryset))
|
||||
if len(queryset) <= 1:
|
||||
return 0.5
|
||||
|
||||
order_rate = float(order.last_satoshis) / float(order.amount)
|
||||
rates = []
|
||||
for similar_order in queryset:
|
||||
rates.append(float(similar_order.last_satoshis) / float(similar_order.amount))
|
||||
|
||||
rates = np.array(rates)
|
||||
return round(np.sum(rates < order_rate) / len(rates),2)
|
||||
|
||||
|
10
api/views.py
10
api/views.py
@ -11,7 +11,7 @@ from django.contrib.auth.models import User
|
||||
from .serializers import ListOrderSerializer, MakeOrderSerializer, UpdateOrderSerializer
|
||||
from .models import LNPayment, MarketTick, Order, Currency
|
||||
from .logics import Logics
|
||||
from .utils import get_lnd_version, get_commit_robosats
|
||||
from .utils import get_lnd_version, get_commit_robosats, compute_premium_percentile
|
||||
|
||||
from .nick_generator.nick_generator import NickGenerator
|
||||
from robohash import Robohash
|
||||
@ -125,7 +125,7 @@ class OrderView(viewsets.ViewSet):
|
||||
# 3. c) If maker and Public, add num robots in book, premium percentile and num similar orders.
|
||||
if data['is_maker'] and order.status == Order.Status.PUB:
|
||||
data['robots_in_book'] = None # TODO
|
||||
data['premium_percentile'] = None # TODO
|
||||
data['premium_percentile'] = compute_premium_percentile(order)
|
||||
data['num_similar_orders'] = len(Order.objects.filter(currency=order.currency, status=Order.Status.PUB))
|
||||
|
||||
# 4) Non participants can view details (but only if PUB)
|
||||
@ -326,9 +326,9 @@ class UserView(APIView):
|
||||
return Response(context, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Does not allow this 'mistake' if the last login was sometime ago (5 minutes)
|
||||
if request.user.last_login < timezone.now() - timedelta(minutes=5):
|
||||
context['bad_request'] = f'You are already logged in as {request.user}'
|
||||
return Response(context, status.HTTP_400_BAD_REQUEST)
|
||||
# if request.user.last_login < timezone.now() - timedelta(minutes=5):
|
||||
# context['bad_request'] = f'You are already logged in as {request.user}'
|
||||
# return Response(context, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
token = request.GET.get(self.lookup_url_kwarg)
|
||||
|
||||
|
@ -256,7 +256,7 @@ export default class TradeBox extends Component {
|
||||
<ListItemIcon>
|
||||
<SmartToyIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={999} secondary="Robots looking at the book"/>
|
||||
<ListItemText primary={'000 coming soon'} secondary="Robots looking at the book"/>
|
||||
</ListItem>
|
||||
|
||||
<Divider/>
|
||||
@ -272,7 +272,8 @@ export default class TradeBox extends Component {
|
||||
<ListItemIcon>
|
||||
<PercentIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText primary="33%" secondary="Premium percentile" />
|
||||
<ListItemText primary={"Premium rank " + this.props.data.premiumPercentile*100+"%"}
|
||||
secondary={"Among public " + this.props.data.currencyCode + " orders (higher is cheaper)"} />
|
||||
</ListItem>
|
||||
<Divider/>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user