def submit_order(loans, purchase_unit): url = "https://api.lendingclub.com/api/investor/v1/accounts/%d/orders" % config.get_account_id() headers = { "Content-type" : "application/json", "Accept" : "application/json", "X-LC-LISTING-VERSION" : "1.2", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", "Authorization": config.get_api_token() } portfolio_id = config.get_portfolio_id() payload = { "aid": config.get_account_id(), "orders": [] } for loan in loans: payload["orders"].append( { "loanId": loan['id'], "requestedAmount": purchase_unit, "portfolioId": portfolio_id } ) print url print payload response = requests.post(url, data=json.dumps(payload), headers=headers) if response.status_code != 200: raise Exception('API request failed') return response.json()
def get_account_summary(): url = "https://api.lendingclub.com/api/investor/v1/accounts/%d/summary" % config.get_account_id() headers = { "Content-type" : "application/json", "Accept" : "application/json", "X-LC-LISTING-VERSION" : "1.2", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", "Authorization": config.get_api_token() } response = requests.get(url, headers=headers) if response.status_code != 200: raise Exception('API request failed') return response.json()
def dump_purchased_notes_detail_statuses_to_cvs(filename): url = "https://api.lendingclub.com/api/investor/v1/accounts/%d/detailednotes" % config.get_account_id() headers = { "Content-type" : "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", "Accept" : "text/csv", "Authorization": config.get_api_token() } response = requests.get(url, headers=headers) if response.status_code != 200: raise Exception('access denied') if not filename.endswith('.csv'): filename = filename + '.csv' with open(filename, "w") as csv_file: csv_file.write(response.text)
def get_available_loan_listings(): url = "https://api.lendingclub.com/api/investor/v1/loans/listing" headers = { "Content-type" : "application/json", "Accept" : "application/json", "X-LC-LISTING-VERSION" : "1.2", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", "Authorization": config.get_api_token() } payload = { "showAll" : "true" } response = requests.get(url, headers=headers, params=payload, stream=False) if response.status_code != 200: raise Exception('API request failed') return response.json()['loans']
def dump_available_loan_listings_to_cvs(filename): url = "https://api.lendingclub.com/api/investor/v1/loans/listing" headers = { "Content-type" : "application/json", "Accept" : "text/csv", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", "X-LC-LISTING-VERSION" : "1.2", "Authorization": config.get_api_token() } payload = { "showAll" : "true" } response = requests.get(url, headers=headers, params=payload) if response.status_code != 200: raise Exception('access denied') if not filename.endswith('.csv'): filename = filename + '.csv' with open(filename, "w") as csv_file: csv_file.write(response.text)