本文整理汇总了Python中tushare.util.netbase.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _sh_mx
def _sh_mx(data, date="", start="", end="", symbol="", pageNo="", beginPage="", endPage="", retry_count=3, pause=0.001):
for _ in range(retry_count):
time.sleep(pause)
ct._write_console()
try:
tail = "&pageHelp.pageNo=%s&pageHelp.beginPage=%s&pageHelp.endPage=%s" % (pageNo, beginPage, endPage)
if pageNo == "":
pageNo = 6
tail = ""
else:
pageNo += 5
beginPage = pageNo
endPage = pageNo + 4
ref = rv.MAR_SH_HZ_REF_URL % (ct.P_TYPE["http"], ct.DOMAINS["sse"])
clt = Client(
rv.MAR_SH_MX_URL
% (
ct.P_TYPE["http"],
ct.DOMAINS["sseq"],
ct.PAGES["qmd"],
_random(5),
date,
symbol,
start,
end,
tail,
_random(),
),
ref=ref,
cookie=rv.MAR_SH_COOKIESTR,
)
lines = clt.gvalue()
lines = lines.decode("utf-8") if ct.PY3 else lines
lines = lines[19:-1]
lines = json.loads(lines)
pagecount = int(lines["pageHelp"].get("pageCount"))
datapage = int(pagecount / 5 + 1 if pagecount % 5 > 0 else pagecount / 5)
if pagecount == 0:
return data
if pageNo == 6:
ct._write_tips(lines["pageHelp"].get("total"))
df = pd.DataFrame(lines["result"], columns=rv.MAR_SH_MX_COLS)
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_mx(
data,
start=start,
end=end,
pageNo=pageNo,
beginPage=beginPage,
endPage=endPage,
retry_count=retry_count,
pause=pause,
)
except _network_error_classes:
pass
else:
return data
raise IOError(ct.NETWORK_URL_ERROR_MSG)
开发者ID:xyicheng,项目名称:tushare,代码行数:60,代码来源:reference.py
示例2: get_suspended
def get_suspended():
"""
获取暂停上市股票列表
Return
--------
DataFrame
code :股票代码
name :股票名称
oDate:上市日期
tDate:终止上市日期
"""
try:
ref = ct.SSEQ_CQ_REF_URL%(ct.P_TYPE['http'], ct.DOMAINS['sse'])
clt = Client(rv.SUSPENDED_URL%(ct.P_TYPE['http'], ct.DOMAINS['sseq'],
ct.PAGES['ssecq'], _random(5),
_random()), ref=ref, cookie=rv.MAR_SH_COOKIESTR)
lines = clt.gvalue()
lines = lines.decode('utf-8') if ct.PY3 else lines
lines = lines[19:-1]
lines = json.loads(lines)
df = pd.DataFrame(lines['result'], columns=rv.TERMINATED_T_COLS)
df.columns = rv.TERMINATED_COLS
return df
except Exception as er:
print(str(er))
开发者ID:Esmidth,项目名称:AnacondaBackup,代码行数:26,代码来源:classifying.py
示例3: lpr_ma_data
def lpr_ma_data(year=None):
"""
获取贷款基础利率均值数据
Parameters
------
year:年份(int)
Return
------
date:日期
1Y_5:5日均值
1Y_10:10日均值
1Y_20:20日均值
"""
year = du.get_year() if year is None else year
lab = ct.SHIBOR_TYPE['LPR_Tendency']
lab = lab.encode('utf-8') if ct.PY3 else lab
try:
clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'],
ct.PAGES['dw'], 'LPR_Tendency',
year, lab,
year))
content = clt.gvalue()
df = pd.read_excel(StringIO(content), skiprows=[0])
df.columns = ct.LPR_MA_COLS
df['date'] = df['date'].map(lambda x: x.date())
if pd.__version__ < '0.21':
df['date'] = df['date'].astype(np.datetime64)
else:
df['date'] = df['date'].astype('datetime64[D]')
return df
except:
return None
开发者ID:peterz3g,项目名称:tushare,代码行数:33,代码来源:shibor.py
示例4: get_terminated
def get_terminated():
"""
获取终止上市股票列表
Return
--------
DataFrame
code :股票代码
name :股票名称
oDate:上市日期
tDate:终止上市日期
"""
try:
ref = ct.SSEQ_CQ_REF_URL % (ct.P_TYPE["http"], ct.DOMAINS["sse"])
clt = Client(
rv.TERMINATED_URL % (ct.P_TYPE["http"], ct.DOMAINS["sseq"], ct.PAGES["ssecq"], _random(5), _random()),
ref=ref,
cookie=rv.MAR_SH_COOKIESTR,
)
lines = clt.gvalue()
lines = lines.decode("utf-8") if ct.PY3 else lines
lines = lines[19:-1]
lines = json.loads(lines)
df = pd.DataFrame(lines["result"], columns=rv.TERMINATED_T_COLS)
df.columns = rv.TERMINATED_COLS
return df
except Exception as er:
print(str(er))
开发者ID:xyicheng,项目名称:tushare,代码行数:28,代码来源:classifying.py
示例5: moneyflow_hsgt
def moneyflow_hsgt():
"""
获取沪深港通资金流向
return:
DataFrame,单位: 百万元
--------------
date: 交易日期
ggt_ss: 港股通(沪)
ggt_sz: 港股通(深)
hgt: 沪港通
sgt: 深港通
north_money: 北向资金流入
south_money: 南向资金流入
"""
clt = Client(rv.HSGT_DATA%(ct.P_TYPE['http'], ct.DOMAINS['em']),
ref=rv.HSGT_REF%(ct.P_TYPE['http'], ct.DOMAINS['em'], ct.PAGES['index']))
content = clt.gvalue()
content = content.decode('utf-8') if ct.PY3 else content
js = json.loads(content)
df = pd.DataFrame(js)
df['DateTime'] = df['DateTime'].map(lambda x: x[0:10])
df = df.replace('-', np.NaN)
df = df[rv.HSGT_TEMP]
df.columns = rv.HSGT_COLS
df = df.sort_values('date', ascending=False)
return df
开发者ID:peterz3g,项目名称:tushare,代码行数:26,代码来源:reference.py
示例6: shibor_quote_data
def shibor_quote_data(year=None):
"""
获取Shibor银行报价数据
Parameters
------
year:年份(int)
Return
------
date:日期
bank:报价银行名称
ON:隔夜拆放利率
ON_B:隔夜拆放买入价
ON_A:隔夜拆放卖出价
1W_B:1周买入
1W_A:1周卖出
2W_B:买入
2W_A:卖出
1M_B:买入
1M_A:卖出
3M_B:买入
3M_A:卖出
6M_B:买入
6M_A:卖出
9M_B:买入
9M_A:卖出
1Y_B:买入
1Y_A:卖出
"""
year = du.get_year() if year is None else year
lab = ct.SHIBOR_TYPE['Quote']
lab = lab.encode('utf-8') if ct.PY3 else lab
try:
clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'],
ct.PAGES['dw'], 'Quote',
year, lab,
year))
content = clt.gvalue()
df = pd.read_excel(StringIO(content), skiprows=[0])
# df.columns = ct.QUOTE_COLS
df.columns = ct.SHIBOR_Q_COLS
df['date'] = df['date'].map(lambda x: x.date())
if pd.__version__ < '0.21':
df['date'] = df['date'].astype(np.datetime64)
else:
df['date'] = df['date'].astype('datetime64[D]')
return df
except:
return None
开发者ID:peterz3g,项目名称:tushare,代码行数:49,代码来源:shibor.py
示例7: _sh_mx
def _sh_mx(data, date='', start='', end='',
symbol='',
pageNo='', beginPage='',
endPage='',
retry_count=3, pause=0.001):
for _ in range(retry_count):
time.sleep(pause)
ct._write_console()
try:
tail = '&pageHelp.pageNo=%s&pageHelp.beginPage=%s&pageHelp.endPage=%s'%(pageNo,
beginPage, endPage)
if pageNo == '':
pageNo = 6
tail = ''
else:
pageNo += 5
beginPage = pageNo
endPage = pageNo + 4
url = rv.MAR_SH_MX_URL%(ct.P_TYPE['http'], ct.DOMAINS['sseq'],
ct.PAGES['qmd'], _random(5), date,
symbol, start, end, tail,
_random())
ref = rv.MAR_SH_HZ_REF_URL%(ct.P_TYPE['http'], ct.DOMAINS['sse'])
clt = Client(url, ref=ref, cookie=rv.MAR_SH_COOKIESTR)
lines = clt.gvalue()
lines = lines.decode('utf-8') if ct.PY3 else lines
lines = lines[19:-1]
lines = json.loads(lines)
pagecount = int(lines['pageHelp'].get('pageCount'))
datapage = int(pagecount/5+1 if pagecount%5>0 else pagecount/5)
if pagecount == 0:
return data
if pageNo == 6:
ct._write_tips(lines['pageHelp'].get('total'))
df = pd.DataFrame(lines['result'], columns=rv.MAR_SH_MX_COLS)
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,
beginPage=beginPage, endPage=endPage,
retry_count=retry_count, pause=pause)
except _network_error_classes:
pass
else:
return data
raise IOError(ct.NETWORK_URL_ERROR_MSG)
开发者ID:jimupon,项目名称:tushare,代码行数:47,代码来源:reference.py
示例8: _sh_hz
def _sh_hz(data, start=None, end=None,
pageNo='', beginPage='',
endPage='',
retry_count=3, pause=0.001):
for _ in range(retry_count):
time.sleep(pause)
ct._write_console()
try:
tail = rv.MAR_SH_HZ_TAIL_URL%(pageNo,
beginPage, endPage)
if not pageNo:
pageNo = 6
tail = ''
else:
pageNo += 5
beginPage = pageNo
endPage = pageNo + 4
url = rv.MAR_SH_HZ_URL%(ct.P_TYPE['http'], ct.DOMAINS['sseq'],
ct.PAGES['qmd'], _random(5),
start, end, tail,
_random())
ref = rv.MAR_SH_HZ_REF_URL%(ct.P_TYPE['http'], ct.DOMAINS['sse'])
clt = Client(url, ref=ref, cookie=rv.MAR_SH_COOKIESTR)
lines = clt.gvalue()
lines = lines.decode('utf-8')
lines = lines[19:-1]
lines = json.loads(lines)
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['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,
beginPage=beginPage, endPage=endPage,
retry_count=retry_count, pause=pause)
except Exception as e:
print(e)
else:
return data
raise IOError(ct.NETWORK_URL_ERROR_MSG)
开发者ID:wlbksy,项目名称:sayswho,代码行数:41,代码来源:reference.py
示例9: shibor_data
def shibor_data(year=None):
"""
获取上海银行间同业拆放利率(Shibor)
Parameters
------
year:年份(int)
Return
------
date:日期
ON:隔夜拆放利率
1W:1周拆放利率
2W:2周拆放利率
1M:1个月拆放利率
3M:3个月拆放利率
6M:6个月拆放利率
9M:9个月拆放利率
1Y:1年拆放利率
"""
year = du.get_year() if year is None else year
lab = ct.SHIBOR_TYPE['Shibor']
lab = lab.encode('utf-8') if ct.PY3 else lab
try:
clt = Client(url=ct.SHIBOR_DATA_URL%(ct.P_TYPE['http'], ct.DOMAINS['shibor'],
ct.PAGES['dw'], 'Shibor',
year, lab,
year))
content = clt.gvalue()
df = pd.read_excel(StringIO(content))
df.columns = ct.SHIBOR_COLS
df['date'] = df['date'].map(lambda x: x.date())
if pd.__version__ < '0.21':
df['date'] = df['date'].astype(np.datetime64)
else:
df['date'] = df['date'].astype('datetime64[D]')
return df
except:
return None
开发者ID:peterz3g,项目名称:tushare,代码行数:38,代码来源:shibor.py
注:本文中的tushare.util.netbase.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论