def setup(self): """ Setup the investor to run """ if self.verbose: print 'VERBOSE OUTPUT IS ON\n' if not self.authed: self.get_auth() self.settings.select_profile() print 'You have ${0} in your account, free to invest\n'.format(self.lc.get_cash_balance()) # Investment settings print 'Now let\'s define what you want to do' # Use the settings from last time if self.settings.profile_loaded is not False: summary = self.settings.show_summary() if summary is False: # there was an error with saved settings print '\nThere was an error with your saved settings. Please go through the prompts again.\n' self.settings.get_investment_settings() if util.prompt_yn('Would you like to use these settings?', 'y'): self.settings.save() # to save the email that was just entered else: self.settings.get_investment_settings() else: self.settings.get_investment_settings() # All ready to start running print '\nThat\'s all we need. Now, as long as this is running, your account will be checked every {0} minutes and invested if enough funds are available.\n'.format(self.settings['frequency'])
def confirm_settings(self): self.show_summary() if util.prompt_yn('Would you like to continue with these settings?', 'y'): self.save() else: self.get_investment_settings()
def setup(self): """ Setup the investor to run """ if self.verbose: print 'VERBOSE OUTPUT IS ON\n' if not self.authed: self.get_auth() self.settings.select_profile() print 'You have ${0} in your account, free to invest\n'.format( self.lc.get_cash_balance()) # Investment settings print 'Now let\'s define what you want to do' # Use the settings from last time if self.settings.profile_loaded is not False: summary = self.settings.show_summary() if summary is False: # there was an error with saved settings print '\nThere was an error with your saved settings. Please go through the prompts again.\n' self.settings.get_investment_settings() if util.prompt_yn('Would you like to use these settings?', 'y'): self.settings.save() # to save the email that was just entered else: self.settings.get_investment_settings() else: self.settings.get_investment_settings() # All ready to start running print '\nThat\'s all we need. Now, as long as this is running, your account will be checked every {0} minutes and invested if enough funds are available.\n'.format( self.settings['frequency'])
def setup(self): """ Setup the investor to run """ if self.verbose: print 'VERBOSE OUTPUT IS ON\n' print 'You have ${0} in your account, free to invest\n'.format(self.lc.get_cash_balance()) # Investment settings print 'Now that you\'re signed in, let\'s define what you want to do\n' # Use the settings from last time if self.settings.investing['min_percent'] is not False and self.settings.investing['max_percent'] is not False: self.settings.show_summary('Prior Settings') if util.prompt_yn('Would you like to use these settings from last time?', 'y'): self.settings.save() # to save the email that was just entered else: self.settings.get_investment_settings() else: self.settings.get_investment_settings() # All ready to start running print '\nThat\'s all we need. Now, as long as this is running, your account will be checked every {0} minutes and invested if enough funds are available.\n'.format(self.settings['frequency'])
def test_prompt_yn(self): # Yes util.get_input = lambda msg: "y" self.assertTrue(util.prompt_yn("msg")) util.get_input = lambda msg: "Y" self.assertTrue(util.prompt_yn("msg")) util.get_input = lambda msg: "Yes" self.assertTrue(util.prompt_yn("msg")) # No util.get_input = lambda msg: "n" self.assertFalse(util.prompt_yn("msg")) util.get_input = lambda msg: "N" self.assertFalse(util.prompt_yn("msg")) util.get_input = lambda msg: "No" self.assertFalse(util.prompt_yn("msg")) # Invalid user input def get_input(msg): self.count += 1 return "Hi" if self.count == 1 else "Y" util.get_input = get_input self.assertTrue(util.prompt_yn("msg")) self.assertEqual(self.count, 2)
def test_prompt_yn(self): # Yes util.get_input = lambda msg: 'y' self.assertTrue(util.prompt_yn('msg')) util.get_input = lambda msg: 'Y' self.assertTrue(util.prompt_yn('msg')) util.get_input = lambda msg: 'Yes' self.assertTrue(util.prompt_yn('msg')) # No util.get_input = lambda msg: 'n' self.assertFalse(util.prompt_yn('msg')) util.get_input = lambda msg: 'N' self.assertFalse(util.prompt_yn('msg')) util.get_input = lambda msg: 'No' self.assertFalse(util.prompt_yn('msg')) # Invalid user input def get_input(msg): self.count += 1 return 'Hi' if self.count == 1 else 'Y' util.get_input = get_input self.assertTrue(util.prompt_yn('msg')) self.assertEqual(self.count, 2)
def get_filter_settings(self): """ Setup the advanced portfolio filters (terms, grades, existing notes, etc.) """ # Saved filter saved_filters = self.investor.lc.get_saved_filters() if len(saved_filters) > 0 and util.prompt_yn('Would you like to select one of your saved filters from LendingClub.com?', self.investing['filter_id'] is not None): # Get the selected one from list (has to be same-same object) selected = None if self.investing['filter_id']: selected = self.investing['filter_id'] print '\nSelect a saved filter from the list below:' saved = self.list_picker( items=saved_filters, default=selected, label_key='name', id_key='id') if saved is False: print '\nDefine all your filters manually...' else: print 'Using {0}'.format(saved) self.investing['filters'] = saved self.investing['filter_id'] = saved.id return filters = Filter() # Manual entry print 'The following questions are from the filters section of the Invest page on LendingClub\n' # Existing loans filters['exclude_existing'] = util.prompt_yn('Exclude loans already invested in?', filters['exclude_existing']) # Funding progress rounded to the nearest tenth print '---------' print 'Funding progress' progress = util.prompt_float('Only include loans which already have at least __% funding (0 - 100)', filters['funding_progress']) filters['funding_progress'] = int(round(progress / 10) * 10) print '---------' print 'Choose term (36 - 60 month)' while(True): filters['term']['Year3'] = util.prompt_yn('Include 36 month term loans?', filters['term']['Year3']) filters['term']['Year5'] = util.prompt_yn('Include 60 month term loans?', filters['term']['Year5']) # Validate 1 was chosen if not filters['term']['Year3'] and not filters['term']['Year5']: print 'You have to AT LEAST choose one term length!' else: break print '---------' print 'Choose interest rate grades (7.4% - 24.84%)' while(True): if util.prompt_yn('Include ALL interest rate grades', filters['grades']['All']): filters['grades']['All'] = True else: filters['grades']['All'] = False filters['grades']['A'] = util.prompt_yn('A - ~7.41%', filters['grades']['A']) filters['grades']['B'] = util.prompt_yn('B - ~12.12%', filters['grades']['B']) filters['grades']['C'] = util.prompt_yn('C - ~15.80%', filters['grades']['C']) filters['grades']['D'] = util.prompt_yn('D - ~18.76%', filters['grades']['D']) filters['grades']['E'] = util.prompt_yn('E - ~21.49%', filters['grades']['E']) filters['grades']['F'] = util.prompt_yn('F - ~23.49%', filters['grades']['F']) filters['grades']['G'] = util.prompt_yn('G - ~24.84%', filters['grades']['G']) # Verify one was chosen gradeChosen = False for grade in filters['grades']: if filters['grades'][grade] is True: gradeChosen = True if not gradeChosen: print 'You have to AT LEAST choose one interest rate grade!' else: break self.investing['filters'] = filters
def get_investment_settings(self): """ Display a series of prompts to get how the user wants to invest their available cash. This fills out the investing dictionary. """ # Minimum cash print '---------' print 'The auto investor will automatically try to invest ALL available cash into a diversified portfolio' while(True): self.investing['min_cash'] = util.prompt_int('What\'s the MINIMUM amount of cash you want to invest each round?', self.investing['min_cash']) if self.investing['min_cash'] < 25: print '\nYou cannot invest less than $25. Please try again.' else: break # Min/max percent print '---------' while(True): print 'When auto investing, the LendingClub API will search for diversified investment portfolios available at that moment.' print 'To pick the appropriate one for you, it needs to know what the minimum and maximum AVERAGE interest rate value you will accept.' print 'The investment option closest to the maximum value will be chosen and all your available cash will be invested in it.\n' self.investing['min_percent'] = util.prompt_float('What\'s MININUM average interest rate portfolio that you will accept?', self.investing['min_percent']) # Max percent should default to being larger than the min percent if self.investing['max_percent'] is False or self.investing['max_percent'] < self.investing['min_percent']: self.investing['max_percent'] = self.investing['min_percent'] + 1 self.investing['max_percent'] = util.prompt_float('What\'s MAXIMUM average interest rate portfolio that you will accept?', self.investing['max_percent']) # Validation if self.investing['max_percent'] < self.investing['min_percent']: print 'The maximum value must be larger than, or equal to, the minimum value. Please try again.' elif self.investing['max_percent'] == self.investing['min_percent']: print 'It\'s very uncommon to find an available portfolio that will match an exact percent.' if not util.prompt_yn('Would you like to specify a broader range?'): break else: break # Max per note print '---------' while(True): self.investing['max_per_note'] = util.prompt_int('How much are you willing to invest per loan note (max per note)?', self.investing['max_per_note']) if self.investing['max_per_note'] < 25: print 'You have to invest AT LEAST $25 per note.' self.investing['max_per_note'] = 25 else: break # Portfolio print '---------' folioOption = False if self.investing['portfolio']: # if saved settings has a portfolio set, default the prompt to 'Y' to choose folioOption = 'y' if util.prompt_yn('Do you want to put your new investments into a named portfolio?', folioOption): self.investing['portfolio'] = self.portfolio_picker(self.investing['portfolio']) else: self.investing['portfolio'] = False print '\n---------' # Advanced filter settings if util.prompt_yn('Would you like to set advanced filter settings?', self.investing['filters'] is not False): self.get_filter_settings() # Review summary self.confirm_settings() return True
def test_prompt_yn_prefill(self): # User enters empty string, select prefill util.get_input = lambda msg: '' self.assertTrue(util.prompt_yn('msg', 'y')) self.assertFalse(util.prompt_yn('msg', 'n'))
""" base_dir = os.path.dirname(os.path.realpath(__file__)) app_dir = os.path.join(base_dir, '.folio_picker_test') settings = Settings(settings_dir=app_dir) investor = lcinvestor.AutoInvestor(settings=settings, verbose=True) investor.lc.get_portfolio_list = lambda names_only: ['apple', 'bar', 'foo'] """ With default option """ print('\nWith a default option') while True: chosen = settings.portfolio_picker('The default') print('You chose: {0}\n'.format(chosen)) if not util.prompt_yn('Again?', 'n'): break """ No default option """ print('\nWithout a default option') while True: chosen = settings.portfolio_picker() print('You chose: {0}\n'.format(chosen)) if not util.prompt_yn('Again?', 'n'): break """ No options """ print('\nWithout any options')
def test_prompt_yn_prefill(self): # User enters empty string, select prefill util.get_input = lambda msg: "" self.assertTrue(util.prompt_yn("msg", "y")) self.assertFalse(util.prompt_yn("msg", "n"))
base_dir = os.path.dirname(os.path.realpath(__file__)) app_dir = os.path.join(base_dir, '.folio_picker_test') settings = Settings(settings_dir=app_dir) investor = lcinvestor.AutoInvestor(settings=settings, verbose=True) investor.lc.get_portfolio_list = lambda names_only: ['apple', 'bar', 'foo'] """ With default option """ print '\nWith a default option' while True: chosen = settings.portfolio_picker('The default') print 'You chose: {0}\n'.format(chosen) if not util.prompt_yn('Again?', 'n'): break """ No default option """ print '\nWithout a default option' while True: chosen = settings.portfolio_picker() print 'You chose: {0}\n'.format(chosen) if not util.prompt_yn('Again?', 'n'): break """ No options
def get_filter_settings(self): """ Setup the advanced portfolio filters (terms, grades, existing notes, etc.) """ # Saved filter saved_filters = self.investor.lc.get_saved_filters() if len(saved_filters) > 0 and util.prompt_yn('Would you like to select one of your saved filters from LendingClub.com?', self.investing['filter_id'] is not None): # Get the selected one from list (has to be same-same object) selected = None if self.investing['filter_id']: selected = self.investing['filter_id'] print('\nSelect a saved filter from the list below:') saved = self.list_picker( items=saved_filters, default=selected, label_key='name', id_key='id') if saved is False: print('\nDefine all your filters manually...') else: print('Using {0}'.format(saved)) self.investing['filters'] = saved self.investing['filter_id'] = saved.id return filters = Filter() # Manual entry print('The following questions are from the filters section of the Invest page on LendingClub\n') # Existing loans filters['exclude_existing'] = util.prompt_yn('Exclude loans already invested in?', filters['exclude_existing']) # Funding progress rounded to the nearest tenth print('---------') print('Funding progress') progress = util.prompt_float('Only include loans which already have at least __% funding (0 - 100)', filters['funding_progress']) filters['funding_progress'] = int(round(progress / 10) * 10) print('---------') print('Choose term (36 - 60 month)') while(True): filters['term']['Year3'] = util.prompt_yn('Include 36 month term loans?', filters['term']['Year3']) filters['term']['Year5'] = util.prompt_yn('Include 60 month term loans?', filters['term']['Year5']) # Validate 1 was chosen if not filters['term']['Year3'] and not filters['term']['Year5']: print('You have to AT LEAST choose one term length!') else: break print('---------') print('Choose interest rate grades (7.4% - 24.84%)') while(True): if util.prompt_yn('Include ALL interest rate grades', filters['grades']['All']): filters['grades']['All'] = True else: filters['grades']['All'] = False filters['grades']['A'] = util.prompt_yn('A - ~7.41%', filters['grades']['A']) filters['grades']['B'] = util.prompt_yn('B - ~12.12%', filters['grades']['B']) filters['grades']['C'] = util.prompt_yn('C - ~15.80%', filters['grades']['C']) filters['grades']['D'] = util.prompt_yn('D - ~18.76%', filters['grades']['D']) filters['grades']['E'] = util.prompt_yn('E - ~21.49%', filters['grades']['E']) filters['grades']['F'] = util.prompt_yn('F - ~23.49%', filters['grades']['F']) filters['grades']['G'] = util.prompt_yn('G - ~24.84%', filters['grades']['G']) # Verify one was chosen gradeChosen = False for grade in filters['grades']: if filters['grades'][grade] is True: gradeChosen = True if not gradeChosen: print('You have to AT LEAST choose one interest rate grade!') else: break self.investing['filters'] = filters
def get_investment_settings(self): """ Display a series of prompts to get how the user wants to invest their available cash. This fills out the investing dictionary. """ # Minimum cash print('---------') print('The auto investor will automatically try to invest ALL available cash into a diversified portfolio') while(True): self.investing['min_cash'] = util.prompt_int('What\'s the MINIMUM amount of cash you want to invest each round?', self.investing['min_cash']) if self.investing['min_cash'] < 25: print('\nYou cannot invest less than $25. Please try again.') else: break # Min/max percent print('---------') while(True): print('When auto investing, the LendingClub API will search for diversified investment portfolios available at that moment.') print('To pick the appropriate one for you, it needs to know what the minimum and maximum AVERAGE interest rate value you will accept.') print('The investment option closest to the maximum value will be chosen and all your available cash will be invested in it.\n') self.investing['min_percent'] = util.prompt_float('What\'s MININUM average interest rate portfolio that you will accept?', self.investing['min_percent']) # Max percent should default to being larger than the min percent if self.investing['max_percent'] is False or self.investing['max_percent'] < self.investing['min_percent']: self.investing['max_percent'] = self.investing['min_percent'] + 1 self.investing['max_percent'] = util.prompt_float('What\'s MAXIMUM average interest rate portfolio that you will accept?', self.investing['max_percent']) # Validation if self.investing['max_percent'] < self.investing['min_percent']: print('The maximum value must be larger than, or equal to, the minimum value. Please try again.') elif self.investing['max_percent'] == self.investing['min_percent']: print('It\'s very uncommon to find an available portfolio that will match an exact percent.') if not util.prompt_yn('Would you like to specify a broader range?'): break else: break # Max per note print('---------') while(True): self.investing['max_per_note'] = util.prompt_int('How much are you willing to invest per loan note (max per note)?', self.investing['max_per_note']) if self.investing['max_per_note'] < 25: print('You have to invest AT LEAST $25 per note.') self.investing['max_per_note'] = 25 else: break # Portfolio print('---------') folioOption = False if self.investing['portfolio']: # if saved settings has a portfolio set, default the prompt to 'Y' to choose folioOption = 'y' if util.prompt_yn('Do you want to put your new investments into a named portfolio?', folioOption): self.investing['portfolio'] = self.portfolio_picker(self.investing['portfolio']) else: self.investing['portfolio'] = False print('\n---------') # Advanced filter settings if util.prompt_yn('Would you like to set advanced filter settings?', self.investing['filters'] is not False): self.get_filter_settings() # Review summary self.confirm_settings() return True