Skip to content

Commit

Permalink
new version released
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmysoa committed Apr 22, 2015
1 parent 321d264 commit f09a6d3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 39 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ Quick Start
Change Logs
------

0.2.6
========
- 新增沪市融资融券列表
- 新增沪市融资融券明细列表
- 新增深市融资融券列表
- 新增深市融资融券明细列表
- 修正复权数据数据源出现null造成异常问题(对大约300个股票有影响)

0.2.5 2015/04/16
===========
- 完成python2.x和python3.x兼容性支持
Expand Down
43 changes: 43 additions & 0 deletions test/fund_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding:utf-8 -*-

import unittest
import tushare.stock.fundamental as fd

class Test(unittest.TestCase):

def set_data(self):
self.code = '600848'
self.start = '2015-01-03'
self.end = '2015-04-07'
self.year = 2014
self.quarter = 4

def test_get_stock_basics(self):
print(fd.get_stock_basics())

def test_get_report_data(self):
self.set_data()
print(fd.get_report_data(self.year, self.quarter))

def test_get_profit_data(self):
self.set_data()
print(fd.get_profit_data(self.year, self.quarter))

def test_get_operation_data(self):
self.set_data()
print(fd.get_operation_data(self.year, self.quarter))

def test_get_growth_data(self):
self.set_data()
print(fd.get_growth_data(self.year, self.quarter))

def test_get_debtpaying_data(self):
self.set_data()
print(fd.get_debtpaying_data(self.year, self.quarter))

def test_get_cashflow_data(self):
self.set_data()
print(fd.get_cashflow_data(self.year, self.quarter))

if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions test/ref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ def test_fund_holdings(self):

def test_new_stocksa(self):
print(fd.new_stocks())


def test_sh_margin_details(self):
self.set_data()
print(fd.sh_margin_details(self.start, self.end, self.code))

def test_sh_margins(self):
self.set_data()
print(fd.sh_margins(self.start, self.end))

def test_sz_margins(self):
self.set_data()
print(fd.sz_margins(self.start, self.end))

def test_sz_margin_details(self):
self.set_data()
print(fd.sz_margin_details(self.end))

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tushare/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.2.6'
__version__ = '0.2.7'
__author__ = 'Jimmy Liu'

"""
Expand Down
6 changes: 3 additions & 3 deletions tushare/stock/ref_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
NEW_STOCKS_COLS = ['code', 'name', 'ipo_date', 'issue_date', 'amount', 'markets', 'price', 'pe',
'limit', 'funds', 'ballot']
MAR_SH_COOKIESTR = '_gscu_1808689395=27850607moztu036'
MAR_SH_HZ_COLS = ['date', 'rzye', 'rzmre', 'rqyl', 'rqylje', 'rqmcl', 'rzrqjyzl']
MAR_SH_MX_COLS = ['date', 'code', 'name', 'rzye', 'rzmre', 'rzche', 'rqyl', 'rqmcl', 'rqchl']
MAR_SH_HZ_COLS = ['opDate', 'rzye', 'rzmre', 'rqyl', 'rqylje', 'rqmcl', 'rzrqjyzl']
MAR_SH_MX_COLS = ['opDate', 'stockCode', 'securityAbbr', 'rzye', 'rzmre', 'rzche', 'rqyl', 'rqmcl', 'rqchl']
MAR_SZ_HZ_COLS = ['rzmre', 'rzye', 'rqmcl', 'rqyl', 'rqye', 'rzrqye']
MAR_SZ_MX_COLS = ['code', 'name', 'rzmre', 'rzye', 'rqmcl', 'rqyl', 'rqye', 'rzrqye']
MAR_SZ_MX_COLS = ['stockCode', 'securityAbbr', 'rzmre', 'rzye', 'rqmcl', 'rqyl', 'rqye', 'rzrqye']
MAR_SZ_HZ_MSG = 'please do not input more than a year,you can obtaining the data year by year.'
MAR_SZ_HZ_MSG2 = 'start and end date all need input.'
70 changes: 35 additions & 35 deletions tushare/stock/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,27 +306,27 @@ def _holding_cotent(start, end, pageNo, retry_count, pause):
if pageNo>0:
ct._write_console()
try:
with urlopen(url) as resp:
lines = resp.read()
lines = lines.decode('utf-8') if ct.PY3 else lines
lines = lines.replace('--', '0')
lines = json.loads(lines)
data = lines['list']
df = pd.DataFrame(data)
df = df.drop(['CODE', 'ESYMBOL', 'EXCHANGE', 'NAME', 'RN', 'SHANGQIGUSHU',
request = Request(url)
lines = urlopen(request, timeout = 10).read()
lines = lines.decode('utf-8') if ct.PY3 else lines
lines = lines.replace('--', '0')
lines = json.loads(lines)
data = lines['list']
df = pd.DataFrame(data)
df = df.drop(['CODE', 'ESYMBOL', 'EXCHANGE', 'NAME', 'RN', 'SHANGQIGUSHU',
'SHANGQISHIZHI', 'SHANGQISHULIANG'], axis=1)
for col in ['GUSHU', 'GUSHUBIJIAO', 'SHIZHI', 'SCSTC27']:
df[col] = df[col].astype(float)
df['SCSTC27'] = df['SCSTC27']*100
df['GUSHU'] = df['GUSHU']/10000
df['GUSHUBIJIAO'] = df['GUSHUBIJIAO']/10000
df['SHIZHI'] = df['SHIZHI']/10000
df['GUSHU'] = df['GUSHU'].map(ct.FORMAT)
df['GUSHUBIJIAO'] = df['GUSHUBIJIAO'].map(ct.FORMAT)
df['SHIZHI'] = df['SHIZHI'].map(ct.FORMAT)
df['SCSTC27'] = df['SCSTC27'].map(ct.FORMAT)
df.columns = rv.FUND_HOLDS_COLS
df = df[['code', 'name', 'date', 'nums', 'nlast', 'count',
for col in ['GUSHU', 'GUSHUBIJIAO', 'SHIZHI', 'SCSTC27']:
df[col] = df[col].astype(float)
df['SCSTC27'] = df['SCSTC27']*100
df['GUSHU'] = df['GUSHU']/10000
df['GUSHUBIJIAO'] = df['GUSHUBIJIAO']/10000
df['SHIZHI'] = df['SHIZHI']/10000
df['GUSHU'] = df['GUSHU'].map(ct.FORMAT)
df['GUSHUBIJIAO'] = df['GUSHUBIJIAO'].map(ct.FORMAT)
df['SHIZHI'] = df['SHIZHI'].map(ct.FORMAT)
df['SCSTC27'] = df['SCSTC27'].map(ct.FORMAT)
df.columns = rv.FUND_HOLDS_COLS
df = df[['code', 'name', 'date', 'nums', 'nlast', 'count',
'clast', 'amount', 'ratio']]
except _network_error_classes:
pass
Expand Down Expand Up @@ -419,7 +419,7 @@ def sh_margins(start=None, end=None, retry_count=3, pause=0.001):
Return
------
DataFrame
date:信用交易日期
opDate:信用交易日期
rzye:本日融资余额(元)
rzmre: 本日融资买入额(元)
rqyl: 本日融券余量
Expand Down Expand Up @@ -470,7 +470,7 @@ def _sh_hz(data, start=None, end=None,
pagecount = int(lines['pageHelp'].get('pageCount'))
datapage = int(pagecount/5+1 if pagecount%5>0 else pagecount/5)
df = pd.DataFrame(lines['result'], columns=rv.MAR_SH_HZ_COLS)
df['date'] = df['date'].map(lambda x: '%s-%s-%s'%(x[0:4], x[4:6], x[6:8]))
df['opDate'] = df['opDate'].map(lambda x: '%s-%s-%s'%(x[0:4], x[4:6], x[6:8]))
data = data.append(df, ignore_index=True)
if beginPage < datapage*5:
data = _sh_hz(data, start=start, end=end, pageNo=pageNo,
Expand Down Expand Up @@ -506,9 +506,9 @@ def sh_margin_details(date='', symbol='',
Return
------
DataFrame
date:信用交易日期
code:标的证券代码
name:标的证券简称
opDate:信用交易日期
stockCode:标的证券代码
securityAbbr:标的证券简称
rzye:本日融资余额(元)
rzmre: 本日融资买入额(元)
rzche:本日融资偿还额(元)
Expand Down Expand Up @@ -565,8 +565,8 @@ def _sh_mx(data, date='', start='', end='',
if pageNo == 6:
ct._write_tips(lines['pageHelp'].get('total'))
df = pd.DataFrame(lines['result'], columns=rv.MAR_SH_MX_COLS)
df['date'] = df['date'].map(lambda x: '%s-%s-%s'%(x[0:4], x[4:6], x[6:8]))
df = df.set_index('date')
df['opDate'] = df['opDate'].map(lambda x: '%s-%s-%s'%(x[0:4], x[4:6], x[6:8]))
df = df.set_index('opDate')
data = data.append(df, ignore_index=True)
if beginPage < datapage*5:
data = _sh_mx(data, start=start, end=end, pageNo=pageNo,
Expand Down Expand Up @@ -596,7 +596,7 @@ def sz_margins(start=None, end=None, retry_count=3, pause=0.001):
Return
------
DataFrame
date:信用交易日期(index)
opDate:信用交易日期(index)
rzmre: 融资买入额(元)
rzye:融资余额(元)
rqmcl: 融券卖出量
Expand Down Expand Up @@ -638,8 +638,8 @@ def _sz_hz(date='', retry_count=3, pause=0.001):
return pd.DataFrame()
df = pd.read_html(lines, skiprows=[0])[0]
df.columns = rv.MAR_SZ_HZ_COLS
df['date'] = date
df = df.set_index('date')
df['opDate'] = date
df = df.set_index('opDate')
except:
pass
else:
Expand All @@ -664,9 +664,9 @@ def sz_margin_details(date='', retry_count=3, pause=0.001):
Return
------
DataFrame
date:信用交易日期
code:标的证券代码
name:标的证券简称
opDate:信用交易日期
stockCode:标的证券代码
securityAbbr:标的证券简称
rzmre: 融资买入额(元)
rzye:融资余额(元)
rqmcl: 融券卖出量
Expand All @@ -685,8 +685,8 @@ def sz_margin_details(date='', retry_count=3, pause=0.001):
return pd.DataFrame()
df = pd.read_html(lines, skiprows=[0])[0]
df.columns = rv.MAR_SZ_MX_COLS
df['code'] = df['code'].map(lambda x:str(x).zfill(6))
df['date'] = date
df['stockCode'] = df['stockCode'].map(lambda x:str(x).zfill(6))
df['opDate'] = date
except:
pass
else:
Expand Down

0 comments on commit f09a6d3

Please sign in to comment.