Esempio n. 1
0
def getPortfolioInfo():
    portKey = "\'" + email + "_" + portName + "\'"
    queryGet = "select symbol, volume from portfolio_stocks where portfolioID=" + portKey
    cur.execute(queryGet)
    holds = cur.fetchall()
    symbs = []
    totalMarketVal = 0
    totalVariance = 0.00
    numStocks = 0

    for row in holds:
        curr_dict = {}
        symbol = row[0]
        volume = row[1]
        symbs.append(symbol)

        info = stockAPI.getStockQuote(symbol, "info")
        try:
            beta = stockAPI.getBeta(symbol)
        except:
            beta = .2
        open_price = info["open"]
        close_price = info["close"]
        volume_traded = info["volume"]

        # compute market val
        mk_val = int(float(close_price) * float(volume))
        # increment global market value
        totalMarketVal += mk_val
        market_val = str(mk_val)

        curr_dict["beta"] = beta
        curr_dict["open"] = open_price
        curr_dict["close"] = close_price
        curr_dict["volume_traded"] = volume_traded
        curr_dict["market_val"] = market_val
        curr_dict["shares_owned"] = volume

        # update portfolioInfoDict
        portfolio_info[symbol] = copy.deepcopy(curr_dict)

    return holds, symbs, totalMarketVal
Esempio n. 2
0
except ora.Error, e:
    print "Error %s<p>" % (e.args[0])
    sys.exit(1)

print("<body>")

# gather CGI arguments passed from the URL
arguments = cgi.FieldStorage()
email = arguments["email"].value
portName = arguments["portName"].value
symbol = arguments["symbol"].value
#print "<p>" + str([email, portName, symbol]) + "</p>"

# quote must exist!
# price per share
globalCurrQuote = stockAPI.getStockQuote(symbol, "close")

# gather number of shares that you own
numShares = 0


def getNumShares():
    portID = "\'" + email + "_" + portName + "\'"
    symbolQ = "\'" + symbol + "\'"
    query = "select volume from portfolio_stocks where portfolioID=" + portID + " and symbol=" + symbolQ
    #print "<p>"+str(query) +"</p>"
    cur.execute(query)
    rows = cur.fetchall()
    num = rows[0][0]
    #print "<p>"+str(num) +"</p>"