def home(request): from django.db import connection cursor = connection.cursor() titre="Home" form2 = LoginForm() if request.method == "POST" and request.user.is_authenticated(): trform = TransferForm(request.POST) if trform.is_valid(): transfer=Transfer() transfer.trader=Trader.objects.get(user=request.user) transfer.type=trform.cleaned_data["type"] transfer.volume=trform.cleaned_data["volume"] transfer.save() trform = TransferForm() trform.non_field_errors="Transfer successful !" else: trform = TransferForm() else: trform = TransferForm() marketPerf=[] for market in Market.objects.all(): if market.event.status==0 and market.event.globalEvent.dateClose>timezone.now(): tv=Market.objects.tradedVolume(market=market) if tv==None: tv=0 tv=float(Decimal(tv).quantize(Decimal('.01'), rounding=ROUND_DOWN)) marketPerf.append([market.id, tv]) marketPerf.sort(key=lambda k: (k[1]), reverse=True) marketPerf=marketPerf[0:3] perfData=[] perfName=[] for mp in range(0,3): market=Market.objects.get(id=marketPerf[mp][0]) marketId=marketPerf[mp][0] cursor.execute("SELECT price price, volume volume, side side, timestamp timestamp FROM markets_trade WHERE not nullTrade and market_id=%i ORDER BY timestamp DESC" % marketId) trades = dictfetchall(cursor) trades=trades[:20] graphData=[] i=20 for trade in trades: i=i-1 graphData.append([i,float(trade['price'])])#[trade['volume'], trade['price']]) perfData.append([mp, graphData]) if mp==0: n0=market.outcome id0=market.id if mp==1: n1=market.outcome id1=market.id if mp==2: n2=market.outcome id2=market.id return render(request, 'markets/home.html', locals())
def home(request): titre="Home" form2 = LoginForm() if request.method == "POST" and request.user.is_authenticated: trform = TransferForm(request.POST) if trform.is_valid(): transfer=Transfer() transfer.trader=Trader.objects.get(user=request.user) transfer.type=trform.cleaned_data["type"] transfer.volume=trform.cleaned_data["volume"] transfer.save() trform = TransferForm() trform.non_field_errors="Transfer successful !" else: trform = TransferForm() else: trform = TransferForm() return render(request, 'markets/home.html', locals())