Exemple #1
0
def fb_dme(request, ss="", scope="extrema", ns=1):
    ss = assure_ss(request, ss)
    r = cache_IEX(ss)
    if not r:
        messages.warning(request,
                         'Failed in analyzing the symbol ' + ss if ss else "")
        ss = ''
    if scope not in [i['scope'] for i in DME_SCOPES]:
        scope = 'extrema'
    watching = is_watching(request, ss) if ss else False
    if ss:
        d = deepcopy(DME_SCOPES)
        for i in d:
            i['api_url'] = i['api_url'].replace('$SS',
                                                ss).replace('$NS', str(ns))
        e = next(i for i in d if i['scope'] == scope)
        ob = next(i for i in STYPE_LIST if i['ftype'] == 'cfp')
    else:
        d = []
        e = {'api_url': '', 'desc': ''}
        ob = ''
    return render(
        request, 'famebits/fb_dailymoveevents.html', {
            'ss': ss,
            'watching': watching,
            'DME_SCOPES': d,
            'scope': scope,
            'api_url': e['api_url'],
            'desc': e['desc'],
            'ob': ob
        })
Exemple #2
0
def fb_sendoc(request, ss="", iex_id=""):
    ss = assure_ss(request, ss)
    rd = {}
    if ss and ss not in get_SP500():
        messages.warning(request,
                         'Non-SP500 stocks are not supported for Fame Sense')
        # return redirect
    else:
        rd['ss'] = ss
    if not table_exist('ff_finnews_f2') or not table_exist(
            'ff_finnews_f3') or not table_exist('ff_finnews_f4'):
        messages.warning(request, 'Fame Sense temporarily offline')
        # return redirect
    else:
        check_sym = runsql(
            "select a.*, b.iex_related, b.iex_title, b.article_url from (select * from ff_finnews_f2 where symbol='"
            + ss + "' and iex_id='" + str(iex_id) +
            "') a, ff_finnews_iex b where a.iex_id=b.iex_id limit 1")
        if not check_sym:
            messages.warning(request,
                             'Fame Sense has not processed that document')
        else:
            rd['iex_id'] = iex_id
            rd['title'] = check_sym[0]['iex_title']
            rd['url'] = "/re?s=" + ss + "&v=fb_sendoc&t=iexnews&u=" + check_sym[
                0]['article_url']
    rd['watching'] = is_watching(request, ss) if ss else False
    return render(request, 'famebits/fb_sense_doc.html', rd)
Exemple #3
0
def fb_bes(request, ss=""):
    ss = assure_ss(request, ss)
    if ss and ss not in get_SP500():
        messages.warning(request,
                         'Non-SP500 stocks are not supported for BestEver')
        ss = ''
    watching = is_watching(request, ss) if ss else False
    return render(request, 'famebits/fb_besteversent.html', {
        'ss': ss,
        'watching': watching
    })
Exemple #4
0
def fb_ahd(request, ss=""):
    ss = assure_ss(request, ss)
    r = cache_IEX(ss)
    if not r:
        messages.warning(request,
                         'Failed in analyzing the symbol ' + ss if ss else "")
        ss = ''
    watching = is_watching(request, ss) if ss else False
    return render(request, 'famebits/fb_fameahead.html', {
        'ss': ss,
        'watching': watching
    })
Exemple #5
0
def fb_chg(request, ss=""):
    ss = assure_ss(request, ss)
    r = cache_IEX(ss)
    if not r:
        messages.warning(request,
                         'Failed in analyzing the symbol ' + ss if ss else "")
    watching = is_watching(request, ss) if ss else False
    ob = next(i for i in STYPE_LIST if i['ftype'] == 'chg')
    return render(request, 'famebits/fb_changerate.html', {
        'ss': ss,
        'watching': watching,
        'ob': ob
    })
Exemple #6
0
def watchlist_entry(request, s="", action="", max_watch=30):
    s = assure_ss(request, s)
    action = action.lower()
    if action != "add" and action != "drop":
        return JsonResponse({"success": False, "message": "Invalid action"})
    if request.method != "POST" or not request.user.is_authenticated:
        return JsonResponse({
            "success": False,
            "message": "Invalid method or user not logged in"
        })
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    ipaddress = ""
    if x_forwarded_for:
        ipaddress = x_forwarded_for.split(',')[-1].strip()
    else:
        ipaddress = request.META.get('REMOTE_ADDR')
    request_view = request.POST.get("view", "")

    watching = [i['symbol'] for i in get_watched_symbols(request)]
    if action == "add":
        if not s:
            return JsonResponse({"message": "Empty symbol"})
        if s not in get_SP500() and not IEX_validator_single(s):
            return JsonResponse({"message": "Invalid symbol " + s})
        if len(watching) >= max_watch:
            return JsonResponse({
                "message":
                "Reached maximum " + str(max_watch) +
                " of watched symbols. Drop some"
            })
    else:
        # action == "drop"
        if s not in watching:
            return JsonResponse({"message": "Not watching " + s})

    o_watchlist = WatchList(
        uid=request.user if request.user.is_authenticated else None,
        request_dt=timezone.now(),
        request_ip=ipaddress,
        request_view=request_view,
        symbol=s,
        action=action)
    o_watchlist.save()
    return JsonResponse({"message": "Succeeded"})