def __init__(self, investor_id, *order_notes): """ Constructor :param investor_id: int """ self._investor_id = investor_id self._order_notes = order_notes orders = list() for order_note in self._order_notes: order = { 'loanId': order_note.loan_id, 'requestedAmount': order_note.amount, } if order_note.portfolio_id is not None: order['portfolioId'] = order_note.portfolio_id orders.append(order) payload = { 'aid': investor_id, 'orders': orders, } response = request.post(self.url, json=payload) Response.__init__(self, response)
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response)
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response) # Formulate the list of portfolios self._list = list() for portfolio_json in self.json['myPortfolios']: self._list.append( Portfolio(self._investor_id, response=portfolio_json))
def search(self, filter_id=None, show_all=None): """ Apply filters and search for loans matching the specifications """ url = DNS + ENDPOINTS['loans'].format(version=API_VERSION) criteria = list() if filter_id is not None: criteria.append('filterId={}'.format(filter_id)) if show_all is not None: if show_all: criteria.append('showAll=true') else: criteria.append('showAll=false') if criteria: url += '?' + '&'.join(criteria) headers = {'X-LC-LISTING-VERSION': LISTING_VERSION} response = Response(request.get(url, headers=headers)) if not response.successful: fstr = "cannot search for any loans" raise LCError(fstr, details=json.dumps(response.json, indent=2)) # Reset the stored loans whenever we search again as long as the # latest request was successful self.loans = list() for loan_json in response.json['loans']: loan = Loan(loan_json) self.loans.append(loan)
def __init__(self, investor_id): """ Constructor :param investor_id: int """ self._investor_id = investor_id response = request.get(self.url) Response.__init__(self, response) self._notes = list() try: self._notes = [ Note(note_json) for note_json in self.json['myNotes'] ] except KeyError: pass
def pending(investor_id): """ Retrieve the pending transfers :param investor_id: int - the investor account id :returns: iterable of instance of lendingclub2.response.transfer.Transaction """ url = DNS + ENDPOINTS['pending_transfer'].format(version=API_VERSION, investor_id=investor_id) response = Response(request.get(url)) if not response.successful: fstr = "cannot find list of pending transactions" raise LCError(fstr, details=json.dumps(response.json, indent=2)) transactions = list() total_transactions = 0 try: total_transactions = response.json['transfers'] except KeyError: pass for key in range(total_transactions): transactions.append(Transaction(response.json[key])) return transactions
def add(investor_id, amount, frequency=TransferFrequency.NOW, start_date=None, end_date=None): """ Add fund to the account :param investor_id: int - the investor account id :param amount: float - amount to withdraw :param frequency: member of lendingclub2.config.TransferFrequency (default: TransferFrequency.NOW) :param start_date: instance of datetime.datetime - required if frequency is not TransferFrequency.NOW (default: None) :param end_date: instance of datetime.datetime - optional (default: None) :returns: instance of lendingclub2.response.Response """ url = DNS + ENDPOINTS['transfer'].format(version=API_VERSION, investor_id=investor_id) if not isinstance(frequency, TransferFrequency): fstr = "frequency parameter is not instance of TransferFrequency" raise LCError(fstr) if frequency != TransferFrequency.NOW: if start_date is None: fstr = "please specify start_date to transfer fund" hint = "start_date needs to be specified for future or recurring " \ "transfer" raise LCError(fstr, hint=hint) elif not isinstance(start_date, datetime.datetime): fstr = "start_date parameter needs to be an instance of datetime" raise LCError(fstr) if end_date is not None and not isinstance(end_date, datetime.datetime): fstr = "end_date parameter needs to be an instance of datetime" raise LCError(fstr) if amount <= 0.0: fstr = "amount has to be a positive number for transfer" raise LCError(fstr) payload = { 'transferFrequency': frequency.value, 'amount': amount, } if start_date is not None: payload['startDate'] = start_date.isoformat() if end_date is not None: payload['endDate'] = end_date.isoformat() return Response(request.post(url, json=payload))
def create(self, name, description=None): """ Create a new portfolio :param name: string - name of portfolio :param description: string - description of portfolio (default: None) """ payload = { 'actorId': self._investor_id, 'portfolioName': name, } if description is not None: payload['portfolioDescription'] = description response = request.post(self.url, json=payload) self._response = Response(response)
def cancel(investor_id, *transaction_ids): """ Cancel the pending transactions :param investor_id: int - the investor account id :param transaction_ids: iterable of int :returns: instance of lendingclub2.response.Response if successful, None if nothing to cancel """ if not transaction_ids: return None url = DNS + ENDPOINTS['cancel_transfer'].format(version=API_VERSION, investor_id=investor_id) payload = {'transferIds': list(transaction_ids)} return Response(request.post(url, json=payload))
def withdraw(investor_id, amount): """ Withdraw the account :param investor_id: int - the investor account id :param amount: float - amount to withdraw :returns: instance of lendingclub2.response.Response """ url = DNS + ENDPOINTS['withdraw'].format(version=API_VERSION, investor_id=investor_id) if amount <= 0.0: fstr = "amount has to be a positive number for withdrawal" raise LCError(fstr) payload = {'amount': amount} return Response(request.post(url, json=payload))