コード例 #1
0
def game_loop():
	while True:
		#x = input('what do you want to do?')
		buy_inputs = ['b', 'buy']
		sell_inputs = ['s', 'sell']
		lookup_inputs = ['l', 'lookup']
		quote_inputs = ['q', 'quote']
		exit_inputs = ['e', 'exit']
		acceptable_inputs = buy_inputs \
				    + sell_inputs \
				    + lookup_inputs \
				    + quote_inputs \
				    + exit_inputs
		user_input = view.main_menu()
		if user_input.lower() in acceptable_inputs:
			if user_input.lower() in buy_inputs:
				pass
			elif user_input.lower() in sell_inputs:
				pass
			elif user_input.lower() in lookup_inputs:
				company_name = view.lookup_menu()
				ticker_symbol = model.get_ticker_symbol(company_name)
				return ticker_symbol
			elif user_input.lower() in  quote_inputs:
				ticker_symbol = view.quote_menu()
				last_price = model.get_last_price(ticker_symbol)
				return last_price
			elif user_input.lower() in exit_inputs:
				#TODO add exit message in the view module
				break
			else:
				return 'Error'
コード例 #2
0
def game_loop(username):
    # Main menu (balance, buy, sell, lookup, quote, portfolio, exit)
    main_done = False
    while not main_done:
        balance_inputs = ["a", "balance"]
        buy_inputs = ["b", "buy"]
        sell_inputs = ["s", "sell"]
        lookup_inputs = ["l", "lookup"]
        quote_inputs = ["q", "quote"]
        portfolio_inputs = ["p", "portfolio"]
        exit_inputs = ["e", "exit"]

        acceptable_inputs = balance_inputs\
           +buy_inputs\
           +sell_inputs\
           +lookup_inputs\
           +quote_inputs\
           +portfolio_inputs\
           +exit_inputs

        user_input = view.main_menu(username)
        # If the user input is acceptable.
        if user_input.lower() in acceptable_inputs:
            # Balance
            if user_input.lower() in balance_inputs:
                balance = model.get_balance(username)
                view.balance_menu(balance)
            # Buy
            elif user_input.lower() in buy_inputs:
                ticker_symbol, trade_volume = view.buy_menu()
                res = model.buy(ticker_symbol, trade_volume, username)
                view.display_response(res)
            # Sell
            elif user_input.lower() in sell_inputs:
                ticker_symbol, trade_volume = view.sell_menu()
                res = model.sell(ticker_symbol, trade_volume, username)
                view.display_response(res)
            # Lookup
            elif user_input.lower() in lookup_inputs:
                company_name = view.lookup_menu()
                ticker_symbol = model.get_ticker_symbol(company_name)
                view.display_ticker_symbol(ticker_symbol)
            # Quote
            elif user_input.lower() in quote_inputs:
                ticker_symbol = view.quote_menu()
                last_price = model.get_last_price(ticker_symbol)
                view.display_last_price(last_price)
            # Portfolio (Holdings)
            elif user_input.lower() in portfolio_inputs:
                df = model.get_holdings_dataframe(username)
                balance = model.get_balance(username)
                earnings = model.get_earnings(username)
                view.display_dataframe(df, balance, earnings, username)
            # Exit
            elif user_input.lower() in exit_inputs:
                view.exit_message()
                main_done = True
            # Otherwise
            else:
                return "Error"
コード例 #3
0
def buy(username):
    ticker_symbol = view.buy_menu_ticker_symbol()
    # Gets the current price so can show it to user before buying it.
    last_price = model.get_last_price(ticker_symbol)
    view.display_last_price(last_price, False)

    trade_volume = view.buy_menu_volume_confirmation()
    order_status = model.buy(ticker_symbol, int(trade_volume), username)
    if order_status == 'SUCCESS':
        view.display_success()
    elif order_status == 'NO_FUNDS':
        balance = model.get_current_balance(username)
        view.display_insufficient_funds(balance)
コード例 #4
0
def game_loop():
    while True:
        #x = input('what do you want to do?')
        acceptable_inputs = ['b', 's', 'l', 'q', 'e']
        user_input = view.main_menu()
        if user_input.lower() in acceptable_inputs:
            if user_input == 'b':
                pass
            elif user_input == 's':
                pass
            elif user_input == 'l':
                pass
            elif user_input == 'q':
                ticker_symbol = view.quote_menu()
                last_price = model.get_last_price(ticker_symbol)
                return last_price
            elif user_input == 'e':
                #TODO add exit message in the view module
                break
            else:
                return 'Error'
コード例 #5
0
def quote():
    ticker_symbol = view.quote_menu()
    last_price = model.get_last_price(ticker_symbol)
    view.display_last_price(last_price, True)