Esempio n. 1
0
def offercheck(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'])
		sellerId = login.objects.get(pk=request.session['login_id'])
		s = offer(seller = sellerId ,share = shareId , quantity=request.POST['quantity'],quote=request.POST['price'])
		userShare = user_share.objects.get(user_id=request.session['login_id'],share=shareId)
		min = round(shareId.day_value * 0.9, 2) 
		max = round(shareId.day_value * 1.1, 2)
		quote = round(decimal.Decimal(s.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'])
		if int(s.quantity) > userShare.quantity:
			message = notification(user_id=request.session['login_id'],notification="Quote unsuccessful. Not enough stocks to sell")
			message.save()
			return HttpResponseRedirect(request.META['HTTP_REFERER'])
			
		
		s.save()
		data = "sell"
		dummy(shareId,request)
		checktransaction(shareId,data,request)
		return HttpResponseRedirect(request.META['HTTP_REFERER'])
	else:
		return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 2
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)
Esempio n. 3
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'])