示例#1
0
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")
示例#2
0
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
示例#3
0
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)
示例#4
0
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)
示例#5
0
def getUserInfo():
    userId = request.args.get('userId')
    return json.dumps({'info': DbHelper.getUserInfo(userId)})
示例#6
0
server.secret_key = os.environ.get('secret_key', 'secret')

df = pd.read_csv(
    'https://raw.githubusercontent.com/plotly/datasets/master/hello-world-stock.csv'
)

app = dash.Dash('app', server=server)

app.scripts.config.serve_locally = False
dcc._js_dist[0][
    'external_url'] = 'https://cdn.plot.ly/plotly-basic-latest.min.js'

app.layout = html.Div([
    html.H1('Doomberg Stock Tickers'),
    dcc.Dropdown(id='my-dropdown',
                 options=DbHelper.getSymbolDictForFrontEndUse(),
                 value="User 1's Net Worth"),
    dcc.Dropdown(id='my-dropdown2',
                 options=DbHelper.getSymbolDictForFrontEndUse(),
                 value='SPY'),
    dcc.Dropdown(id='my-dropdown3',
                 options=DbHelper.getSymbolDictForFrontEndUse(),
                 value='TSLA'),
    dcc.Dropdown(id='my-dropdown4',
                 options=DbHelper.getSymbolDictForFrontEndUse(),
                 value='KWEB'),
    dcc.Dropdown(id='options',
                 options=[
                     {
                         'label': 'Normalize',
                         'value': 'Normalize'
示例#7
0
def getPortfolioStockListForUser(userId):
    return DbHelper.select(
        "SELECT DISTINCT(symbol) from users.portfolio where user_id = " +
        userId)
示例#8
0
def getPortfolioStockList():
    return DbHelper.select("SELECT DISTINCT(symbol) from users.portfolio")
示例#9
0
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]
示例#10
0
def getMostRecentPrice(symbol):
    return DbHelper.select("SELECT price from Stocks.price where symbol = '" +
                           symbol + "' ORDER BY price_ts DESC LIMIT 1")
示例#11
0
def getAllUserIds():
    return DbHelper.select(
        "SELECT user_id from users.user ORDER BY user_id ASC")