def getStockPriceOverTimeDateFilter(symbol, dateRange): if "net worth" in symbol.lower(): userId = symbol[symbol.index(" ") + 1:symbol.index("'")] return DbHelper.select( "select net_worth from users.net_worth where user_id = " + userId + " and net_worth_ts > '" + dateRange + "'ORDER BY net_worth_ts DESC") return DbHelper.select("select price from stocks.price where symbol = '" + symbol + "' and price_ts > '" + dateRange + "'ORDER BY price_ts DESC")
def getUserInfo(userId): try: value = DbHelper.select("Select * from users.user where user_id = " + str(userId)) except Exception as e: value = "ERROR! -> " + str(e) return value
def getUserNetWorth(userId): try: value = DbHelper.select( "select net_worth from users.net_worth where user_id = " + str(userId) + "ORDER BY net_worth_ts DESC LIMIT 1") except Exception as e: value = "ERROR! -> " + str(e) return float(value)
def getNetWorthForUser(userId): records = DbHelper.select( "SELECT symbol,quantity from Users.portfolio where user_id = " + str(userId)) total = 0.0 for record in records: myList = record.split(",") price = DbStockPriceHelper.getMostRecentPrice(myList[0])[0] value = float(price) * float(myList[1]) total += value return round(total, 2)
def getPortfolioStockListForUser(userId): return DbHelper.select( "SELECT DISTINCT(symbol) from users.portfolio where user_id = " + userId)
def getPortfolioStockList(): return DbHelper.select("SELECT DISTINCT(symbol) from users.portfolio")
def getNetWorthTsForUser(userId): symbolList = DbPortfolioHelper.getPortfolioStockListForUser(userId) return DbHelper.select( "select price_ts from stocks.price where symbol in(" + str(symbolList).replace("[", "").replace("]", "") + ") ORDER BY price_ts desc LIMIT 1")[0]
def getMostRecentPrice(symbol): return DbHelper.select("SELECT price from Stocks.price where symbol = '" + symbol + "' ORDER BY price_ts DESC LIMIT 1")
def getAllUserIds(): return DbHelper.select( "SELECT user_id from users.user ORDER BY user_id ASC")