tushare 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +28 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/tushare.rb +18 -0
- data/lib/tushare/datayes.rb +50 -0
- data/lib/tushare/datayes/bond.rb +69 -0
- data/lib/tushare/datayes/constants.rb +598 -0
- data/lib/tushare/datayes/equity.rb +111 -0
- data/lib/tushare/datayes/fund.rb +115 -0
- data/lib/tushare/datayes/fundamental.rb +260 -0
- data/lib/tushare/datayes/future.rb +22 -0
- data/lib/tushare/datayes/hk_equity.rb +18 -0
- data/lib/tushare/datayes/idx.rb +19 -0
- data/lib/tushare/datayes/iv.rb +60 -0
- data/lib/tushare/datayes/macro.rb +3517 -0
- data/lib/tushare/datayes/market.rb +286 -0
- data/lib/tushare/datayes/master.rb +67 -0
- data/lib/tushare/datayes/options.rb +22 -0
- data/lib/tushare/datayes/subject.rb +349 -0
- data/lib/tushare/internet/box_office.rb +155 -0
- data/lib/tushare/stock/billboard.rb +197 -0
- data/lib/tushare/stock/classifying.rb +288 -0
- data/lib/tushare/stock/fundamental.rb +232 -0
- data/lib/tushare/stock/macro.rb +253 -0
- data/lib/tushare/stock/news_event.rb +165 -0
- data/lib/tushare/stock/reference.rb +473 -0
- data/lib/tushare/stock/shibor.rb +136 -0
- data/lib/tushare/stock/trading.rb +513 -0
- data/lib/tushare/util.rb +293 -0
- data/lib/tushare/version.rb +3 -0
- data/tushare.gemspec +32 -0
- metadata +211 -0
data/lib/tushare/util.rb
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
|
3
|
+
module Tushare
|
4
|
+
K_LABELS = ['D', 'W', 'M']
|
5
|
+
K_MIN_LABELS = ['5', '15', '30', '60']
|
6
|
+
K_TYPE = {'D'=> 'akdaily', 'W'=> 'akweekly', 'M'=> 'akmonthly'}
|
7
|
+
INDEX_LABELS = %w(sh sz hs300 sz50 cyb zxb zx300 zh500).freeze
|
8
|
+
INDEX_LIST = {
|
9
|
+
'sh' => 'sh000001',
|
10
|
+
'sz' => 'sz399001',
|
11
|
+
'hs300' => 'sz399300',
|
12
|
+
'sz50' => 'sh000016',
|
13
|
+
'zxb' => 'sz399005',
|
14
|
+
'cyb' => 'sz399006',
|
15
|
+
'zx300' => 'sz399008',
|
16
|
+
'zh500' => 'sh000905'
|
17
|
+
}.freeze
|
18
|
+
P_TYPE = {
|
19
|
+
'http' => 'http://',
|
20
|
+
'ftp' => 'ftp://'
|
21
|
+
}.freeze
|
22
|
+
PAGE_NUM = [38, 60, 80, 100].freeze
|
23
|
+
#FORMAT = lambda x: '%.2f' % x
|
24
|
+
DOMAINS = {
|
25
|
+
'sina' => 'sina.com.cn',
|
26
|
+
'sinahq' => 'sinajs.cn',
|
27
|
+
'ifeng' => 'ifeng.com',
|
28
|
+
'sf' => 'finance.sina.com.cn',
|
29
|
+
'vsf' => 'vip.stock.finance.sina.com.cn',
|
30
|
+
'idx' => 'www.csindex.com.cn',
|
31
|
+
'163' => 'money.163.com',
|
32
|
+
'em' => 'eastmoney.com',
|
33
|
+
'sseq' => 'query.sse.com.cn',
|
34
|
+
'sse' => 'www.sse.com.cn',
|
35
|
+
'szse' => 'www.szse.cn',
|
36
|
+
'oss' => '218.244.146.57',
|
37
|
+
'idxip' => '115.29.204.48',
|
38
|
+
'shibor' => 'www.shibor.org',
|
39
|
+
'mbox' => 'www.cbooo.cn'
|
40
|
+
}.freeze
|
41
|
+
PAGES = {
|
42
|
+
'fd' => 'index.phtml',
|
43
|
+
'dl' => 'downxls.php',
|
44
|
+
'jv' => 'json_v2.php',
|
45
|
+
'cpt' => 'newFLJK.php',
|
46
|
+
'ids' => 'newSinaHy.php',
|
47
|
+
'lnews' => 'rollnews_ch_out_interface.php',
|
48
|
+
'ntinfo' => 'vCB_BulletinGather.php',
|
49
|
+
'hs300b' => '000300cons.xls',
|
50
|
+
'hs300w' => '000300closeweight.xls',
|
51
|
+
'sz50b' => '000016cons.xls',
|
52
|
+
'dp' => 'all_fpya.php',
|
53
|
+
'163dp' => 'fpyg.html',
|
54
|
+
'emxsg' => 'JS.aspx',
|
55
|
+
'163fh' => 'jjcgph.php',
|
56
|
+
'newstock' => 'vRPD_NewStockIssue.php',
|
57
|
+
'zz500b' => '000905cons.xls',
|
58
|
+
'zz500wt' => '000905closeweight.xls',
|
59
|
+
't_ticks' => 'vMS_tradedetail.php',
|
60
|
+
'dw' => 'downLoad.html',
|
61
|
+
'qmd' => 'queryMargin.do',
|
62
|
+
'szsefc' => 'ShowReport.szse',
|
63
|
+
'ssecq' => 'commonQuery.do',
|
64
|
+
'sinadd' => 'cn_bill_download.php',
|
65
|
+
'ids_sw' => 'SwHy.php'
|
66
|
+
}.freeze
|
67
|
+
TICK_COLUMNS = ['time', 'price', 'change', 'volume', 'amount', 'type']
|
68
|
+
TODAY_TICK_COLUMNS = ['time', 'price', 'pchange', 'change', 'volume', 'amount', 'type']
|
69
|
+
DAY_TRADING_COLUMNS = ['code', 'symbol', 'name', 'changepercent',
|
70
|
+
'trade', 'open', 'high', 'low', 'settlement', 'volume', 'turnoverratio']
|
71
|
+
REPORT_COLS = ['code', 'name', 'eps', 'eps_yoy', 'bvps', 'roe',
|
72
|
+
'epcf', 'net_profits', 'profits_yoy', 'distrib', 'report_date']
|
73
|
+
FORECAST_COLS = %w(code name type report_date pre_eps range).freeze
|
74
|
+
PROFIT_COLS = ['code', 'name', 'roe', 'net_profit_ratio',
|
75
|
+
'gross_profit_rate', 'net_profits', 'eps', 'business_income', 'bips']
|
76
|
+
OPERATION_COLS = ['code', 'name', 'arturnover', 'arturndays', 'inventory_turnover',
|
77
|
+
'inventory_days', 'currentasset_turnover', 'currentasset_days']
|
78
|
+
GROWTH_COLS = ['code', 'name', 'mbrg', 'nprg', 'nav', 'targ', 'epsg', 'seg']
|
79
|
+
DEBTPAYING_COLS = ['code', 'name', 'currentratio',
|
80
|
+
'quickratio', 'cashratio', 'icratio', 'sheqratio', 'adratio']
|
81
|
+
CASHFLOW_COLS = ['code', 'name', 'cf_sales', 'rateofreturn',
|
82
|
+
'cf_nm', 'cf_liabilities', 'cashflowratio']
|
83
|
+
DAY_PRICE_COLUMNS = ['date', 'open', 'high', 'close', 'low', 'volume', 'price_change', 'p_change',
|
84
|
+
'ma5', 'ma10', 'ma20', 'v_ma5', 'v_ma10', 'v_ma20', 'turnover']
|
85
|
+
INX_DAY_PRICE_COLUMNS = ['date', 'open', 'high', 'close', 'low', 'volume', 'price_change', 'p_change',
|
86
|
+
'ma5', 'ma10', 'ma20', 'v_ma5', 'v_ma10', 'v_ma20']
|
87
|
+
LIVE_DATA_COLS = %w(name open pre_close price high low bid ask volume amount
|
88
|
+
b1_v b1_p b2_v b2_p b3_v b3_p b4_v b4_p b5_v b5_p
|
89
|
+
a1_v a1_p a2_v a2_p a3_v a3_p a4_v a4_p a5_v a5_p date
|
90
|
+
time s).freeze
|
91
|
+
FOR_CLASSIFY_B_COLS = %w(code name).freeze
|
92
|
+
FOR_CLASSIFY_W_COLS = %w(date code weight).freeze
|
93
|
+
THE_FIELDS = %w(code symbol name changepercent trade open high low settlement
|
94
|
+
volume turnoverratio).freeze
|
95
|
+
TICK_PRICE_URL = '%smarket.%s/%s?date=%s&symbol=%s'
|
96
|
+
TODAY_TICKS_PAGE_URL = '%s%s/quotes_service/api/%s/CN_Transactions.getAllPageTime?date=%s&symbol=%s'
|
97
|
+
TODAY_TICKS_URL = '%s%s/quotes_service/view/%s?symbol=%s&date=%s&page=%s'
|
98
|
+
DAY_PRICE_URL = '%sapi.finance.%s/%s/?code=%s&type=last'
|
99
|
+
LIVE_DATA_URL = '%shq.%s/rn=%s&list=%s'.freeze
|
100
|
+
DAY_PRICE_MIN_URL = '%sapi.finance.%s/akmin?scode=%s&type=%s'
|
101
|
+
SINA_DAY_PRICE_URL = '%s%s/quotes_service/api/%s/Market_Center.getHQNodeData?num=80&sort=changepercent&asc=0&node=hs_a&symbol=&_s_r_a=page&page=%s'
|
102
|
+
REPORT_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/mainindex/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
103
|
+
FORECAST_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/performance/%s?s_i=&s_a=&s_c=&s_type=&reportdate=%s&quarter=%s&p=%s&num=%s'.freeze
|
104
|
+
PROFIT_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/profit/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
105
|
+
OPERATION_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/operation/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
106
|
+
GROWTH_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/grow/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
107
|
+
DEBTPAYING_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/debtpaying/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
108
|
+
CASHFLOW_URL = '%s%s/q/go.php/vFinanceAnalyze/kind/cashflow/%s?s_i=&s_a=&s_c=&reportdate=%s&quarter=%s&p=%s&num=%s'
|
109
|
+
SHIBOR_TYPE = {
|
110
|
+
'Shibor' => 'Shibor数据',
|
111
|
+
'Quote' => '报价数据',
|
112
|
+
'Tendency' => 'Shibor均值数据',
|
113
|
+
'LPR' => 'LPR数据',
|
114
|
+
'LPR_Tendency' => 'LPR均值数据'
|
115
|
+
}.freeze
|
116
|
+
SHIBOR_DATA_URL = '%s%s/shibor/web/html/%s?nameNew=Historical_%s_Data_%s.xls&downLoadPath=data&nameOld=%s%s.xls&shiborSrc=http://www.shibor.org/shibor/'.freeze
|
117
|
+
ALL_STOCK_BASICS_FILE = '%s%s/static/all.csv' % [P_TYPE['http'], DOMAINS['oss']]
|
118
|
+
SINA_CONCEPTS_INDEX_URL = '%smoney.%s/q/view/%s?param=class'.freeze
|
119
|
+
SINA_INDUSTRY_INDEX_URL = '%s%s/q/view/%s'.freeze
|
120
|
+
SINA_DATA_DETAIL_URL = '%s%s/quotes_service/api/%s/Market_Center.getHQNodeData?page=1&num=400&sort=symbol&asc=1&node=%s&symbol=&_s_r_a=page'.freeze
|
121
|
+
INDEX_C_COMM = 'sseportal/ps/zhs/hqjt/csi'
|
122
|
+
HS300_CLASSIFY_URL_FTP = '%s%s/webdata/%s'.freeze
|
123
|
+
HS300_CLASSIFY_URL_HTTP = '%s%s/%s/%s'
|
124
|
+
HIST_FQ_URL = '%s%s/corp/go.php/vMS_FuQuanMarketHistory/stockid/%s.phtml?year=%s&jidu=%s'.freeze
|
125
|
+
HIST_INDEX_URL = '%s%s/corp/go.php/vMS_MarketHistory/stockid/%s/type/S.phtml?year=%s&jidu=%s'.freeze
|
126
|
+
HIST_FQ_FACTOR_URL = '%s%s/api/json.php/BasicStockSrv.getStockFuQuanData?symbol=%s&type=hfq'.freeze
|
127
|
+
INDEX_HQ_URL = '''%shq.%s/rn=xppzh&list=sh000001,sh000002,sh000003,sh000008,sh000009,sh000010,sh000011,sh000012,sh000016,sh000017,sh000300,sz399001,sz399002,sz399003,sz399004,sz399005,sz399006,sz399100,sz399101,sz399106,sz399107,sz399108,sz399333,sz399606'''.freeze
|
128
|
+
SSEQ_CQ_REF_URL = '%s%s/assortment/stock/list/name'.freeze
|
129
|
+
ALL_STK_URL = '%s%s/all.csv'
|
130
|
+
SINA_DD = '%s%s/quotes_service/view/%s?symbol=%s&num=60&page=1&sort=ticktime&asc=0&volume=%s&amount=0&type=0&day=%s'
|
131
|
+
BOX = 'boxOffice'
|
132
|
+
MOVIE_BOX = '%s%s/%s/GetHourBoxOffice?d=%s'.freeze
|
133
|
+
BOXOFFICE_DAY = '%s%s/%s/GetDayBoxOffice?num=%s&d=%s'.freeze
|
134
|
+
BOXOFFICE_MONTH = '%s%s/%s/getMonthBox?sdate=%s'.freeze
|
135
|
+
BOXOFFICE_CBD = '%s%s/%s/getCBD?pIndex=%s&dt=%s'.freeze
|
136
|
+
SHIBOR_COLS = %w(date ON 1W 2W 1M 3M 6M 9M 1Y).freeze
|
137
|
+
QUOTE_COLS = %w(date bank ON_B ON_A 1W_B 1W_A 2W_B 2W_A 1M_B 1M_A
|
138
|
+
3M_B 3M_A 6M_B 6M_A 9M_B 9M_A 1Y_B 1Y_A).freeze
|
139
|
+
SHIBOR_MA_COLS = %w(date ON_5 ON_10 ON_20 1W_5 1W_10 1W_20 2W_5 2W_10 2W_20
|
140
|
+
1M_5 1M_10 1M_20 3M_5 3M_10 3M_20 6M_5 6M_10 6M_20
|
141
|
+
9M_5 9M_10 9M_20 1Y_5 1Y_10 1Y_20).freeze
|
142
|
+
LPR_COLS = %w(date 1Y).freeze
|
143
|
+
LPR_MA_COLS = %w(date 1Y_5 1Y_10 1Y_20).freeze
|
144
|
+
INDEX_HEADER = 'code,name,open,preclose,close,high,low,0,0,volume,amount,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,d,c,3\n'.freeze
|
145
|
+
INDEX_COLS = %w(code name change open preclose close high low volume amount).freeze
|
146
|
+
HIST_FQ_COLS = %w(date open high close low volume amount factor).freeze
|
147
|
+
SINA_DD_COLS = ['code', 'name', 'time', 'price', 'volume', 'preprice', 'type']
|
148
|
+
HIST_FQ_FACTOR_COLS = ['code','value']
|
149
|
+
DATA_GETTING_TIPS = '[Getting data:]'
|
150
|
+
DATA_GETTING_FLAG = '#'
|
151
|
+
DATA_ROWS_TIPS = '%s rows data found.Please wait for a moment.'
|
152
|
+
DATA_INPUT_ERROR_MSG = 'date input error.'
|
153
|
+
NETWORK_URL_ERROR_MSG = '获取失败,请检查网络和URL'
|
154
|
+
DATE_CHK_MSG = '年度输入错误:请输入1989年以后的年份数字,格式:YYYY'
|
155
|
+
DATE_CHK_Q_MSG = '季度输入错误:请输入1、2、3或4数字'
|
156
|
+
TOP_PARAS_MSG = 'top有误,请输入整数或all.'
|
157
|
+
LHB_MSG = '周期输入有误,请输入数字5、10、30或60'.freeze
|
158
|
+
TOKEN_F_P = 'tk.csv'
|
159
|
+
TOKEN_ERR_MSG = '请设置通联数据接口的token凭证码'
|
160
|
+
BOX_INPUT_ERR_MSG = '请输入YYYY-MM格式的年月数据'.freeze
|
161
|
+
DP_URL = '%sapp.finance.%s/data/stock/%s?day=&page=%s'
|
162
|
+
DP_163_URL = '%squotes.%s/data/caibao/%s?reportdate=%s&sort=declaredate&order=desc&page=%s'.freeze
|
163
|
+
FUND_HOLDS_URL = '%squotes.%s/hs/marketdata/service/%s?host=/hs/marketdata/service/%s&page=%s&query=start:%s;end:%s&order=desc&count=60&type=query&req=%s'
|
164
|
+
XSG_URL = '%sdatainterface.%s/EM_DataCenter/%s?type=FD&sty=BST&st=3&sr=true&fd=%s&stat=%s'.freeze
|
165
|
+
# LHB_URL = '%sdata.%s/stock/lhb/%s.html'.freeze
|
166
|
+
LHB_URL = '%sdata.%s/DataCenter_V3/stock2016/TradeDetail/pagesize=200,page=1,sortRule=-1,sortType=,startDate=%s,endDate=%s,gpfw=0,js=vardata_tab_1.html'
|
167
|
+
LHB_SINA_URL = '%s%s/q/go.php/vLHBData/kind/%s/%s?last=%s&p=%s'.freeze
|
168
|
+
LHB_TMP_COLS = %w(SCode SName Chgradio ZeMoney Bmoney Smoney Ctypedes
|
169
|
+
Turnover).freeze
|
170
|
+
LHB_COLS = %w(code name pchange amount buy sell reason Turnover).freeze
|
171
|
+
NEW_STOCKS_URL = '%s%s/corp/view/%s?page=%s&cngem=0&orderBy=NetDate&orderType=desc'.freeze
|
172
|
+
MAR_SH_HZ_URL = '%s%s/marketdata/tradedata/%s?jsonCallBack=jsonpCallback%s&isPagination=true&tabType=&pageHelp.pageSize=100&beginDate=%s&endDate=%s%s&_=%s'
|
173
|
+
MAR_SH_HZ_REF_URL = '%s%s/market/dealingdata/overview/margin/'
|
174
|
+
MAR_SH_MX_URL = '%s%s/marketdata/tradedata/%s?jsonCallBack=jsonpCallback%s&isPagination=true&tabType=mxtype&detailsDate=%s&pageHelp.pageSize=100&stockCode=%s&beginDate=%s&endDate=%s%s&_=%s'.freeze
|
175
|
+
MAR_SZ_HZ_URL = '%s%s/szseWeb/%s?SHOWTYPE=EXCEL&ACTIONID=8&CATALOGID=1837_xxpl&txtDate=%s&tab2PAGENUM=1&ENCODE=1&TABKEY=tab1'.freeze
|
176
|
+
MAR_SZ_MX_URL = '%s%s/szseWeb/%s?SHOWTYPE=EXCEL&ACTIONID=8&CATALOGID=1837_xxpl&txtDate=%s&tab2PAGENUM=1&ENCODE=1&TABKEY=tab2'.freeze
|
177
|
+
MAR_SH_HZ_TAIL_URL = '&pageHelp.pageNo=%s&pageHelp.beginPage=%s&pageHelp.endPage=%s'.freeze
|
178
|
+
TERMINATED_URL = '%s%s/%s?jsonCallBack=jsonpCallback%s&isPagination=true&sqlId=COMMON_SSE_ZQPZ_GPLB_MCJS_ZZSSGGJBXX_L&pageHelp.pageSize=50&_=%s'.freeze
|
179
|
+
SUSPENDED_URL = '%s%s/%s?jsonCallBack=jsonpCallback%s&isPagination=true&sqlId=COMMON_SSE_ZQPZ_GPLB_MCJS_ZTSSGS_L&pageHelp.pageSize=50&_=%s'
|
180
|
+
TERMINATED_T_COLS = %w(COMPANY_CODE COMPANY_ABBR LISTING_DATE CHANGE_DATE).freeze
|
181
|
+
LHB_KINDS = %w(ggtj yytj jgzz jgmx).freeze
|
182
|
+
LHB_GGTJ_COLS = %w(code name count bamount samount net bcount scount).freeze
|
183
|
+
LHB_YYTJ_COLS = %w(broker count bamount bcount samount scount top3).freeze
|
184
|
+
LHB_JGZZ_COLS = %w(code name bamount bcount samount scount net).freeze
|
185
|
+
LHB_JGMX_COLS = %w(code name date bamount samount type).freeze
|
186
|
+
TERMINATED_COLS = %w(code name oDate tDate).freeze
|
187
|
+
DP_COLS = ['report_date', 'quarter', 'code', 'name', 'plan']
|
188
|
+
DP_163_COLS = %w(code name year plan report_date).freeze
|
189
|
+
XSG_COLS = %w(code name date count ratio).freeze
|
190
|
+
QUARTS_DIC = {
|
191
|
+
'1' => ['%s-12-31', '%s-03-31'],
|
192
|
+
'2' => ['%s-03-31', '%s-06-30'],
|
193
|
+
'3' => ['%s-06-30', '%s-09-30'],
|
194
|
+
'4' => ['%s-9-30', '%s-12-31']
|
195
|
+
}.freeze
|
196
|
+
FUND_HOLDS_COLS = ['count', 'clast', 'date', 'ratio', 'amount', 'nums','nlast', 'name', 'code']
|
197
|
+
NEW_STOCKS_COLS = ['code', 'name', 'ipo_date', 'issue_date', 'amount', 'markets', 'price', 'pe',
|
198
|
+
'limit', 'funds', 'ballot']
|
199
|
+
MAR_SH_COOKIES = { '_gscu_1808689395' => '27850607moztu036' }.freeze
|
200
|
+
MAR_SH_HZ_COLS = %w(opDate rzye rzmre rqyl rqylje rqmcl rzrqjyzl).freeze
|
201
|
+
MAR_SH_MX_COLS = ['opDate', 'stockCode', 'securityAbbr', 'rzye', 'rzmre', 'rzche', 'rqyl', 'rqmcl', 'rqchl']
|
202
|
+
MAR_SZ_HZ_COLS = %w(rzmre rzye rqmcl rqyl rqye rzrqye).freeze
|
203
|
+
MAR_SZ_MX_COLS = %w(stockCode securityAbbr rzmre rzye rqmcl rqyl rqye rzrqye).freeze
|
204
|
+
MAR_SZ_HZ_MSG = 'please do not input more than a year,you can obtaining the data year by year.'.freeze
|
205
|
+
MAR_SZ_HZ_MSG2 = 'start and end date all need input.'.freeze
|
206
|
+
# for NewsEvent
|
207
|
+
LATEST_URL = '%sroll.news.%s/interface/%s?col=43&spec=&type=&ch=03&k=&offset_page=0&offset_num=0&num=%s&asc=&page=1&r=0.%s'.freeze
|
208
|
+
LATEST_COLS = %w(classify title time url).freeze
|
209
|
+
LATEST_COLS_C = %w(classify title time url content).freeze
|
210
|
+
NOTICE_INFO_URL = '%s%s/corp/view/%s?stock_str=%s'.freeze
|
211
|
+
NOTICE_INFO_CLS = %w(title type date url).freeze
|
212
|
+
GUBA_SINA_URL = '%sguba.%s'.freeze
|
213
|
+
GUBA_SINA_COLS = %w(title content ptime rcounts).freeze
|
214
|
+
# for Macro
|
215
|
+
MACRO_TYPE = %w(nation price fininfo).freeze
|
216
|
+
MACRO_URL = '%smoney.finance.%s/mac/api/jsonp.php/SINAREMOTECALLCALLBACK%s/MacPage_Service.get_pagedata?cate=%s&event=%s&from=0&num=%s&condition=&_=%s'.freeze
|
217
|
+
GDP_YEAR_COLS = %w(year gdp pc_gdp gnp pi si industry cons_industry ti
|
218
|
+
trans_industry lbdy).freeze
|
219
|
+
GDP_QUARTER_COLS = %w(quarter gdp gdp_yoy pi pi_yoy si si_yoy ti ti_yoy).freeze
|
220
|
+
GDP_FOR_COLS = %w(year end_for for_rate asset_for asset_rate goods_for
|
221
|
+
goods_rate).freeze
|
222
|
+
GDP_PULL_COLS = %w(year gdp_yoy pi si industry ti).freeze
|
223
|
+
GDP_CONTRIB_COLS = %w(year gdp_yoy pi si industry ti).freeze
|
224
|
+
CPI_COLS = %w(month cpi).freeze
|
225
|
+
PPI_COLS = %w(month ppiip ppi qm rmi pi cg food clothing roeu dcg).freeze
|
226
|
+
DEPOSIT_COLS = %w(date deposit_type rate).freeze
|
227
|
+
LOAN_COLS = %w(date loan_type rate).freeze
|
228
|
+
RRR_COLS = %w(date before now changed).freeze
|
229
|
+
MONEY_SUPPLY_COLS = %w(month m2 m2_yoy m1 m1_yoy m0 m0_yoy cd cd_yoy qm
|
230
|
+
qm_yoy ftd ftd_yoy sd sd_yoy rests rests_yoy).freeze
|
231
|
+
MONEY_SUPPLY_BLA_COLS = %w(year m2 m1 m0 cd qm ftd sd rests).freeze
|
232
|
+
ALL_CAL_FILE = format('%s%s/static/calAll.csv', P_TYPE['http'], DOMAINS['oss']).freeze
|
233
|
+
|
234
|
+
|
235
|
+
module Util
|
236
|
+
# 生成symbol代码标志
|
237
|
+
def _code_to_symbol(code)
|
238
|
+
return INDEX_LIST[code] if INDEX_LABELS.include?(code)
|
239
|
+
return '' if code.nil? or code.size != 6
|
240
|
+
['5','6','9'].include?(code[0]) ? "sh#{code}" : "sz#{code}"
|
241
|
+
end
|
242
|
+
|
243
|
+
def _write_console()
|
244
|
+
$stdout.write(DATA_GETTING_FLAG)
|
245
|
+
$stdout.flush()
|
246
|
+
end
|
247
|
+
def _write_head()
|
248
|
+
$stdout.write(DATA_GETTING_TIPS)
|
249
|
+
$stdout.flush()
|
250
|
+
end
|
251
|
+
|
252
|
+
def check_year(year)
|
253
|
+
fail "year param: #{year} is wrong format" if year.to_i < 1989
|
254
|
+
end
|
255
|
+
|
256
|
+
def check_quarter(quarter)
|
257
|
+
fail "quarter param: #{quarter} is wrong" unless (1..4).cover? quarter
|
258
|
+
end
|
259
|
+
|
260
|
+
def fetch_ftp_file(url, &block)
|
261
|
+
uri = URI(url)
|
262
|
+
local_file_path = "/tmp/#{File.basename(uri.path)}"
|
263
|
+
ftp = Net::FTP.new(uri.host)
|
264
|
+
ftp.login
|
265
|
+
ftp.getbinaryfile(uri.path, local_file_path)
|
266
|
+
return local_file_path unless block_given?
|
267
|
+
file = File.new(local_file_path)
|
268
|
+
result = yield file if block_given?
|
269
|
+
file.close
|
270
|
+
File.delete(local_file_path)
|
271
|
+
result
|
272
|
+
end
|
273
|
+
|
274
|
+
# 交易日历 isOpen=1是交易日,isOpen=0为休市
|
275
|
+
def trade_cal
|
276
|
+
resp = HTTParty.get(ALL_CAL_FILE)
|
277
|
+
result = []
|
278
|
+
CSV.new(resp.body.encode('utf-8', 'gbk')).drop(1).each do |arr|
|
279
|
+
result << { 'date' => arr[0], 'is_open' => arr[1] }
|
280
|
+
end
|
281
|
+
result
|
282
|
+
end
|
283
|
+
|
284
|
+
# 判断是否为交易日,返回 true or false
|
285
|
+
def holiday?(date)
|
286
|
+
trade_cals = trade_cal
|
287
|
+
holidays = trade_cals.select { |object| object['is_open'] == 0 }
|
288
|
+
.map { |object| object['date'] }
|
289
|
+
[6, 7].include?(date.cwday) ||
|
290
|
+
holidays.include?(date.strftime('%F'))
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
data/tushare.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tushare/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tushare"
|
8
|
+
spec.version = Tushare::VERSION
|
9
|
+
spec.authors = ["Robot Jiang", "Roger Mo"]
|
10
|
+
spec.email = ["robot.z.jiang@gmail.com", "ShallmentMo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Tushare-Ruby is ruby version of [tushare](https://github.com/waditu/tushare)}
|
13
|
+
spec.description = %q{Tushare-Ruby is ruby version of [tushare](https://github.com/waditu/tushare). TuShare is a utility for crawling historical data of China stocks}
|
14
|
+
spec.homepage = "https://github.com/waditu/tushare-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "httparty", "~> 0.14"
|
23
|
+
spec.add_dependency "nokogiri", "~> 1.7"
|
24
|
+
spec.add_dependency "table_print", "~> 1.5"
|
25
|
+
spec.add_dependency "awesome_print", "~> 1.7"
|
26
|
+
spec.add_dependency "roo", "~> 2.7"
|
27
|
+
spec.add_dependency "roo-xls", "~> 1.0"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tushare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robot Jiang
|
8
|
+
- Roger Mo
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.14'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.14'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.7'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.7'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: table_print
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.5'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.5'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: awesome_print
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.7'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.7'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: roo
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.7'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.7'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: roo-xls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: bundler
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.8'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1.8'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '10.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '10.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '3.4'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.4'
|
140
|
+
description: Tushare-Ruby is ruby version of [tushare](https://github.com/waditu/tushare).
|
141
|
+
TuShare is a utility for crawling historical data of China stocks
|
142
|
+
email:
|
143
|
+
- robot.z.jiang@gmail.com
|
144
|
+
- ShallmentMo@gmail.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- ".gitignore"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- lib/tushare.rb
|
159
|
+
- lib/tushare/datayes.rb
|
160
|
+
- lib/tushare/datayes/bond.rb
|
161
|
+
- lib/tushare/datayes/constants.rb
|
162
|
+
- lib/tushare/datayes/equity.rb
|
163
|
+
- lib/tushare/datayes/fund.rb
|
164
|
+
- lib/tushare/datayes/fundamental.rb
|
165
|
+
- lib/tushare/datayes/future.rb
|
166
|
+
- lib/tushare/datayes/hk_equity.rb
|
167
|
+
- lib/tushare/datayes/idx.rb
|
168
|
+
- lib/tushare/datayes/iv.rb
|
169
|
+
- lib/tushare/datayes/macro.rb
|
170
|
+
- lib/tushare/datayes/market.rb
|
171
|
+
- lib/tushare/datayes/master.rb
|
172
|
+
- lib/tushare/datayes/options.rb
|
173
|
+
- lib/tushare/datayes/subject.rb
|
174
|
+
- lib/tushare/internet/box_office.rb
|
175
|
+
- lib/tushare/stock/billboard.rb
|
176
|
+
- lib/tushare/stock/classifying.rb
|
177
|
+
- lib/tushare/stock/fundamental.rb
|
178
|
+
- lib/tushare/stock/macro.rb
|
179
|
+
- lib/tushare/stock/news_event.rb
|
180
|
+
- lib/tushare/stock/reference.rb
|
181
|
+
- lib/tushare/stock/shibor.rb
|
182
|
+
- lib/tushare/stock/trading.rb
|
183
|
+
- lib/tushare/util.rb
|
184
|
+
- lib/tushare/version.rb
|
185
|
+
- tushare.gemspec
|
186
|
+
homepage: https://github.com/waditu/tushare-ruby
|
187
|
+
licenses:
|
188
|
+
- MIT
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.5.1
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: Tushare-Ruby is ruby version of [tushare](https://github.com/waditu/tushare)
|
210
|
+
test_files: []
|
211
|
+
has_rdoc:
|