def browse_notes(self): """ Sends the filters to the Browse Notes API and returns a JSON of the notes found """ try: # Get all investment options filters = util.get_filter_json(self.settings['filters']) print 'Filter!\n', filters if filters is False: filters = 'default' payload = { 'method': 'search', 'filter': filters #'filter': '[{"m_id":39,"m_metadata":{"m_controlValues":[{"value":"Year3","label":"36-month","sqlValue":null,"valueIndex":0},{"value":"Year5","label":"60-month","sqlValue":null,"valueIndex":1}],"m_type":"MVAL","m_rep":"CHKBOX","m_label":"Term (36 - 60 month)","id":39,"m_onHoverHelp":"Select the loan maturities you are interested to invest in","m_className":"classname","m_defaultValue":[{"value":"Year3","label":"36-month","sqlValue":null,"valueIndex":0},{"value":"Year5","label":"60-month","sqlValue":null,"valueIndex":1}]},"m_value":[{"value":"Year3","label":"36-month","sqlValue":null,"valueIndex":0},{"value":"Year5","label":"60-month","sqlValue":null,"valueIndex":1}],"m_visible":false,"m_position":0},{"m_id":38,"m_metadata":{"m_controlValues":[{"value":true,"label":"Exclude loans invested in","sqlValue":null,"valueIndex":0}],"m_type":"SVAL","m_rep":"CHKBOX","m_label":"Exclude Loans already invested in","id":38,"m_onHoverHelp":"Use this filter to exclude loans from a borrower that you have already invested in.","m_className":"classname","m_defaultValue":[{"value":true,"label":"Exclude loans invested in","sqlValue":null,"valueIndex":0}]},"m_value":[{"value":true,"label":"Exclude loans invested in","sqlValue":null,"valueIndex":0}],"m_visible":false,"m_position":0},{"m_id":10,"m_metadata":{"m_controlValues":[{"value":"All","label":"All","sqlValue":null,"valueIndex":0},{"value":"D","label":"<span class=\\"grades d-loan-grade\\">D</span> 18.76%","sqlValue":null,"valueIndex":1},{"value":"A","label":"<span class=\\"grades a-loan-grade\\">A</span> 7.41%","sqlValue":null,"valueIndex":2},{"value":"E","label":"<span class=\\"grades e-loan-grade\\">E</span> 21.49%","sqlValue":null,"valueIndex":3},{"value":"B","label":"<span class=\\"grades b-loan-grade\\">B</span> 12.12%","sqlValue":null,"valueIndex":4},{"value":"F","label":"<span class=\\"grades f-loan-grade\\">F</span> 23.49%","sqlValue":null,"valueIndex":5},{"value":"C","label":"<span class=\\"grades c-loan-grade\\">C</span> 15.80%","sqlValue":null,"valueIndex":6},{"value":"G","label":"<span class=\\"grades g-loan-grade\\">G</span> 24.84%","sqlValue":null,"valueIndex":7}],"m_type":"MVAL","m_rep":"CHKBOX","m_label":"Interest Rate","id":10,"m_onHoverHelp":"Specify the interest rate ranges of the notes you are willing to invest in.","m_className":"short","m_defaultValue":[{"value":"All","label":"All","sqlValue":null,"valueIndex":0}]},"m_value":[{"value":"A","label":"<span class=\\"grades a-loan-grade\\">A</span> 7.41%","sqlValue":null,"valueIndex":2},{"value":"B","label":"<span class=\\"grades b-loan-grade\\">B</span> 12.12%","sqlValue":null,"valueIndex":4},{"value":"C","label":"<span class=\\"grades c-loan-grade\\">C</span> 15.80%","sqlValue":null,"valueIndex":6}],"m_visible":false,"m_position":0},{"m_id":37,"m_metadata":{"m_controlValues":null,"m_type":"SVAL","m_rep":"TEXTBOX","m_label":"Keyword","id":37,"m_onHoverHelp":"Type any keyword","m_className":"classname","m_defaultValue":[]},"m_value":null,"m_visible":false,"m_position":0}]' } response = util.post_url('/browse/browseNotesAj.action', data=payload) jsonRes = response.json() return jsonRes except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_tb(exc_traceback, limit=10, file=sys.stdout) self.logger.error(str(e)) return False
def get_investment_option(self, cash): """ When investing, lending club provides a list of investment portfolio options, all with different diversification of loan classes which come out to an average percent return. This method returns an investment option that best matches your available cash and min/max percentage (defined in investing) desired. If there are multiple options between min & max, the one closest to max will be chosen. """ try: maxPercent = self.settings['maxPercent'] minPercent = self.settings['minPercent'] # Get all investment options filters = util.get_filter_json(self.settings['filters']) if filters is False: filters = 'default' payload = { 'amount': cash, 'max_per_note': 0, 'filter': filters } response = util.post_url('/portfolio/lendingMatchOptionsV2.action', data=payload) json = response.json() if json['result'] == 'success' and 'lmOptions' in json: options = json['lmOptions'] lastOption = False # Loop through all the investment options i = 0 for option in options: option['optIndex'] = i # A perfect match if option['percentage'] == maxPercent: return option # Over the max elif option['percentage'] > maxPercent: break # Over the minimum elif option['percentage'] >= minPercent: lastOption = option i += 1 # If the perfect match wasn't found, return the last # option that was under the maximum percent return lastOption else: self.logger.error('Could not get investment portfolio options! Server responded with: {0}'.format(response.text)) return False except Exception as e: self.logger.error(str(e)) return False