def add(self, irc, msg, args, amount, symbol): """<amount> <symbol> Add <amount> of shares of <symbol> to your portfolio. """ user = self._check_auth(irc, msg) if user: p = PortfolioManager(user.name) try: (symbol, amount, price) = p.add(symbol, amount) irc.reply("Added %s shares of '%s' at %s" % (amount, symbol, price)) except PortfolioError, e: irc.reply(e)
def remove(self, irc, msg, args, symbol, amount, price=None): """<symbol> [amount] Remove shares from your portfolio. If [amount] is unspecified, we erase all shares under <symbol> """ user = self._check_auth(irc, msg) if user: p = PortfolioManager(user.name) try: removed = p.remove(symbol, amount, price) except PortfolioError, e: irc.reply(e) return False irc.reply("Removed %s shares of '%s'" % (removed, symbol))
def show(self, irc, msg, args): user = self._check_auth(irc, msg) if user: p = PortfolioManager(user.name) current_value = 0 initial_value = 0 for stock in p: for batch in p[stock]: paid = batch.getInitialValue() worth = batch.getCurrentValue() gains = batch.getTotalGains() current_value += worth initial_value += paid