Exemplo n.º 1
0
def bidcheck(request):
	date = datetime.now()
	hour = (date.time()).hour

	if hour < 0:
		message = notification(user_id=request.session['login_id'],notification = "Order cannot be processed. Market Closed")
		message.save()
		return HttpResponseRedirect('/marketwatch/')
	if request.method == 'POST':
		shareId = share.objects.get(pk=request.POST['share'])
		bidderId = login.objects.get(pk=request.session['login_id'])
		b = bid(bidder = bidderId, share = shareId, quantity=request.POST['quantity'], quote=request.POST['price'])
		min = round(shareId.day_value * 0.9, 2)
		max = round(shareId.day_value * 1.1, 2)
		quote = round(decimal.Decimal(b.quote), 2)
		if quote < min or quote > max:
			message = notification(user_id=request.session['login_id'],notification = "Quote unsuccessful. Quote price out of bounds")
			message.save()
			return HttpResponseRedirect(request.META['HTTP_REFERER'])
		b.save()
		data = "bid"
		dummy(shareId,request)
		checktransaction(shareId,data,request)
		return HttpResponseRedirect(request.META['HTTP_REFERER'])
	else:
		return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemplo n.º 2
0
def bidcheck(request):
	date = datetime.now()
	hour = (date.time()).hour
	if hour > 0:
		message = notification(user_id=request.session['login_id'],notification = "Order cannot be processed. Market Closed")
		return HttpResponse(json.dumps({"server_response":"wronginput"}), mimetype='application/javascript')
		message.save()
		return HttpResponseRedirect('/marketwatch/')
# remember to change response type
	if request.method == 'POST':
	        if request.POST['quantity']=="" or request.POST['price']=="":
        	        return HttpResponse(json.dumps({"server_response":"wronginput"}), mimetype='application/javascript')
		shareId = share.objects.get(pk=request.POST['share'])
		bidderId = login.objects.get(pk=request.session['login_id'])
		b = bid(bidder = bidderId, share = shareId, quantity=request.POST['quantity'], quote=request.POST['price'])
		min = round(shareId.day_value * 0.9, 2)
		max = round(shareId.day_value * 1.1, 2)
		quote = round(decimal.Decimal(b.quote), 2)
		if quote < min or quote > max:
			message = notification(user_id=request.session['login_id'],notification = "Quote unsuccessful. Quote price out of bounds")
			message.save()
	                return HttpResponse(json.dumps({"server_response":"wronginput"}), mimetype='application/javascript')

		b.save()
		data = "bid"
		dummy(shareId,request)
		checktransaction(shareId,data,request)
#		return HttpResponseRedirect(request.META['HTTP_REFERER'])
		return HttpResponse(json.dumps({"server_response":"biddone"}), mimetype='application/javascript')
	else:
                return HttpResponseRedirect('/marketwatch/')
Exemplo n.º 3
0
def dummy(shareId,request):
	dummy = login.objects.get(email='*****@*****.**')
	#change dummy money here
	try:
		bidMoney = bid.objects.filter(bidder_id=request.session['login_id'],share=shareId).order_by('-id')[0].quote
		bidQuantity = bid.objects.filter(bidder_id=request.session['login_id'],share=shareId).order_by('-id')[0].quantity
		totalBidValue = bidMoney*bidQuantity
	except:
		totalBidValue = 0
	try:
		offerMoney = offer.objects.filter(seller_id=request.session['login_id'],share=shareId).order_by('-id')[0].quote
		offerQuantity = offer.objects.filter(seller_id=request.session['login_id'],share=shareId).order_by('-id')[0].quantity
		totalOfferValue = offerMoney*offerQuantity
	except:
		totalOfferValue = 0
	try:
		current_price = ((transactions.objects.filter(share=shareId).order_by('-id'))[0]).price
	except:
		current_price = shareId.day_value
	totalValue=max(totalBidValue, totalOfferValue)
	
	dummyquantity = totalValue * 0.4 / current_price
	if dummyquantity<1:
		dummyquantity = 10
	multiplier = 0.01
	if shareId.id == 13:
		multiplier = 0.03
	start = current_price
	stopbid = current_price  - shareId.day_value * multiplier
	stopoffer = current_price + shareId.day_value * multiplier
	step = 0.001
	f = .001
	
	for i in range(3):
		b = bid(bidder=dummy, share=shareId, quantity=dummyquantity, quote=round((random.randrange(round(stopbid/f),round(start/f),round(step/f))*f),2))
		s = offer(seller=dummy, share=shareId, quantity=dummyquantity, quote=round((random.randrange(round(start/f),round(stopoffer/f),round(step/f))*f),2))
		b.save()
		s.save()
	
	checktransaction(shareId, "bid", request)
Exemplo n.º 4
0
def eod(request):
	if request.method == 'POST':
		if request.POST['password'] == "bowchikawowwow":
			shares = share.objects.all()
			dummy = login.objects.get(email='*****@*****.**')
				
			cursor = connection.cursor()
			cursor.execute("TRUNCATE TABLE `transaction_bid`")
			cursor.execute("TRUNCATE TABLE `transaction_offer`")
			
			for shareId in shares:
					try:
						current_price = round(((transactions.objects.filter(share=shareId).order_by('-id'))[0]).price,2)
					except:
						current_price = shareId.day_value
					shareId.day_value = current_price
					shareId.save()
					
					
					start = shareId.day_value
					stopbid = shareId.day_value - shareId.day_value * 0.01
					stopoffer = shareId.day_value + shareId.day_value * 0.01
					step = 0.001
					f = .001
					
					dummyquantity = round(40000/current_price)
					
					for i in range(3):
						b = bid(bidder=dummy, share=shareId, quantity=dummyquantity, quote=round((random.randrange(round(stopbid/f),round(start/f),round(step/f))*f),2))
						s = offer(seller=dummy, share=shareId, quantity=dummyquantity, quote=round((random.randrange(round(start/f),round(stopoffer/f),round(step/f))*f),2))
						b.save()
						s.save()
			return HttpResponseRedirect(request.META['HTTP_REFERER'])
		else:
			return HttpResponseRedirect(request.META['HTTP_REFERER'])
	else:
		return HttpResponseRedirect(request.META['HTTP_REFERER'])