Permalink
Browse files

0.6.2

  • Loading branch information...
1 parent 9bb6a2e commit fa5e837d9cbbf55a5e57e9c62aed72d6ec4dbe27 @jimmysoa jimmysoa committed Dec 4, 2016
Showing with 103 additions and 9 deletions.
  1. +6 −0 README.md
  2. +7 −3 tushare/__init__.py
  3. +17 −1 tushare/stock/cons.py
  4. +3 −0 tushare/stock/ref_vars.py
  5. +55 −4 tushare/stock/reference.py
  6. +15 −1 tushare/util/dateu.py
View
@@ -181,6 +181,12 @@ Quick Start
Change Logs
-----------
+0.6.2 2016/12/03
+==========
+- 新增十大股东和十大流通股接口 top10_holders
+- 新增全球实时指数列表接口 global_realtime
+- 修复部分bug
+
0.6.1 2016/11/22
===========
- 修正get_k_databug
View
@@ -1,4 +1,4 @@
-__version__ = '0.6.1'
+__version__ = '0.6.2'
__author__ = 'Jimmy Liu'
"""
@@ -52,7 +52,8 @@
xsg_data, fund_holdings,
new_stocks, sh_margins,
sh_margin_details,
- sz_margins, sz_margin_details)
+ sz_margins, sz_margin_details,
+ top10_holders)
"""
for shibor
@@ -100,4 +101,7 @@
"""
for futures API
"""
-from tushare.futures.intlfutures import (get_intlfuture)
+from tushare.futures.intlfutures import (get_intlfuture)
+
+
+from tushare.stock.globals import (global_realtime)
View
@@ -27,7 +27,7 @@
'sse': 'www.sse.com.cn', 'szse': 'www.szse.cn',
'oss': '218.244.146.57', 'idxip':'115.29.204.48',
'shibor': 'www.shibor.org', 'mbox':'www.cbooo.cn',
- 'tt': 'gtimg.cn'}
+ 'tt': 'gtimg.cn', 'gw': 'gw.com.cn'}
PAGES = {'fd': 'index.phtml', 'dl': 'downxls.php', 'jv': 'json_v2.php',
'cpt': 'newFLJK.php', 'ids': 'newSinaHy.php', 'lnews':'rollnews_ch_out_interface.php',
'ntinfo':'vCB_BulletinGather.php', 'hs300b':'000300cons.xls',
@@ -119,6 +119,8 @@
INDEX_COLS = ['code', 'name', 'change', 'open', 'preclose', 'close', 'high', 'low', 'volume', 'amount']
HIST_FQ_COLS = ['date', 'open', 'high', 'close', 'low', 'volume', 'amount', 'factor']
SINA_DD_COLS = ['code', 'name', 'time', 'price', 'volume', 'preprice', 'type']
+GLOBAL_HQ_SYMBOL = 'sh000001,hkHSI,znb_UKX,znb_DAX,znb_INDEXCF,znb_CAC,znb_SMI,znb_FTSEMIB,znb_MADX,znb_OMX,znb_SPX,znb_HEX,znb_OSEAX,znb_ISEQ,znb_AEX,znb_ICEXI,znb_NKY,znb_TWSE,znb_FSSTI,znb_KOSPI,znb_FBMKLCI,znb_SET,znb_JCI,znb_PCOMP,znb_KSE100,znb_SENSEX,znb_VNINDEX,znb_CSEALL,znb_SASEIDX,znb_SPTSX,znb_MEXBOL,znb_IBOV,znb_MERVAL,znb_AS51,znb_NZSE50FG,znb_CASE,znb_JALSH,sz399001,znb_INDU,znb_CCMP'
+GLOBAL_HQ_COLS = ['symbol', 'name', 'price', 'chga', 'chgp', 'datetime']
HIST_FQ_FACTOR_COLS = ['code','value']
DATA_GETTING_TIPS = '[Getting data:]'
DATA_GETTING_FLAG = '#'
@@ -274,3 +276,17 @@ def _check_lhb_input(last):
raise TypeError(LHB_MSG)
else:
return True
+
+
+def _code_to_symbol(code):
+ """
+ 生成symbol代码标志
+ """
+ if code in INDEX_LABELS:
+ return INDEX_LIST[code]
+ else:
+ if len(code) != 6 :
+ return ''
+ else:
+ return 'sh%s'%code if code[:1] in ['5', '6', '9'] else 'sz%s'%code
+
@@ -18,6 +18,9 @@
MAR_SH_HZ_TAIL_URL = '&pageHelp.pageNo=%s&pageHelp.beginPage=%s&pageHelp.endPage=%s'
TERMINATED_URL = '%s%s/%s?jsonCallBack=jsonpCallback%s&isPagination=true&sqlId=COMMON_SSE_ZQPZ_GPLB_MCJS_ZZSSGGJBXX_L&pageHelp.pageSize=50&_=%s'
SUSPENDED_URL = '%s%s/%s?jsonCallBack=jsonpCallback%s&isPagination=true&sqlId=COMMON_SSE_ZQPZ_GPLB_MCJS_ZTSSGS_L&pageHelp.pageSize=50&_=%s'
+TOP10_HOLDERS_URL = '%swebf10.%s/SDGD/SD%sGD%s.js'
+TOP10_SUMM_COLS = ['quarter', 'amount', 'changed' ,'props']
+TOP10_PER_COLS = ['quarter', 'name', 'hold', 'h_pro', 'sharetype', 'status']
TERMINATED_T_COLS = ['COMPANY_CODE', 'COMPANY_ABBR', 'LISTING_DATE', 'CHANGE_DATE']
LHB_KINDS = ['ggtj', 'yytj', 'jgzz', 'jgmx']
LHB_GGTJ_COLS = ['code', 'name', 'count', 'bamount', 'samount', 'net', 'bcount', 'scount']
@@ -9,7 +9,6 @@
from __future__ import division
from tushare.stock import cons as ct
from tushare.stock import ref_vars as rv
-from tushare.util import dateu as dt
import pandas as pd
import time
import lxml.html
@@ -19,6 +18,8 @@
from pandas.compat import StringIO
from tushare.util import dateu as du
from tushare.util.netbase import Client
+from bokeh.charts.builders.line_builder import Line
+from _csv import Error
try:
from urllib.request import urlopen, Request
@@ -232,8 +233,8 @@ def xsg_data(year=None, month=None,
count:解禁数量(万股)
ratio:占总盘比率
"""
- year = dt.get_year() if year is None else year
- month = dt.get_month() if month is None else month
+ year = du.get_year() if year is None else year
+ month = du.get_month() if month is None else month
for _ in range(retry_count):
time.sleep(pause)
try:
@@ -690,9 +691,59 @@ def sz_margin_details(date='', retry_count=3, pause=0.001):
raise IOError(ct.NETWORK_URL_ERROR_MSG)
+def top10_holders(code=None, year=None, quarter=None, gdtype='0',
+ retry_count=3, pause=0.001):
+ if code is None:
+ return None
+ else:
+ code = ct._code_to_symbol(code)
+ gdtype = 'LT' if gdtype == '1' else ''
+ qdate = ''
+ if (year is not None) & (quarter is not None):
+ qdate = du.get_q_date(year, quarter)
+ for _ in range(retry_count):
+ time.sleep(pause)
+ try:
+ request = Request(rv.TOP10_HOLDERS_URL%(ct.P_TYPE['http'], ct.DOMAINS['gw'],
+ gdtype, code.upper()))
+ lines = urlopen(request, timeout = 10).read()
+ lines = lines.decode('utf8') if ct.PY3 else lines
+ reg = re.compile(r'= \'\[(.*?)\]\';')
+ lines = reg.findall(lines)[0]
+ jss = json.loads('[%s]' %lines)
+ summ = []
+ data = pd.DataFrame()
+ for row in jss:
+ qt = row['jzrq']
+ hold = row['ljcy']
+ change = row['ljbh']
+ props = row['ljzb']
+ arow = [qt, hold, change ,props]
+ summ.append(arow)
+ ls = row['sdgdList']
+ dlist = []
+ for inrow in ls:
+ sharetype = inrow['gbxz']
+ name = inrow['gdmc']
+ hold = inrow['cgs']
+ h_pro = inrow['zzgs']
+ status = inrow['zjqk']
+ dlist.append([qt, name, hold, h_pro, sharetype, status])
+ ddata = pd.DataFrame(dlist, columns=rv.TOP10_PER_COLS)
+ data = data.append(ddata, ignore_index=True)
+ df = pd.DataFrame(summ, columns=rv.TOP10_SUMM_COLS)
+ if qdate != '':
+ df = df[df.quarter == qdate]
+ data = data[data.quarter == qdate]
+ except Exception as e:
+ print(e)
+ else:
+ return df, data
+ raise IOError(ct.NETWORK_URL_ERROR_MSG)
+
+
def _random(n=13):
from random import randint
start = 10**(n-1)
end = (10**n)-1
return str(randint(start, end))
-
View
@@ -56,6 +56,12 @@ def get_now():
return time.strftime('%Y-%m-%d %H:%M:%S')
+def int2time(timestamp):
+ datearr = datetime.datetime.utcfromtimestamp(timestamp)
+ timestr = datearr.strftime("%Y-%m-%d %H:%M:%S")
+ return timestr
+
+
def diff_day(start=None, end=None):
d1 = datetime.datetime.strptime(end, '%Y-%m-%d')
d2 = datetime.datetime.strptime(start, '%Y-%m-%d')
@@ -109,4 +115,12 @@ def tt_dates(start='', end=''):
return dates
-
+def _random(n=13):
+ from random import randint
+ start = 10**(n-1)
+ end = (10**n)-1
+ return str(randint(start, end))
+
+def get_q_date(year=None, quarter=None):
+ dt = {'1': '-03-31', '2': '-06-30', '3': '-09-30', '4': '-12-31'}
+ return '%s%s'%(str(year), dt[str(quarter)])

0 comments on commit fa5e837

Please sign in to comment.