def record_repost(username, post_ID):
    check = Select().select_repost(username, post_ID)
    if check == None:
        Insert().insert_repost(username, post_ID)
        count = Select().select_repost_user(username)
        Insert().insert_repost_user(username, count)
    else:
        pass
Exemple #2
0
def portfolio_performance(username, type1, type2):
    bal = Select().select_balance(username)
    bor = Select().select_borrowed(username)
    balance = round((bal), 2)
    borrowed = round((bor), 2)
    m_r = 100000.00 - borrowed
    mrkt_val = round((market_value(username, type1, type2) + balance), 2)
    p_l = round((mrkt_val - 100000), 2)
    return f'{balance:.2f}', f'{borrowed:.2f}', f'{p_l:.2f}', f'{mrkt_val:.2f}', f'{m_r:.2f}'
def user_tweets(username):
    items = Select().select_all_user_posts(username)
    x = []
    for i in reversed(items):
        tweet = {'username': i[0], 'date': i[1], 'comment': i[2]}
        x.append(tweet)
    return x
def user_info(username):
    info = Select().select_user_info(username)
    return {
        'first': info[0][0],
        'posts': info[0][1],
        'reposts': info[0][2],
        'followers': info[0][3],
        'following': info[0][4]
    }
def orders(username):
    lst = Select().select_all_orders(username)
    h_list = []
    for unix_time,ticker,type,shares,price in lst:
        company_name = get_company_name(ticker)
        date = datetime.datetime.fromtimestamp(unix_time).strftime('%Y-%m-%d')
        total = price * float(shares)
        h_vars = [date,ticker,company_name,type,shares,price,total]
        h_list.append(h_vars)
    return reversed(h_list)
Exemple #6
0
def market_value(username, type1, type2):
    # MONEY LONGS
    lst = Select().select_mrkt_val(username, type1)
    m_v_list = []
    for ticker, shares in lst:
        last_price = get_last_price(ticker)
        m_v = last_price * shares
        m_v_list.append(m_v)
    long_total = sum(m_v_list)
    # MONEY SHORTS
    lst = Select().select_shrt_val(username, type2)
    m_v_list = []
    for ticker, shares in lst:
        last_price = get_last_price(ticker)
        m_v = last_price * shares
        m_v_list.append(m_v)
    pre_total = sum(m_v_list)
    bor = Select().select_borrowed(username)
    short_total = bor - pre_total
    total = long_total + short_total
    return total
def user_tweets(username):
    items = Select().select_all_user_posts(username)
    x = []
    for i in reversed(items):
        tweet = {
            'username': i[0],
            'date': i[1],
            'tweet': i[2],
            'reposts': i[3],
            'id': i[4],
            'repost': repost_counter(i[4])
        }
        x.append(tweet)
    return x
def logs(username):
    lst = Select().select_all_logs(username)
    h_list = []
    for unix_time,balance in lst:
        date = datetime.datetime.fromtimestamp(unix_time).strftime('%Y%m%d %H:%M:%S')
        h_vars = [date,balance]
        h_list.append(h_vars)
    start = h_list[ 0][0]
    start = datetime.strptime(start,'%Y%m%d %H:%M:%S')
    end   = h_list[-1][0]
    end   = datetime.strptime(end,"%Y%m%d %H:%M:%S")
    intv  = 10
    dif   = (end - start) / intv
    y = []
    for i in range(intv):
        x = (start + diff * i).strftime("%Y%m%d %H:%M:%S")
        y.append(x)
    y.append(end.strftime("%Y%m%d %H:%M:%S"))
    return y
def holdings(username):
    lst = Select().select_all_holdings(username)
    h_list = []
    for ticker,type,shares,vwap in lst:
        curr_shares = float(shares)
        company_name = get_company_name(ticker)
        last_price = round((get_last_price(ticker)),2)
        if last_price != None:
            total = round((last_price * curr_shares),2)
            long_p_l  = round((total - (curr_shares * vwap)),2)
            short_p_l = round(((curr_shares * vwap) - total),2)
            h_vars = [ticker,company_name,type,shares,last_price,total,long_p_l,short_p_l]
            h_list.append(h_vars)
        else:
            last_price = 'N/A'
            total = 'N/A'
            long_p_l  = 'N/A'
            short_p_l = 'N/A'
            h_vars = [ticker,company_name,type,shares,last_price,total,long_p_l,short_p_l]
            h_list.append(h_vars)
    return h_list
def repost_counter(post_ID):
    count = Select().select_repost_counter(post_ID)
    return count
def record_tweet(username, tweet, reposts):
    date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    Insert().insert_tweet(username, date, tweet, reposts)
    count = Select().select_post_user(username)
    Insert().insert_post_user(username, count)
def logging(username, password):
    user = Select().select_existing_account(username, password)
    return user
def user_info(username):
    info = Select().select_user_info(username)
    return {'first': info[0][0], 'prev': info[0][1]}