예제 #1
0
def lookup_price(ticker):
    # curl http://localhost:5000/api/price/nvda
    """ return the price of a given stock. no api authentication """
    price = get_price(ticker)
    if price is None:
        abort(404)
    return jsonify({
        "ticker": ticker,
        "price": price
    })
예제 #2
0
def main_loop(user):
    while True:
        view.main_menu(user)
        choice = view.get_choice()
        if choice.strip() == "10":
            return login_loop()
        if choice.strip()== "9":
            print(user.api_key)
            main_loop(user)        
        if choice.strip() == "8":
            company_name = input("Enter company name: ")
            print(get_ticker(company_name))
            main_loop(user)        
        if choice.strip() == "7":
            new_deposit = int(input("Enter deposit amount: $"))
            user.balance +=new_deposit
            user.save()
            main_loop(user)
        if choice.strip()== "6":
            ticker = input("Enter ticker symbol: ")
            print(user.trades_for(ticker))
            main_loop(user)
        if choice.strip()== "5":
            print(user.all_trades())
            main_loop(user)
        if choice.strip()== "4":
            ticker = input("Enter ticker symbol: ")
            amount = int(input("Enter amount of shares you want to sell: "))
            user.sell(ticker,amount)
            main_loop(user)
        if choice.strip() =='3':
            ticker = input("Enter ticker symbol: ")
            amount = int(input("Enter amount of shares you want to buy: "))
            user.buy(ticker,amount)
            main_loop(user)
        if choice.strip()=="2":
            ticker = input("Enter ticker symbol: ")
            print(get_price(ticker))
            main_loop(user)
        if choice.strip()=="1":
            print(user.all_positions())
            main_loop(user)
        else:
            view.error_bad_input()
            continue
예제 #3
0
def account_loop(user):
    selection = views.user_account_view(user.real_name, user.balance)
    while True:
        if selection.strip() == "1":
            pos = user.all_positions()
            print("{:<10}{:>10}".format("Ticker", "Amount"))
            for p in pos:
                print("{:<10}{:>10}".format(p.ticker, p.amount))
            input("Enter to continue...")
            account_loop(user)
        elif selection.strip() == "2":
            ticker = input("Enter ticker symbol ")
            print(get_price(ticker))
            input("Enter to continue...")
            account_loop(user)
        elif selection.strip() =="3":
            ticker = input("Enter ticker symbol: ").lower()
            buy_amt = int(input("Enter amount of shares you want to buy: "))
            try:
                user.buy(ticker,buy_amt)
            except ValueError:
                print("")
                ColorText("red", "\nInvalid Amount")
                time.sleep(1)
                account_loop(user)
            except InsufficientFundsError:
                print("")
                ColorText("red", "\nInsufficient Funds")
                time.sleep(1)
                account_loop(user)
            except Exception:
                print("")
                ColorText("red", "\nConnection Error")
                time.sleep(2)
                account_loop(user)
            account_loop(user)

        elif selection.strip() == "4":
            ticker = input("Enter ticker symbol: ").lower()
            sell_amt = int(input("Enter amount of shares you want to sell: "))
            try:
                user.sell(ticker,sell_amt)
            except ValueError:
                print("")
                ColorText("red", "\nInvalid Amount")
                time.sleep(1)
                account_loop(user)
            except InsufficientSharesError:
                print("")
                ColorText("red", "\nInsufficent Shares")
                time.sleep(1)
            except Exception:
                print("")
                ColorText("red", "\nConnection Error")
                time.sleep(2)
                account_loop(user)
            account_loop(user)
        elif selection.strip() == "5":
            trades = user.all_trades()
            print("{:<30}{:<10}{:>10}{:>10}".format("Date", "Ticker", "Price", "Shares"))
            for p in trades:
                print("{:<30}{:<10}{:>10}{:>10}".format(time.ctime(p.time), p.ticker, p.price, p.volume))
            input("Enter to continue...")
            account_loop(user)
        elif selection.strip() == "6":
            ticker = input("Enter ticker symbol: ").lower()
            trades = user.trades_for(ticker)

            print("{:<10}{:>10}{:>10}".format("Ticker", "Price", "Shares"))
            for p in trades:
                print("{:<10}{:>10}{:>10}".format(p.ticker, p.price, p.volume))

            input("Enter to continue...")
            account_loop(user)
        elif selection.strip() == "7":
            deposit = int(input("Enter the deposit amount: $"))
            user.balance += deposit
            user.save()
            ColorText("green", "Success!")
            time.sleep(1)
            account_loop(user)
        elif selection.strip() == "8":
            views.api_view(user.api_key)
            input("\nEnter to continue...")
            account_loop(user)
        elif selection.strip() == "9":
            run()
예제 #4
0
def lookup_price(ticker):
    """ return the price of a given stock. no api authentication """
    price = get_price(ticker)
    return jsonify({"ticker": ticker, "price": price})