def get_shares_GroupbyClassify_EM(concept): fp='webdata/puse/eastmpy/classified.pkl' f=open(fp,'rb') classify=pickle.load(f) f.close() if concept in classify.keys(): url='http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.{0}1&sty=FCOIATA&sortType=(ChangePercent)&sortRule=-1&page=1&pageSize=1000&js={1}&token=7bc05d0d4c3c22ef9fca8c2a912d779c'.format(classify[concept],'{%22rank%22:[(x)],%22pages%22:(pc),%22total%22:(tot)}') r=requests.get(url,headers=hds()) dtext=json.loads(r.text) dd='\n'.join(dtext['rank']) df=pd.read_csv(StringIO(dd),header=None) df=df.drop([0,13,14,15,16,18,17,19,20],axis=1) df.columns=['code','name','close','chg','chgp%','zhengfu%','volume','amount','pre_close','open','high','low','chgp_in_5m%','liangbi','turnover%','PE','listed_date'] df['code']=df['code'].map(lambda x:str(x).zfill(6)) df=df.set_index('code') df=df.replace('-',np.nan) for label in df.columns: try: df[label]=df[label].astype(float) except: df[label]=df[label].map(lambda x: wt._tofl(x)) return df else: print("%s not in classify......"%concept) print(classify.keys()) sys.exit()
def get_cashf_sharehist_min_EM(code, day=today): """获得某只股票的资金流入流出情况,按1min中进行统计, day为交易日的条数 bkname 为板块的名称 """ if code[0] in ['6', '9']: code = code + '1' elif code[0] in ['0', '2', '3']: code = code + '2' url = 'http://ff.eastmoney.com/EM_CapitalFlowInterface/api/js?id={0}&type=ff&check=MLBMS&cb=var%20aff_data={1}&js={2}&rtntype=3&acces_token=1942f5da9b46b069953c873404aad4b5'.format( code, day, '{(x)}') r = requests.get(url, headers=hds()) pc = '=' + day text = r.text.split(pc)[1] #print(text) data = json.loads(text) dataset = [] for i in data['ya']: dataset.append(i.split(',')) df = pd.DataFrame(dataset) index = data['xa'].split(',') index = index[:df.shape[0]] df.index = index df = df.replace('', np.nan) df = df.dropna(how='all', axis=0) df.columns = ['Main', 'Super', 'Big', 'Middle', 'Small'] df = df.applymap(lambda x: wt._tofl(x)) return df
def get_holder_change_EM(code): url = 'http://data.eastmoney.com/DataCenter_V3/gdhs/GetDetial.ashx?code={0}&js=var%20wDmaHnNC&pagesize=5000&page=1&sortRule=-1&sortType=EndDate¶m=&rt=50019973'.format( code) r = requests.get(url, headers=hds()) text = r.text.split("wDmaHnNC=")[1] data = json.loads(text) df = pd.DataFrame(data['data']) #df['NoticeDate']=df['NoticeDate'].map(lambda x:x[:10]) df['EndDate'] = df['EndDate'].map(lambda x: x[:10]) df = df.set_index('EndDate') df = df.sort_index() try: del df['NoticeDate'] del df['CapitalStockChange'] del df['CapitalStockChangeEvent'] except: pass df = df.applymap(lambda x: wt._tofl(x)) return df
def get_holder_analys_EM(year,qu): """股东持股明细,reportdate='2017-06-30' """ reportdate=quarter[qu]%year url="http://dcfm.eastmoney.com//em_mutisvcexpandinterface/api/js/get?type=NSHDDETAILLA&token=70f12f2f4f091e459a279469fe49eca5&cmd=&st=NDATE,SCODE,RANK&sr=1&p=1&ps=5000&js={1}&filter=(RDATE=%27^{0}^%27)".format(reportdate,'{%22pages%22:(tp),%22data%22:(x)}') #print(url) r=requests.get(url,headers=hds()) text=r.text text=text.replace('pages:','"pages":').replace("data:",'"data":') #print(text[:30]) data=json.loads(text) df=pd.DataFrame(data['data']) tp=data['pages'] if tp>1: for i in range(2,tp+1): url="http://dcfm.eastmoney.com//em_mutisvcexpandinterface/api/js/get?type=NSHDDETAILLA&token=70f12f2f4f091e459a279469fe49eca5&cmd=&st=NDATE,SCODE,RANK&sr=1&p={2}&ps=5000&js={1}&filter=(RDATE=%27^{0}^%27)".format(reportdate,'{%22pages%22:(tp),%22data%22:(x)}',i) r=requests.get(url,headers=hds()) text=r.text text=text.replace('pages:','"pages":').replace("data:",'"data":') data=json.loads(text) df=df.append(pd.DataFrame(data['data'])) df['NDATE']=df['NDATE'].map(lambda x:x[:10]) df['RDATE']=df['RDATE'].map(lambda x:x[:10]) df=df.replace('-',np.nan) df=df.drop(['SHAREHDCODE','COMPANYCODE', 'SHARESTYPE', 'LTAG'],axis=1) df=df.applymap(lambda x:wt._tofl(x)) df['SCODE']=df['SCODE'].map(lambda x:str(x).split('.')[0].zfill(6)) return df
def get_sharesholded_change_EM(code=None,mtype='all'): """股东对股票的增减持情况 ------------------------- mtype: all--所有的变动;jjc--减持;jzc--增持。 """ if code is None: code='' url='http://data.eastmoney.com/DataCenter_V3/gdzjc.ashx?pagesize=5000&page=1¶m=&sortRule=-1&sortType=BDJZ&tabid={1}&code={0}&name='.format(code,mtype) r=requests.get(url,headers=hds()) text=r.text.split(',data:["')[1].split('"] ,"url')[0] text=text.replace('","','\n') df=pd.read_csv(StringIO(text),header=None) tp=r.text.split(",data:[")[0].split("pages:")[1] tp=int(tp) if tp>1: for i in range(2,tp+1): url='http://data.eastmoney.com/DataCenter_V3/gdzjc.ashx?pagesize=5000&page={1}¶m=&sortRule=-1&sortType=BDJZ&tabid=all&code={0}&name='.format(code,i) r=requests.get(url,headers=hds()) text=r.text.split(',data:["')[1].split('"] ,"url')[0] text=text.replace('","','\n') df=df.append(pd.read_csv(StringIO(text),header=None)) #df=df.drop(16,axis=1) df.columns=['code','name','price','chg','holder','type','chg_num','chg.cur.rate','source','hold_num','tt.rate','hold_cur_num','cur.rate','start','end','date','chg.tt.rate'] df=df.applymap(lambda x:wt._tofl(x)) df['code']=df['code'].map(lambda x:str(x).zfill(6)) df=df.reset_index(drop=True) return df
def _settle(url): r = requests.get(url, headers=hds()) text = r.text data = json.loads(text) try: data = json.loads(data) except: pass df = pd.DataFrame(data) name = list(df.columns)[:4] name.extend(list(df.iloc[0, 4:])) df.columns = name df = df.drop(0, axis=0) del df['Indent'] del df['IsBold'] del df['IsShowChart'] df = df.set_index("IndexName") df = df.dropna(how='all', axis=0) #df=df.dropna(how='all',axis=0) df = df.applymap(lambda x: wt._tofl(x)) df = df.T df = df.sort_index() df = df.replace('-', np.nan) return df
def get_tick_today_EM(code, mtype=0): if code[0] in ['6', '9']: code = code + '1' if code[0] in ['0', '2', '3']: code = code + '2' url = 'http://hqdigi2.eastmoney.com/EM_Quote2010NumericApplication/CompatiblePage.aspx?Type=OB&stk={0}&Reference=xml&limit={1}&page=1'.format( code, mtype) r = requests.get(url, headers=hds()) text = r.text.split('=')[1] data = text.split('data:["')[1].replace('"]};', '').replace('","', '\n') df = pd.read_csv(StringIO(data), header=None) page = text.split('{pages:')[1].split(',data:')[0] page = int(page) if page > 1: for i in range(2, page + 1): url = 'http://hqdigi2.eastmoney.com/EM_Quote2010NumericApplication/CompatiblePage.aspx?Type=OB&stk={0}&Reference=xml&limit={1}&page={2}'.format( code, mtype, i) r = requests.get(url, headers=hds()) text = r.text.split('=')[1] data = text.split('data:["')[1].replace('"]};', '').replace('","', '\n') df = df.append(pd.read_csv(StringIO(data), header=None)) df.columns = ['time', 'price', 'volume', 'type'] df = df.applymap(lambda x: wt._tofl(x)) return df
def get_cashf_concepthist_EM(bkname): """板块的历史资金流向,资金流入金额的单位均为万元 -------------------------------------- Main.I.net :今日主力净流入净额 Main.I.R :今日主力净流入净占比 """ try: df = pd.read_pickle('output/eastmsource/bk.pkl') except: df = pd.read_csv('output/eastmsource/bk.csv', encoding='gbk') idd = df[df['name'] == bkname]['id'].tolist()[0] #idd=df.loc[bkname,'id'] url = 'http://ff.eastmoney.com//EM_CapitalFlowInterface/api/js?type=hff&rtntype=2&js={1}&cb=var%20aff_data=&check=TMLBMSPROCR&acces_token=1942f5da9b46b069953c873404aad4b5&id={0}1&_=1502340432743'.format( idd, '{%22data%22:(x)}') r = requests.get(url, headers=hds()) text = r.text.split('{"data":["')[1].replace('(["', '').replace('"])', '') text = text.replace('"]}', '') text = text.replace('","', '\n') #print(text) df = pd.read_csv(StringIO(text), header=None) df.columns = [ 'date', 'Main.I.net', 'Main.I.R', 'Su.I.net', 'Su.I.R', 'Big.I.net', 'Big.I.R', 'Mid.I.net', 'Mid.I.R', 'Sm.I.net', 'Sm.I.R', 'price', 'Chg%' ] df = df.applymap(lambda x: wt._tofl(x)) df = df.set_index('date') return df
def get_cashf_sharehist_EM(code): """个股的历史资金流向,资金流入金额的单位均为万元 -------------------------------------- Main.I.net :今日主力净流入净额 Main.I.R :今日主力净流入净占比 """ if code[0] in ['6', '9']: code = code + '1' if code[0] in ['0', '2', '3']: code = code + '2' url = 'http://ff.eastmoney.com//EM_CapitalFlowInterface/api/js?type=hff&rtntype=2&check=TMLBMSPROCR&acces_token=1942f5da9b46b069953c873404aad4b5&id={0}'.format( code) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df.columns = [ 'date', 'Main.I.net', 'Main.I.R', 'Su.I.net', 'Su.I.R', 'Big.I.net', 'Big.I.R', 'Mid.I.net', 'Mid.I.R', 'Sm.I.net', 'Sm.I.R', 'price', 'Chg%' ] df = df.applymap(lambda x: wt._tofl(x)) df = df.set_index('date') return df
def get_Future_info_EM(mtype='sqs'): """ 核心题材 -------------------------- mtype:为股票代码,为6位数 """ url = future[mtype] df = _basic(url) df = df.applymap(lambda x: wt._tofl(x)) df = df.replace('-', np.nan) return df
def get_seniorM_holder_EM(): """董监高及相关人员持股变动明细 """ url='http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=GG&sty=GGMX&p=1&ps=5000' #print(url) r=requests.get(url,headers=hds()) text=r.text.replace('(["','').replace('"])','') text=text.replace('","','\n') df=pd.read_csv(StringIO(text),header=None) df=df.drop([4,11,15],axis=1) df.columns=['chg','senior','code','holder','date','chg_num','num','trade_price','name','relation','reason','amount','title'] df=df.applymap(lambda x:wt._tofl(x)) df['code']=df['code'].map(lambda x:str(x).zfill(6)) #df=df.set_index('code') #df=df.replace('-',np.nan) return df
def HK_dividend_EM(code): url = wt.div_url.format(code, wt.yearl) #df=_settle(url) r = requests.get(url, headers=hds()) text = r.text data = json.loads(text) df = pd.DataFrame(data) df.columns = df.iloc[0, :].tolist() df = df.set_index('除权日') df = df.applymap(lambda x: wt._tofl(x)) df = df.T df = df.sort_index() df = df.replace('-', np.nan) df = df.drop('除权日', axis=1) df = df.dropna(how='all', axis=1) #print(data) return df
def HK_trade_data_EM(code): """ 查询香港股票的每日交易统计数据 http://hkf10.eastmoney.com/html_HKStock/index.html?securitycode=00005&name=dailyData -------------------------- code:为香港的股票代码,为5位数 """ url = 'http://hkf10.eastmoney.com/F9HKStock/GetStockDailyMarketDataList.do?securityCode={0}.HK&yearList=2017,2016,2015,2014,2013&dateSearchType=1&rotate=1&seperate=0&order=desc&cashType=0&exchangeValue=1&customSelect=0&CurrencySelect=0'.format( code) #print(url) r = requests.get(url, headers=hds()) text = r.text data = json.loads(text) df = pd.DataFrame(data) df = df.set_index('TRADEDATE') df = df.sort_index() df.index.name = 'date' df = df.applymap(lambda x: wt._tofl(x)) return df
def get_Future_comparetoGlobal(): url = 'http://hq2data.eastmoney.com/qhbj/index.aspx?param=RmbLatestPrice&sort=0' r = requests.get(url, headers=hds()) content = r.text content = content.split('futures:["')[1].replace('"]}', '').replace('","', '\n') df = pd.read_csv(StringIO(content), header=None) df = df.drop([2, 3, 4, 7, 8, 15, 16, 17], axis=1) df.columns = [ 'name', 'Exchange', 'M_name', 'G_name', 'M_price', 'M_chg', 'G_price', 'G_chg', 'ToRMB', 'spread' ] del df['Exchange'] df = df.set_index('name') df = df.applymap(lambda x: wt._tofl(x)) df = df.replace('-', np.nan) return df
def get_classified_index_EM(concept,mtype='day',fq='fq'): """ 获取行业\概念\地域版块的指数: ------------------------------- concept:行业\概念\地域 名词 fq:不复权,None;qfq:前复权;hfq:后复权 mtype:day,日线;week,周线;month,月线;m5:5分钟线;m15:15分钟线;m30:30分钟 线;m60:60分钟线 """ fqv={'fq':'','qfq':'authorityType=fa','hfq':'authorityType=ba'} kline={'day':'K','month':'mk','week':'wk','m5':'m5k','m15':'m15k','m30':'m30k','m60':'m60k'} fp='webdata/puse/eastmpy/classified.pkl' f=open(fp,'rb') classify=pickle.load(f) f.close() if concept in classify.keys(): if fq =='fq': url='http://pdfm2.eastmoney.com/EM_UBG_PDTI_Fast/api/js?id=%s1&TYPE=%s&js=(x)&rtntype=5'%(classify[concept],kline[mtype]) else: url='http://pdfm2.eastmoney.com/EM_UBG_PDTI_Fast/api/js?id=%s1&TYPE=%s&js=(x)&rtntype=5&%s'%(classify[concept],kline[mtype],fqv[fq]) r=requests.get(url,headers=hds()) dtext=json.loads(r.text) dd='\n'.join(dtext['data']) df=pd.read_csv(StringIO(dd),header=None) df.columns=['date','open','close','high','low','volume','amount','turnover'] df=df.set_index('date') df.index=pd.to_datetime(df.index) df=df.replace('-',np.nan) for label in df.columns: try: df[label]=df[label].astype(float) except: df[label]=df[label].map(lambda x: wt._tofl(x)) return df else: print("%s not in classify......"%concept) print(classify.keys()) sys.exit()
def HK_HSG_EM(): hurl = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.BK07071&sty=FCOIATA&sortType=C&sortRule=-1&page=1&pageSize=20000&js=var%20quote_123%3d{%22rank%22:[(x)],%22pages%22:(pc)}&token=7bc05d0d4c3c22ef9fca8c2a912d779c&jsName=quote_123&_g=0.785481323255226' surl = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.BK08041&sty=FCOIATA&sortType=C&sortRule=-1&page=1&pageSize=20000&js=var%20quote_123%3d{%22rank%22:[(x)],%22pages%22:(pc)}&token=7bc05d0d4c3c22ef9fca8c2a912d779c&jsName=quote_123&_g=0.03943358431570232' uls = [surl, hurl] df = pd.DataFrame() for url in uls: #print(url) df = df.append(_hk_ggt(url)) df = df.drop([0, 13, 14, 15, 16, 17, 18, 19, 20], axis=1) df.columns = [ 'code', 'name', 'close', 'chg', 'chg%', 'apmature', 'volume', 'amount', 'pre.close', 'open', 'high', 'low', 'chg_5m', 'LB', 'turnover', 'PE' ] df = df.drop_duplicates() df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(6)) #df=df.sort_values(by='chg%',ascending=False) return df
def cashfl_concept_hist(self, bkname): """核心题材 """ idd = self.bk[self.bk['name'] == bkname]['id'].tolist()[0] #print(idd) url = 'http://data.eastmoney.com/bkzj/{0}.html'.format(idd) self.driver.get(url) waitForLoad(self.driver) self.driver.find_element_by_xpath('//ul[@id="s1-tab"]/li[2]').click() text = self.driver.find_element_by_xpath( '//table[@id="tb_lishi"]').text text = text.replace(' ', ',') text = text.split('\n') dataset = [] for i in text[2:]: dataset.append(i) df = pd.read_csv(StringIO('\n'.join(dataset)), header=None) df = df.applymap(lambda x: wt._tofl(x)) #df=df.applymap(lambda x:wt._tofl(x)) return df
def get_finance_index_EM(year, qu): yq = quarter[qu] % year url = 'http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SR&sty=YJBB&fd=%s&st=13&sr=-1&p=1&ps=5000000' % yq #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df = df.drop([14, 15, 18], axis=1) df.columns = [ 'code', 'name', 'eps', 'eps_d', 'rev', 'rev_yoy', 'rev_hb', 'profit', 'profit_yoy', 'profit_hb', 'nav_ps', 'roe', 'cf_ps', 'margin', 'pulish', 'report' ] df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(6)) df = df.set_index('code') df = df.replace('-', np.nan) return df
def get_bkindex_EM(name, mtype='D'): mtp = { 'd': 'k', 'wk': 'wk', 'mk': 'mk', '5min': 'm5k', '15min': 'm15k', '30min': 'm30k', '60min': 'm60k' } mtype = mtype.lower() timestamp = int(time.time() * 1000) names = wt.bkurlsets.keys() flag = True if name not in names: while flag: name = input("Input BK name:") if name in names: flag = False bkid = os.path.splitext(os.path.basename(urlsets[name]))[0] + '1' url = 'http://pdfm2.eastmoney.com/EM_UBG_PDTI_Fast/api/js?id=%s&TYPE=%s&js=(x)&rtntype=5&isCR=false&fsData%s' % ( bkid, mtp[mtype], timestamp) r = requests.get(url) text = r.text #print(text[:300]) data = json.loads(text) df = pd.read_csv(StringIO('\n'.join(data['data'])), header=None) df.columns = [ 'date', 'open', 'close', 'high', 'low', 'volume', 'amount', 'amplitude' ] df = df.set_index('date') df.index = pd.to_datetime(df.index) for label in df.columns: try: df[label] = df[label].astype(float) except: df[label] = df[label].map(lambda x: wt._tofl(x)) return df
def get_forcast_EM(year, qu): yq = quarter[qu] % year url = 'http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SR&sty=YJYG&fd=%s&st=4&sr=-1&p=1&ps=500000' % yq #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) #df=df.drop([14,15,18],axis=1) df.columns = [ 'code', 'name', 'describe', 'change_period', 'type', 'prof_l', 'ttype', 'pulish', 'date' ] df = df.replace('-', np.nan) df['cc'] = df['change_period'].map(lambda x: ss.findall(str(x))) df['Down'] = np.nan df['Up'] = np.nan for i in range(df.shape[0]): if len(df.iloc[i, df.columns.get_loc('cc')]) == 2: df.iloc[i, df.columns.get_loc('Down')] = df.iloc[ i, df.columns.get_loc('cc')][0] df.iloc[i, df.columns.get_loc('Up')] = df.iloc[ i, df.columns.get_loc('cc')][1] elif len(df.iloc[i, df.columns.get_loc('cc')]) == 1: df.iloc[i, df.columns.get_loc('Down')] = df.iloc[ i, df.columns.get_loc('cc')][0] df.iloc[i, df.columns.get_loc('Up')] = df.iloc[ i, df.columns.get_loc('cc')][0] del df['cc'] df = df[[ 'code', 'name', 'change_period', 'Down', 'Up', 'type', 'prof_l', 'ttype', 'describe', 'pulish', 'date' ]] df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(6)) df = df.set_index('code') return df
def HK_GGT_EM(): """ 获取港股通的股票数据,即通过国内交易系统可以购买香港市场的股票 """ urlh = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.mk0144&sty=CTF&sortType=C&sortRule=-1&page=1&pageSize=20000&js=var%20quote_123%3d{%22rank%22:[(x)],%22pages%22:(pc)}&token=44c9d251add88e27b65ed86506f6e5da&jsName=quote_123&_g=0.5358432093635201' urls = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.mk0146&sty=CTF&sortType=C&sortRule=-1&page=1&pageSize=20000&js=var%20quote_123%3d{%22rank%22:[(x)],%22pages%22:(pc)}&token=44c9d251add88e27b65ed86506f6e5da&jsName=quote_123&_g=0.15627210377715528' uls = [urls, urlh] df = pd.DataFrame() for url in uls: #print(url) df = df.append(_hk_ggt(url)) df = df.drop([0, 6, 7], axis=1) df.columns = [ 'code', 'name', 'close', 'chg', 'chg%', 'unk', 'volume', 'amount', 'open', 'pre.close', 'high', 'low', 'turnover', 'PE' ] df = df.drop_duplicates() df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(5)) #df=df.sort_values(by='chg%',ascending=False) return df
def get_STI_EM(): """ 钢铁指数 -------------------------- """ url = 'http://dcfm.eastmoney.com//EM_MutiSvcExpandInterface/api/js/get?type=QHHQBLDH&token=70f12f2f4f091e459a279469fe49eca5&filter=(ID=%27EMI00662545%27)&st=DATADATE&sr=-1&p=1&ps=2000&js=var%20CENlUZQH={pages:(tp),data:(x)}&rt=50063561' r = requests.get(url, headers=hds()) text = r.text text = text.replace('pages', '"pages"').replace('data:[', '"data":[') text = text.split("=")[1] data = json.loads(text) df = pd.DataFrame(data['data']) tp = data['pages'] if tp > 1: for i in range(2, tp + 1): url = 'http://dcfm.eastmoney.com//EM_MutiSvcExpandInterface/api/js/get?type=QHHQBLDH&token=70f12f2f4f091e459a279469fe49eca5&filter=(ID=%27EMI00662545%27)&st=DATADATE&sr=-1&p={0}&ps=2000&js=var%20CENlUZQH={1}&rt=50063561'.format( i, '{pages:(tp),data:(x)}') r = requests.get(url, headers=hds()) text = r.text text = text.replace('pages', '"pages"').replace('data:[', '"data":[') text = text.split("=")[1] data = json.loads(text) df = df.append(pd.DataFrame(data['data'])) df.columns = ['date', 'code', 'price', 'change', 'chg'] df = df[['date', 'price', 'change', 'chg']] df = df.set_index('date') df = df.sort_index() df = df.applymap(lambda x: wt._tofl(x)) return df
def get_cashf_conceptshares_EM(bkname, day=''): """获取同行业的股票涨跌信息 """ try: df = pd.read_pickle('output/eastmsource/bk.pkl') except: df = pd.read_csv('output/eastmsource/bk.csv', encoding='gbk') idd = df[df['name'] == bkname]['id'].tolist()[0] #idd=df.loc[bkname,'id'] #print(idd) if len(day) == 0: day = 'BalFlowMain' elif len(day) > 0: day = 'BalFlowMainNet' + day url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cmd=C.{0}1&type=ct&st=({1})&sr=-1&p=1&ps=5000&token=894050c76af8597a853f5b408b759f5d&sty=DCFFITA'.format( idd, day) #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df = df.drop(0, axis=1) df = df.applymap(lambda x: wt._tofl(x)) try: df.columns = [ 'code', 'name', 'price', 'chg', 'Main.I.net', 'Main.I.R', 'Su.I.net', 'Su.I.R', 'Big.I.net', 'Big.I.R', 'Mid.I.net', 'Mid.I.R', 'Sm.I.net', 'Sm.I.R', 'date' ] df['code'] = df['code'].map(lambda x: str(x).zfill(6)) df['date'] = df['date'].map(lambda x: x[:10]) except: pass df = df.replace('-', np.nan) return df
def get_share_holdernum_change_EM(code): """个股的股东户数历史详情 """ url='http://data.eastmoney.com/DataCenter_V3/gdhs/GetDetial.ashx?code={0}&pagesize=500&page=1&sortRule=-1&sortType=EndDate¶m=&rt=50055484'.format(code) print(url) r=requests.get(url,headers=hds()) text=r.text print(text) data=json.loads(text) tp=data['pages'] df=pd.DataFrame(data['data']) if tp>1: for i in range(2,tp+1): url='http://data.eastmoney.com/DataCenter_V3/gdhs/GetDetial.ashx?code={0}&pagesize=500&page={1}&sortRule=-1&sortType=EndDate¶m=&rt=50055484'.format(code,i) r=requests.get(url,headers=hds()) text=r.text data=json.loads(text) df=df.append(pd.DataFrame(data['data'])) df=df.applymap(lambda x:wt._tofl(x)) for label in [ 'EndDate', 'NoticeDate', 'PreviousEndDate']: df[label]=df[label].map(lambda x:x[:10]) return df
def get_cashf_concept_EM(mtype='hy', day=''): """获取板块的现金流入情况 mtype:hy--行业板块;gn--概念板块;dy--地域板块 day: 分为当日的数据,5日的数据,10日的数据 =========================================== Main.I.net :今日主力净流入净额 Main.I.R :今日主力净流入净占比 """ day = 'BalFlowMain' + day if mtype == 'gn': url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cmd=C._BKGN&type=ct&st=({0})&sr=-1&p=1&ps=5000&token=894050c76af8597a853f5b408b759f5d&sty=DCFFITABK&rt=50054963'.format( day) if mtype == 'hy': url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cmd=C._BKHY&type=ct&st=({0})&sr=-1&p=1&ps=50000&token=894050c76af8597a853f5b408b759f5d&sty=DCFFITABK&rt=50054967'.format( day) if mtype == 'dy': url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cmd=C._BKDY&type=ct&st=({0})&sr=-1&p=1&ps=50&token=894050c76af8597a853f5b408b759f5d&sty=DCFFITABK'.format( day) #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df = df.drop([0], axis=1) df.columns = [ 'id', 'name', 'Chg%', 'Main.I.net', 'Main.I.R', 'Su.I.net', 'Su.I.R', 'Big.I.net', 'Big.I.R', 'Mid.I.net', 'Mid.I.R', 'Sm.I.net', 'Sm.I.R', 'Sec_name', 'code' ] df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(7)) df['code'] = df['code'].map(lambda x: x[:6]) return df
def get_cashf_conceptcenter_EM(bkname): """获取同行业股票行情中心的涨跌信息 """ try: df = pd.read_pickle('output/eastmsource/bk.pkl') except: df = pd.read_csv('output/eastmsource/bk.csv', encoding='gbk') idd = df[df['name'] == bkname]['id'].tolist()[0] #idd=df.loc[bkname,'id'] url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=CT&cmd=C.{0}1&sty=FCOIATA&sortType=C&sortRule=-1&page=1&pageSize=2000&token=7bc05d0d4c3c22ef9fca8c2a912d779c'.format( idd) #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df = df.drop([0, 13, 14, 15, 16, 17, 18, 19, 20], axis=1) df = df.applymap(lambda x: wt._tofl(x)) try: df.columns = [ 'code', 'name', 'price', 'chg', 'chg%', 'ZF', 'volume', 'amount', 'pre.close', 'open', 'high', 'low', 'chg.5m', 'LR', 'turnover', 'PE' ] df['code'] = df['code'].map(lambda x: str(x).zfill(6)) except: pass df = df.replace('-', np.nan) df = df.dropna(how='all', axis=1) return df
def get_cashf_alltoday_EM(): """主力资金流入排名 Main.R.T:主力净占比, Rank.T :今日排名 Chg%.T :今日涨跌 """ url = 'http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx/JS.aspx?type=ct&st=(FFRank)&sr=1&p=1&ps=50000&token=894050c76af8597a853f5b408b759f5d&cmd=C._AB&sty=DCFFITAM' #print(url) r = requests.get(url, headers=hds()) text = r.text.replace('(["', '').replace('"])', '') text = text.replace('","', '\n') df = pd.read_csv(StringIO(text), header=None) df = df.drop([0], axis=1) df.columns = [ 'code', 'name', 'price', 'Main.R.T', 'Rank.T', 'Chg%.T', 'Main.R.5', 'Rank.5', 'Chg%.5', 'Main.R.10', 'Rank.10', 'Chg%.10', 'industry', 'indu.ID', 'date' ] df = df.applymap(lambda x: wt._tofl(x)) df['code'] = df['code'].map(lambda x: str(x).zfill(6)) df = df.set_index('code') #df=df.replace('-',np.nan) return df