-
Notifications
You must be signed in to change notification settings - Fork 331
01. 股票数据
PKUJohnson edited this page Dec 20, 2018
·
1 revision
OpenDataTools通过stock接口,支持对上交所、深交所股票数据的获取,要求版本0.2.2以上。
数据来源:雪球、新浪、上交所、深交所、中证指数公司
- 证券代码规范:600000.SH表示浦发银行,000002.SZ表示万科A。
- 时间规范2018-01-01,YYYY-MM-DD
from opendatatools import stock
- 获取实时行情
# 获取实时行情
df, msg = stock.get_quote('600000.SH,000002.SZ')
- 获取实时K线(只能获取最近两个交易日)
# 1m, 5m, 15m, 30m, 60m
df, msg = stock.get_kline('000002.SZ', '2018-06-15', '1m')
- 获取日线数据
df, msg = stock.get_daily('600000.SH', start_date='2017-06-06', end_date='2018-06-07')
- 获取复权因子
df, msg = stock.get_adj_factor('600000.SH')
- 获取成交明细数据
df, msg = stock.get_trade_detail('600000.SH', trade_date='2018-06-07')
- 获取交易所指数列表
# market=SH/SZ/CSI
index_list = stock.get_index_list('SH')
- 获取指数成份股
stock_list = stock.get_index_component('000050.SH')
- 获得融资融券市场信息
df_total, df_detail = stock.get_rzrq_info(market = 'SZ', date = '20180614')
- 获取分红信息
df = stock.get_dividend('600000.SH')
- 获取股权质押数据
df_total, df_detail = stock.get_pledge_info(market = 'SZ', date = '20180614')
- 获取财务报表
df, msg = stock.get_report_data(symbol='600030.SH', type='利润表')
df[df['报告年度'] == '2017-12-31'].T
- 获取股本信息
df, msg = stock.get_shareholder_structure('600030.SH')
- 一个应用案例(如何识别股权质押风险:找出质押比率较大的股票)
import pandas as pd
from progressbar import ProgressBar
def analyze_pledge_info(market='SZ', date='2018-06-21'):
df_total, df_detail = stock.get_pledge_info(market, date='2018-06-21')
data = []
progress_bar = ProgressBar().start(max_value=len(df_detail))
for index, row in df_detail.iterrows():
progress_bar.update(index+1)
symbol = str(row['证券代码']) + '.' + market
if market == 'SZ':
pledge_share = float(row['待购回无限售条件证券余量'].replace(',', '')) + float(row['待购回有限售条件证券余量'].replace(',',''))
else:
pledge_share = float(row['待购回余量(股/份/张)'].replace(',', ''))
df, msg = stock.get_shareholder_structure(symbol)
if df is None:
#print('error occurs on ', symbol)
continue
total_share = float(df[df.indicator == '总股本'].iloc[0, 1].replace(',', ''))
tradable_share = float(df[df.indicator == '流通股'].iloc[0, 1].replace(',', ''))
data.append({'symbol': symbol, 'total_share' : total_share, 'tradable_share' : tradable_share, 'pledge_share' : pledge_share, 'pledge_ratio' : pledge_share / total_share })
df = pd.DataFrame(data)
return df
df_sh = get_pledge_info('SH', '2018-06-21')
df_sz = get_pledge_info('SZ', '2018-06-21')
df = pd.concat([df_sh, df_sz])
df.sort_values('pledge_ratio', ascending=False, inplace=True)
df.head(20)
- 每笔100万资金以上的属于超大
- 每笔50-100万的属于大单
- 每笔10-50 万的属于中单
- 每笔10万以下的属于小单
- 获取实时资金流向
# ZLJLRJE:主力净流入金额,CDDJLRJE:超大单净流入金额
# DDJLRJE:大单净流入金额,ZDJLRJE:中单净流入金额,XDJLRJE:小单净流入金额
# 单位:万元
df, msg = stock.get_realtime_money_flow('600030.SH')
df.head(20)
- 获取历史资金流向
# ZLJLRJE:主力净流入金额,CDDJLRJE:超大单净流入金额
# DDJLRJE:大单净流入金额,ZDJLRJE:中单净流入金额,XDJLRJE:小单净流入金额
# 单位:百万元
df, msg = stock.get_hist_money_flow('600000.SH')
df.tail(20)
- 每笔100万资金以上的属于超大
- 每笔50-100万的属于大单
- 每笔10-50 万的属于中单
- 每笔10万以下的属于小单
- 获取全市场历史资金流向数据
df, msg = stock.get_hist_money_flow_market()
df.tail(20)
- 获取全市场实时资金流向数据
df, msg = stock.get_realtime_money_flow_market()
df.tail(20)