Example #1
0
def alert(request):
    if request.method == 'GET':
        raise Http404
    else:
        GoalRecord.record("emailsubmitted", WebUser(request))
        email = request.POST['email']
        new_email = Email_Collector(email=email)
        new_email.save()
        return HttpResponse('ok')
def alert(request):
    if request.method == 'GET':
        raise Http404
    else:
        GoalRecord.record("emailsubmitted", WebUser(request))
        email = request.POST['email']
        new_email = Email_Collector(email=email)
        new_email.save()
        return HttpResponse('ok')
def query_data(request):        
    if request.method == "POST":
        raise Http404
    else:
        GoalRecord.record("query", WebUser(request))
        try:
            symbol = request.GET["symbol"]
            start_date = request.GET["start_date"].replace('/','')
            end_date = request.GET["end_date"].replace('/','')
            buy_query_1 = request.GET.getlist("buy_query_1")
            sell_query_1 = request.GET.getlist("sell_query_1")
            buy_query_2 = request.GET.getlist("buy_query_2")
            sell_query_2 = request.GET.getlist("sell_query_2")
            buy_query_3 = request.GET.getlist("buy_query_3")
            sell_query_3 = request.GET.getlist("sell_query_3")
            stop_loss_percent = request.GET.get("stop_loss_percent", None)
            
        except Exception as e:
            return HttpResponse(jsonpickle.encode(Return_Code(value="3001", contents=e)))
        
        utils = Utils()
        service = Service()
        buy_queries = []
        sell_queries = []

        if buy_query_1:
            buy_queries.append(buy_query_1)
        if buy_query_2:
            buy_queries.append(buy_query_2)
        if buy_query_3:
            buy_queries.append(buy_query_3)

        if sell_query_1:
            sell_queries.append(sell_query_1)
        if sell_query_2:
            sell_queries.append(sell_query_2)
        if sell_query_3:
            sell_queries.append(sell_query_3)
        
        if buy_queries and sell_queries:
            all_buy_points, buy_indicators_data_list = service.execute_logical_or_queries(symbol, start_date, end_date, buy_queries)
            all_sell_points, sell_indicators_data_list = service.execute_logical_or_queries(symbol, start_date, end_date, sell_queries)

            for indicators_data in sell_indicators_data_list:
			    buy_indicators_data_list.append(indicators_data)

            backtester = Backtester()
            account = TradingAccount(cash_balance=10000)
            timeline, account_summary = backtester.execute_long_strategy(all_buy_points, all_sell_points, account, stop_loss_percent)
	 
            indicators_data = utils.convert_indicators_data_to_nicks_specifications(buy_indicators_data_list)
            result = {"data":timeline, "indicators_data":indicators_data, "summary":account_summary}

        elif buy_queries and not sell_queries:
            all_buy_points, buy_indicators_data_list = service.execute_logical_or_queries(symbol, start_date, end_date, buy_queries)
            indicators_data = utils.convert_indicators_data_to_nicks_specifications(buy_indicators_data_list)
            result = {"data":all_buy_points, "indicators_data":indicators_data, "summary":None}

        elif not buy_queries and sell_queries:
            all_sell_points, sell_indicators_data_list = service.execute_logical_or_queries(symbol, start_date, end_date, sell_queries)
            indicators_data = utils.convert_indicators_data_to_nicks_specifications(sell_indicators_data_list)
            result = {"data":all_sell_points, "indicators_data":indicators_data, "summary":None}

        return HttpResponse(jsonpickle.encode(Return_Code(value="3000", contents=result)))    
def cheatsheet(request):
    GoalRecord.record("cheatsheet", WebUser(request))
    return render_to_response("cheatsheet.html", context_instance=RequestContext(request))
def tour(request):
    GoalRecord.record("tour", WebUser(request))
    return render_to_response("tour.html", context_instance=RequestContext(request))
Example #6
0
def cheatsheet(request):
    GoalRecord.record("cheatsheet", WebUser(request))
    return render_to_response("cheatsheet.html",
                              context_instance=RequestContext(request))
Example #7
0
def tour(request):
    GoalRecord.record("tour", WebUser(request))
    return render_to_response("tour.html",
                              context_instance=RequestContext(request))
Example #8
0
def query_data(request):
    if request.method == "POST":
        raise Http404
    else:
        GoalRecord.record("query", WebUser(request))
        try:
            symbol = request.GET["symbol"]
            start_date = request.GET["start_date"].replace('/', '')
            end_date = request.GET["end_date"].replace('/', '')
            buy_query_1 = request.GET.getlist("buy_query_1")
            sell_query_1 = request.GET.getlist("sell_query_1")
            buy_query_2 = request.GET.getlist("buy_query_2")
            sell_query_2 = request.GET.getlist("sell_query_2")
            buy_query_3 = request.GET.getlist("buy_query_3")
            sell_query_3 = request.GET.getlist("sell_query_3")
            stop_loss_percent = request.GET.get("stop_loss_percent", None)

        except Exception as e:
            return HttpResponse(
                jsonpickle.encode(Return_Code(value="3001", contents=e)))

        utils = Utils()
        service = Service()
        buy_queries = []
        sell_queries = []

        if buy_query_1:
            buy_queries.append(buy_query_1)
        if buy_query_2:
            buy_queries.append(buy_query_2)
        if buy_query_3:
            buy_queries.append(buy_query_3)

        if sell_query_1:
            sell_queries.append(sell_query_1)
        if sell_query_2:
            sell_queries.append(sell_query_2)
        if sell_query_3:
            sell_queries.append(sell_query_3)

        if buy_queries and sell_queries:
            all_buy_points, buy_indicators_data_list = service.execute_logical_or_queries(
                symbol, start_date, end_date, buy_queries)
            all_sell_points, sell_indicators_data_list = service.execute_logical_or_queries(
                symbol, start_date, end_date, sell_queries)

            for indicators_data in sell_indicators_data_list:
                buy_indicators_data_list.append(indicators_data)

            backtester = Backtester()
            account = TradingAccount(cash_balance=10000)
            timeline, account_summary = backtester.execute_long_strategy(
                all_buy_points, all_sell_points, account, stop_loss_percent)

            indicators_data = utils.convert_indicators_data_to_nicks_specifications(
                buy_indicators_data_list)
            result = {
                "data": timeline,
                "indicators_data": indicators_data,
                "summary": account_summary
            }

        elif buy_queries and not sell_queries:
            all_buy_points, buy_indicators_data_list = service.execute_logical_or_queries(
                symbol, start_date, end_date, buy_queries)
            indicators_data = utils.convert_indicators_data_to_nicks_specifications(
                buy_indicators_data_list)
            result = {
                "data": all_buy_points,
                "indicators_data": indicators_data,
                "summary": None
            }

        elif not buy_queries and sell_queries:
            all_sell_points, sell_indicators_data_list = service.execute_logical_or_queries(
                symbol, start_date, end_date, sell_queries)
            indicators_data = utils.convert_indicators_data_to_nicks_specifications(
                sell_indicators_data_list)
            result = {
                "data": all_sell_points,
                "indicators_data": indicators_data,
                "summary": None
            }

        return HttpResponse(
            jsonpickle.encode(Return_Code(value="3000", contents=result)))