Module: Tushare::Stock::Classifying
- Extended by:
- Classifying, Util
- Included in:
- Classifying
- Defined in:
- lib/tushare/stock/classifying.rb
Overview
获取股票分类数据接口
Instance Method Summary collapse
-
#area_classified ⇒ Object
获取地域分类数据 Return ——– DataFrame code :股票代码 name :股票名称 area :地域名称.
-
#concept_classified ⇒ Object
获取概念分类数据 Return ——– DataFrame code :股票代码 name :股票名称 c_name :概念名称.
-
#gem_classified ⇒ Object
获取创业板股票 Return ——– DataFrame code :股票代码 name :股票名称.
-
#hs300s ⇒ Object
获取沪深300当前成份股及所占权重 Return ——– DataFrame code :股票代码 name :股票名称 date :日期 weight:权重.
-
#industry_classified(standard = 'sina') ⇒ Object
Returns ——- DataFrame code :股票代码 name :股票名称 c_name :行业名称.
-
#sme_classified ⇒ Object
获取中小板股票 Return ——– DataFrame code :股票代码 name :股票名称.
-
#st_classified ⇒ Object
获取风险警示板股票 Return ——– DataFrame code :股票代码 name :股票名称.
-
#suspended ⇒ Object
获取暂停上市股票列表 Return ——– DataFrame code :股票代码 name :股票名称 oDate:上市日期 tDate:终止上市日期.
-
#sz50s ⇒ Object
获取上证50成份股 Return ——– DataFrame code :股票代码 name :股票名称.
-
#terminated ⇒ Object
获取终止上市股票列表 Return ——– DataFrame code :股票代码 name :股票名称 oDate:上市日期 tDate:终止上市日期.
-
#zz500s ⇒ Object
获取中证500成份股 Return ——– DataFrame code :股票代码 name :股票名称.
Methods included from Util
_code_to_symbol, _write_console, _write_head, check_quarter, check_year, fetch_ftp_file, holiday?, trade_cal
Instance Method Details
#area_classified ⇒ Object
获取地域分类数据 Return
DataFrame
code :股票代码
name :股票名称
area :地域名称
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tushare/stock/classifying.rb', line 60 def area_classified basics = Tushare::Stock::Fundamental.get_stock_basics result = [] basics.each do |basic| result << { 'code' => basic['code'], 'name' => basic['name'], 'area' => basic['area'] } end result.sort_by { |object| object['area'] || '' } end |
#concept_classified ⇒ Object
获取概念分类数据 Return
DataFrame
code :股票代码
name :股票名称
c_name :概念名称
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tushare/stock/classifying.rb', line 41 def concept_classified _write_head url = format(SINA_CONCEPTS_INDEX_URL, P_TYPE['http'], DOMAINS['sf'], PAGES['cpt']) type_data = fetch_type_data(url) result = [] type_data.keys.each do |type| result.concat fetch_detail(type, type_data[type]) end result end |
#gem_classified ⇒ Object
获取创业板股票 Return
DataFrame
code :股票代码
name :股票名称
77 78 79 80 81 82 83 84 85 |
# File 'lib/tushare/stock/classifying.rb', line 77 def gem_classified basics = Tushare::Stock::Fundamental.get_stock_basics basics.select! { |basic| basic['code'][0] == '3' } result = [] basics.each do |basic| result << { 'code' => basic['code'], 'name' => basic['name'] } end result.sort_by { |object| object['code'] || '' } end |
#hs300s ⇒ Object
获取沪深300当前成份股及所占权重 Return
DataFrame
code :股票代码
name :股票名称
date :日期
weight:权重
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/tushare/stock/classifying.rb', line 127 def hs300s url = format(HS300_CLASSIFY_URL_FTP, P_TYPE['ftp'], DOMAINS['idxip'], PAGES['hs300w']) fetch_ftp_file url do |file| xls = ::Roo::Spreadsheet.open(file, extension: 'xls') result = [] xls.sheet(0).drop(1).each do |row| result << { 'date' => row[0], 'code' => row[3], 'weight' => row[6] } end basics = Tushare::Stock::Fundamental.get_stock_basics result.each do |object| find_result = basics.find { |basic| basic['code'] == object['code'] } object[name] = find_result['name'] end result end end |
#industry_classified(standard = 'sina') ⇒ Object
Returns
DataFrame
code :股票代码
name :股票名称
c_name :行业名称
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tushare/stock/classifying.rb', line 22 def industry_classified(standard = 'sina') _write_head url = format(SINA_INDUSTRY_INDEX_URL, P_TYPE['http'], DOMAINS['vsf'], standard == 'sw' ? PAGES['ids_sw'] : PAGES['ids']) type_data = fetch_type_data(url) result = [] type_data.keys.each do |type| result.concat fetch_detail(type, type_data[type]) end result end |
#sme_classified ⇒ Object
获取中小板股票 Return
DataFrame
code :股票代码
name :股票名称
93 94 95 96 97 98 99 100 101 |
# File 'lib/tushare/stock/classifying.rb', line 93 def sme_classified basics = Tushare::Stock::Fundamental.get_stock_basics basics.select! { |basic| basic['code'][0..2] == '002' } result = [] basics.each do |basic| result << { 'code' => basic['code'], 'name' => basic['name'] } end result.sort_by { |object| object['code'] || '' } end |
#st_classified ⇒ Object
获取风险警示板股票 Return
DataFrame
code :股票代码
name :股票名称
109 110 111 112 113 114 115 116 117 |
# File 'lib/tushare/stock/classifying.rb', line 109 def st_classified basics = Tushare::Stock::Fundamental.get_stock_basics basics.select! { |basic| basic['name'].include? 'ST' } result = [] basics.each do |basic| result << { 'code' => basic['code'], 'name' => basic['name'] } end result.sort_by { |object| object['code'] || '' } end |
#suspended ⇒ Object
获取暂停上市股票列表 Return
DataFrame
code :股票代码
name :股票名称
oDate:上市日期
tDate:终止上市日期
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/tushare/stock/classifying.rb', line 229 def suspended ref = format(SSEQ_CQ_REF_URL, P_TYPE['http'], DOMAINS['sse']) url = format(SUSPENDED_URL, P_TYPE['http'], DOMAINS['sseq'], PAGES['ssecq'], _random(5), _random) resp = HTTParty.get( url, headers: { 'Referer' => ref }, cookies: MAR_SH_COOKIES ) json = JSON.parse(resp.body.sub(/jsonpCallback\d+\(/, '')[0..-2])['pageHelp'] result = [] json['data'].each do |datum| object = {} TERMINATED_T_COLS.each_with_index do |key, index| object[TERMINATED_COLS[index]] = datum[key] end result << object end result end |
#sz50s ⇒ Object
获取上证50成份股 Return
DataFrame
code :股票代码
name :股票名称
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/tushare/stock/classifying.rb', line 153 def sz50s url = format(HS300_CLASSIFY_URL_FTP, P_TYPE['ftp'], DOMAINS['idxip'], PAGES['sz50b']) fetch_ftp_file url do |file| xls = ::Roo::Spreadsheet.open(file, extension: 'xls') result = [] xls.sheet(0).drop(1).each do |row| result << { 'code' => row[0], 'name' => row[1] } end result end end |
#terminated ⇒ Object
获取终止上市股票列表 Return
DataFrame
code :股票代码
name :股票名称
oDate:上市日期
tDate:终止上市日期
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/tushare/stock/classifying.rb', line 200 def terminated ref = format(SSEQ_CQ_REF_URL, P_TYPE['http'], DOMAINS['sse']) url = format(TERMINATED_URL, P_TYPE['http'], DOMAINS['sseq'], PAGES['ssecq'], _random(5), _random) resp = HTTParty.get( url, headers: { 'Referer' => ref }, cookies: MAR_SH_COOKIES ) json = JSON.parse(resp.body.sub(/jsonpCallback\d+\(/, '')[0..-2])['pageHelp'] result = [] json['data'].each do |datum| object = {} TERMINATED_T_COLS.each_with_index do |key, index| object[TERMINATED_COLS[index]] = datum[key] end result << object end result end |
#zz500s ⇒ Object
获取中证500成份股 Return
DataFrame
code :股票代码
name :股票名称
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/tushare/stock/classifying.rb', line 173 def zz500s url = format(HS300_CLASSIFY_URL_FTP, P_TYPE['ftp'], DOMAINS['idxip'], PAGES['zz500wt']) fetch_ftp_file url do |file| xls = ::Roo::Spreadsheet.open(file, extension: 'xls') result = [] xls.sheet(0).drop(1).each do |row| result << { 'date' => row[0], 'code' => row[3], 'weight' => row[6] } end basics = Tushare::Stock::Fundamental.get_stock_basics result.each do |object| find_result = basics.find { |basic| basic['code'] == object['code'] } object[name] = find_result['name'] end end end |