def prepare_investment_order(self, cash, investmentOption): """ Submit an investment request for with an investment portfolio option selected from get_investment_option() """ # Place the order try: if 'optIndex' not in investmentOption: self.logger.error('The \'optIndex\' key is not present in investmentOption passed to sendInvestment()! This value is set when selecting the option from get_investment_option()') return False # Prepare the order (don't process response) payload = { 'order_amount': cash, 'lending_match_point': investmentOption['optIndex'], 'lending_match_version': 'v2' } util.get_url('/portfolio/recommendPortfolio.action', params=payload) # Get struts token return self.get_strut_token() except Exception as e: self.logger.error('Could not complete your order (although, it might have gone through): {0}'.format(str(e))) return False
def get_strut_token(self): """ Get the struts token from the place order page """ strutToken = '' try: response = util.get_url('/portfolio/placeOrder.action') soup = BeautifulSoup(response.text, "html5lib") strutTokenTag = soup.find('input', {'name': 'struts.token'}) if strutTokenTag: strutToken = strutTokenTag['value'] except Exception as e: self.logger.warning('Could not get struts token. Error message: {0}'.filter(str(e))) return strutToken
def get_portfolio_list(self): """ Return the list of portfolio names from the server """ foliosNames = [] try: response = util.get_url('/data/portfolioManagement?method=getLCPortfolios') json = response.json() # Get portfolios and create a list of names if json['result'] == 'success': folios = json['results'] for folio in folios: foliosNames.append(folio['portfolioName']) except Exception as e: self.logger.warning('Could not get list of portfolios for this account. Error message: {0}'.format(str(e))) return foliosNames
def get_cash_balance(self): """ Returns the cash balance available to invest """ cash = -1 try: response = util.get_url('/browse/cashBalanceAj.action') json = response.json() if json['result'] == 'success': self.logger.debug('Cash available: {0}'.format(json['cashBalance'])) cash = util.currency_to_float(json['cashBalance']) else: self.logger.error('Could not get cash balance: {0}'.format(response.text)) except Exception as e: self.logger.error('Could not get the cash balance on the account: {0}\nJSON: {1}'.format(str(e), response.text)) return cash