def leaderboards(apikey): username = model.api_authenticate(apikey) lb = model.leaderboard(username) if not username: return jsonify({'error': 'could not authenticate'}) if not lb: return jsonify({'error': 'No leaderboards yet...'}) return jsonify({'leaderboards': lb})
def get_balance(apikey): user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) return jsonify({ "username": user_name, "balance": model.get_balance(user_name) })
def current_balance(apikey): username = model.api_authenticate(apikey) if not username: return jsonify({'error': 'could not authenticate'}) return jsonify({ 'username': username, 'balance': model.current_balance(username) }) return ('API Trader')
def lookup(apikey, company_name): username = model.api_authenticate(apikey) if not username: return jsonify({'error': 'could not authenticate'}) return jsonify({ 'Username': username, 'balance': model.current_balance(username), 'Results': model.get_lookup(company_name) })
def get_quote(apikey): if not request.json or not 'Ticker' in request.json: abort(400) if not isinstance(request.json['Ticker'], (str)): abort(400) user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) ticker = request.json['Ticker'] return jsonify({"Ticker": ticker, "price": model.quote(ticker)})
def get_lookup(apikey): if not request.json or not 'Company' in request.json: abort(400) if not isinstance(request.json['Company'], (str)): abort(400) user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) company = request.json['Company'] return jsonify({"Ticker": model.lookup(company)})
def get_buy(apikey): if not request.json or not 'Ticker' and 'Shares' in request.json: abort(400) if not isinstance(request.json['Ticker'], (str)): abort(400) if not isinstance(request.json['Shares'], (int)): abort(400) user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) ticker = request.json['Ticker'] shares = request.json['Shares'] return jsonify(model.buy(ticker, shares, user_name))
def get_deposit(apikey): if not request.json or not 'Deposit' in request.json: abort(400) if not isinstance(request.json['Deposit'], (float, int)): abort(400) user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) money = request.json['Deposit'] model.deposit(user_name, money) return jsonify({ "username": user_name, "Deposit": money, "Balance": model.get_balance(user_name) })
def get_holdings(apikey): user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) return jsonify(model.print_holdings(user_name))
def get_dashboard(apikey): user_name = model.api_authenticate(apikey) if not user_name: return (jsonify({"error": "count not authenticate"})) return jsonify(model.dashboard(user_name))
def api_authenticate(apikey): row = m.api_authenticate(apikey) if row is None: return None, None else: return row