一个借书俱乐部的图书馆,让你检查你的现金余额,搜索笔记,建立订单和投资。
lendingclub的Python项目详细描述
借贷俱乐部API
一个独立的python模块,用于与您的贷款俱乐部帐户进行交互。简而言之,它可以让你检查现金余额,搜索票据,建立订单,投资等等。
免责声明
我已经尽我所能测试了这个工具,但是我知道它可能有bug。使用风险自负!
手动安装
首先确保已安装依赖项,然后运行:
sudo python ./setup.py install
文件
查看完整的API documentation。
示例
下面是在python交互shell中使用lending club api模块的几个例子。
简单的搜索和排序
搜索B级贷款并在第一笔贷款中投资25美元:
>>> from lendingclub import LendingClub >>> from lendingclub.filters import Filter >>> lc = LendingClub() >>> lc.authenticate() Email:test@test.com Password: True >>> filters = Filter() >>> filters['grades']['B'] = True # Filter for only B grade loans >>> results = lc.search(filters) # Search using this filter >>> len(results['loans']) # See how many results returned 100 >>> results['loans'][0]['loan_id'] # See the loan_id of the first loan 1763030 >>> order = lc.start_order() # Start a new investment order >>> order.add(1763030, 25) # Add the first loan to the order with a $25 investment >>> order.execute() # Execute the order 1861879 >>> order.order_id # See the order ID 1861879 >>> order.assign_to_portfolio('Foo') # Assign the loans in this order to a portfolio called 'Foo' True
投资贷款组合
在这里,我们想投资400美元在一个只有B,C,D和E级债券的投资组合,平均总回报率在17%-19%之间。这类似于在lendingclub.com上的“投资”部分找到投资组合:
>>> from lendingclub import LendingClub >>> from lendingclub.filters import Filter >>> lc = LendingClub() >>> lc.authenticate() Email:test@test.com Password: True >>> filters = Filter() # Set the filters >>> filters['grades']['B'] = True # See Pro Tips for a shorter way to do this >>> filters['grades']['C'] = True >>> filters['grades']['D'] = True >>> filters['grades']['E'] = True >>> lc.get_cash_balance() # See the cash you have available for investing 463.80000000000001 # Find a portfolio to invest in ($400, between 17-19%, $25 per note) >>> portfolio = lc.build_portfolio(400, min_percent=17.0, max_percent=19.0, max_per_note=25, filters=filters) >>> len(portfolio['loan_fractions']) # See how many loans are in this portfolio 16 >>> loans_notes = portfolio['loan_fractions'] >>> order = lc.start_order() # Start a new order >>> order.add_batch(loans_notes) # Add the loans to the order >>> order.execute() # Execute the order 1861880
您的贷款票据
获取已投资的贷款票据列表(默认情况下,一次只返回100):
>>> from lendingclub import LendingClub >>> lc = LendingClub() >>> lc.authenticate() Email:test@test.com Password: True >>> notes = lc.my_notes() # Get the first 100 loan notes >>> len(notes['loans']) 100 >>> notes['total'] # See the total number of loan notes you have 630 >>> notes = lc.my_notes(start_index=100) # Get the next 100 loan notes >>> len(notes['loans']) 100 >>> notes = lc.my_notes(get_all=True) # Get all notes in one request (may be slow) >>> len(notes['loans']) 630
使用保存的过滤器
使用lendingclub.com上保存的筛选器搜索贷款请参见下面的注释:
>>> from lendingclub import LendingClub >>> from lendingclub.filters import SavedFilter >>> lc = LendingClub() >>> lc.authenticate() Email:test@test.com Password: True >>> filters = lc.get_saved_filters() # Get a list of all saved filters on LendinClub.com >>> print filters # I've pretty printed the output for you [ <SavedFilter: 12345, '90 Percent'>, <SavedFilter: 23456, 'Only A loans'> ] >>> filter = lc.get_saved_filter(23456) # Load a saved filter by ID 7611034 >>> filter.name u'Only A' >>> results = lc.search(filter) # Search for loan notes with that filter >>> len(results['loans']) 100
注意:使用保存的搜索筛选器时,应始终确认返回的结果与筛选器匹配。这是因为LendingClub的搜索API不够宽容。当我们从服务器获取保存的筛选器,然后将其发送到搜索API时,如果其中任何部分已被更改或损坏,LendingClub将执行通配符搜索,而不是使用筛选器。这个python模块中的代码非常注意保持过滤器的原始性并检查不一致性,但这不能替代个人投资者的勤奋。
批量投资
在一个动作中投资贷款列表:
>>> from lendingclub import LendingClub >>> lc = LendingClub(email='test@test.com', password='secret123') >>> lc.authenticate() True >>> loans = [1234, 2345, 3456] # Create a list of loan IDs >>> order = lc.start_order() # Start a new order >>> order.add_batch(loans, 25) # Invest $25 in each loan >>> order.execute() # Execute the order 1861880
获取更多注释详细信息
浏览便笺时,您可以通过请求“loandetailaj.action”url:
>>> import pprint as pp >>> from lendingclub import LendingClub >>> from lendingclub.filters import Filter >>> lc = LendingClub() >>> lc.authenticate() True >>> filters = Filter() >>> filters['grades']['B'] = True >>> results = lc.search(filters) >>> load_id = results['loans'][0]['loan_id'] >>> request = lc.session.get('/browse/loanDetailAj.action', query={'loan_id': load_id} ) >>> details = request.json() >>> pp.pprint(details) {u'DTI': u'21.24', u'amountDelinquent': u'$0.00', u'collectionsExcludingMedical': u'0', u'completeTenure': u'10+ years', u'creditDateShort': u'7/14/14', ... u'verifiedIncome': u'false'}
专业提示
电子邮件/密码
初始化LendingClub对象时设置电子邮件/密码:
lc = LendingClub(email='you@your.com', password='illnevertell')
过滤一个衬套
在init行中定义一些过滤器:
filters = Filter({'grades': {'B': True, 'C': True, 'D': True, 'E': True}})
许可证
麻省理工学院许可证(MIT)
版权所有(c)2013 Jeremy Gillick
兹免费准许任何人取得副本 本软件和相关文档文件(“软件”)的 在软件中不受限制,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许软件的用户 在满足以下条件的情况下,可以这样做:
上述版权公告及本许可公告须包括在 软件的所有副本或大部分。
本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中rwise,源于, 不属于或与软件、使用或其他交易有关 软件。