Пример #1
0
def company_search(comp):
    check = wrapper.Markit()
    data = check.company_search(comp)
    if (data is not None):
        return data
    else:
        return (False)
Пример #2
0
def get_quote(sym):
    quote = wrapper.Markit()
    data = quote.get_quote(sym)
    if (data is not None):
        return data
    else:
        return (False)
def transactErrorCheck(order_list, order_type, user):
    if len(order_list) != 2:
        print(view.invalidString("input",f"{order_type} menu"))
        transactStock(order_type,user)
    try:
        number_of_shares = int(order_list[1])
    except:
        print(view.invalidString("number of shares input",f"{order_type} menu"))
        transactStock(order_type,user)
    if int(number_of_shares) != float(number_of_shares):
        print(view.invalidString("number of shares input (decimals)",f"{order_type} menu"))
        transactStock(order_type,user)
    ticker = order_list[0].strip().upper()
    quote = wrapper.Markit().get_quote(ticker,"LastPrice","Timestamp")
    if quote == {}:
        print(view.invalidString("stock ticker input",f"{order_type} menu"))
        transactStock(order_type,user)
    if order_type == "buy":
        if not model.checkFunds(user['username'],quote['LastPrice'],number_of_shares):
            print(view.invalidString("funds to execute the buy order",f"{order_type} menu"))
            transactStock(order_type,user)
        else:
            return ticker, quote, number_of_shares
    elif order_type == "sell":
        if not model.checkStocks(user['username'],ticker,number_of_shares):
            print(view.invalidString(f"number of stocks entered. You don't have that many stocks of {ticker}",f"{order_type} menu"))
            transactStock(order_type,user)
        else:
            return ticker, quote, number_of_shares
Пример #4
0
def get_quote(symbol):
    quote = wrapper.Markit()
    data = quote.get_quote(symbol)
    if (data is not None):
        return data
    else:
        return ("Connection Error")
def stockTickerSearch(user):
    print(view.printTitle("Stock Ticker Search"))
    ticker_input = input(view.queryString("Stock Ticker: ")).strip().upper()
    quote = wrapper.Markit().get_quote(ticker_input,'Name','Symbol','LastPrice','Open','Timestamp')
    if quote == {}:
        print(view.invalidString("stock ticker","user page"))
    else:
        print(f"Information on {ticker_input}:")
        print(view.printDict(quote))
def companySearch(user):
    print(view.printTitle("Company Search"))
    company_name = input(view.queryString("Company Name"))
    companies = wrapper.Markit().company_search(company_name)
    if companies.empty:
        print(view.invalidString("company name","user page"))
    else:
        print(f"Company list that matches {company_name}:")
        print(companies.to_string(index = False))
Пример #7
0
def leaderboard(**kwargs):
    all_p = getAllPortfolios()
    all_p['current_price'] = all_p.apply(lambda x: wrapper.Markit().get_price(x['stock_ticker']), axis = 1)
    all_p['worth'] = all_p['number_of_shares_owned']*all_p['current_price']
    all_p = all_p[['username','worth']].groupby('username').sum().reset_index()
    banks = getAllBanks()
    final = pd.merge(all_p,banks,how = 'outer',on = ['username','username'])
    final.fillna(0,inplace = True)
    final['net_worth'] = final['worth'] + final['bank_account']
    return final.sort_values(['net_worth','username'],ascending = [0,1])[['username','net_worth']]
Пример #8
0
def quote():
    if (request.method == 'POST'):
        sym = request.form['name']
        quote = wrapper.Markit()
        data = quote.get_quote(sym)
        if (data is not None):
            return render_template("result.html", data=data, action="Quote")
        else:
            return render_template("index.html")
        return render_template("result.html", data=data, action="Quote")
Пример #9
0
def search():
    # form = CompanyForm()
    if (request.method == 'POST'):
        name = request.form['name']
        check = wrapper.Markit()
        data = check.company_search(name)
        if (data is not None):
            return render_template("result.html", data=data, action="Search")
        else:
            return render_template("index.html")
    return render_template("index.html")
Пример #10
0
def main():
    model.create_table()
    print('Welcome to Share Market, Login/Signin in to your Account')
    # username = input('Enter Username: '******'Enter Password: '******'admin':
        input("Hit any key to see the Top 10 Users.")
        model.Admin(username)
    else:
        print('Please select from below menu')
        print('a. Search for a Company'  )
        print('b. Get a quote')
        print('c. Buy Shares')
        print('d. Sell Shares')
        print('e. Earnings')
        print('f. Shares List')
        print('g. Exit')

        i=1
        while i>0:
            ch= input("Enter the menu item as a, b, c, d, e, f, g: ")
            cl = contr.Markit()
            if ch== 'a':
                symbol = input('To start the trade, please enter the name of the company. (For example AAPL for APPLE or A for All stocks that starts with A ): ')
                k, v = cl.company_search(symbol)
                model.Lookup(k,v)
            elif ch== 'b':
                #symbol = input('Enter the exact symbol of the company from above list:')
                k,v = cl.quote()
                model.Quote(k, v)
            elif ch== 'c':
                #symbol = input('Enter the exact symbol of the company from above list.')
                model.Shares_Buy(username, symbol)
            elif ch=='d':
                #symbol = input('Enter the exact symbol of the company from above list.')
                model.Shares_Sell(username, symbol)
            elif ch=='e':
                model.Earnings(username)
            elif ch=='f':
                model.SharesList(username)
            else:
                break
            i=i+1
Пример #11
0
def buy():
    if (request.method == 'POST'):
        sym = request.form['comp_sym']
        no = float(request.form['number'])
        quote = wrapper.Markit()
        data = quote.get_quote(sym)
        user = User.query.filter_by(email=session['email']).first()
        if (data == False):
            last_price = 0
        elif ('LastPrice' not in data):
            print("No Company Like that")
            return redirect(url_for('home'))
        else:
            last_price = data["LastPrice"]
        total = no * last_price
        if (session['amount'] <= total):
            error = "Insufficient Balance"
            return render_template('homepage.html', user=user, error=error)
        stocks = Stocks.query.filter_by(usemail=session['email']).all()
        flag = 0
        for i in stocks:
            if (i.symbol == sym):
                i.stocks_update(sym, no, "BUY")
                flag = 1
                break
        if flag == 0:
            newstock = Stocks(session['email'], sym, no)
            db.session.add(newstock)
            db.session.commit()

        newtrans = Transaction(session['email'], sym, no, last_price, total,
                               "BUY")
        db.session.add(newtrans)
        db.session.commit()

        user.update_amount(total, "BUY")
        db.session.add(user)
        db.session.commit()
        print(user.amount)
        error = None
    return redirect(url_for('home'))
Пример #12
0
def sell_shares():
    if (request.method == 'POST'):
        uid = request.form['uid']
        sym = request.form['comp_sym']
        no = float(request.form['number'])
        quote = wrapper.Markit()
        data = quote.get_quote(sym)
        if (data == False):
            last_price = 0
        elif ('LastPrice' not in data):
            print("No Company Like that")
            return redirect(url_for('home'))
        else:
            last_price = data["LastPrice"]
        total = no * last_price
        stocks = Stocks.query.filter_by(usemail=session['email']).all()
        for i in stocks:
            if (i.symbol == sym):
                if (i.stocks >= no):
                    i.stocks_update(sym, no, "SELL")

                    newtrans = Transaction(session['email'], sym, no,
                                           last_price, total, "SELL")
                    db.session.add(newtrans)
                    db.session.commit()
                    user = User.query.filter_by(email=session['email']).first()
                    user.update_amount(total, "SELL")
                    db.session.add(user)
                    db.session.commit()
                    break
                else:
                    print("You do not have that much stocks..")
            else:
                print("You do not have stock of the specified company..")

    return redirect(url_for('home'))
 row = cur.fetchall()
 cur.execute('''SELECT password FROM users''')
 row2 = cur.fetchall()
 testuser = str(row)
 testpwd = str(row2)
 if id1 in testuser:
     if pwd in testpwd:
         while (flag2 == 0):
             print("DASHBOARD OF USER: "******"\n")
             opt = int(
                 input(
                     "CLICK THE BELOW OPTIONS TO CONTINUE\n1-Search Stocks by company name\n2-Update and View Existing Stocks\n3-Buy Stocks\n4-Sell Stocks\n5-Exit\n"
                 ))
             if (opt == 1):
                 try:
                     m = wrapper.Markit()
                     name = input('Enter the Company Name\n')
                     name = name.upper()
                     print(name)
                     formal_name, ticker_symbol, exchange = m.company_search(
                         name)
                     print("formal name: ", formal_name)
                     print("ticker symbol: ", ticker_symbol)
                     print("exchnage: ", exchange)
                     last_price = m.get_quote(ticker_symbol)
                     print("last stock price: ", last_price)
                 except:
                     print(
                         "Error - API has been called too many times or Wrong Input - Try again after sometime"
                     )
             elif (opt == 2):
Пример #14
0
import wrapper

wrap = wrapper.Markit()


def userfunctions(userlogin, userid):

    print('\n---------------')
    print('Welcome ' + userlogin + ' !')
    print('----------------')
    print('\nWhat would you like to do today?\n')
    #print(userid)

    options = [
        'Search for a company and get its stock ticker symbol ', 'Buy stock',
        'Sell stock', 'View your current portfolio', 'Log out'
    ]

    index = 1

    for items in options:
        print(str(index) + '. ' + items)
        index += 1

    try:
        choice = input('\nEnter your choice(1-5): ')
        choice = int(choice)

    except ValueError as e:
        if not choice:
            print("\nEmpty input!")