def rxt6(): ds=date_s.get() de=date_e.get() g.gtype=g.vbook.get() g.sday=ds.strip() g.eday=de.strip() item =tb6.tree.selection()[0] aa=tb6.tree.item(item, "values") bb=list(aa) g.stock=bb[2] g.vtitle=bb[3] stock.set(g.stock) g.gmarket=htdx.get_market(g.stock) df3=htdx.get_k_data2(g.stock,g.sday,g.eday) if g.tab3!=None: g.tabControl.forget(g.tab3) g.tab3=None #用户自建新画面 g.tab3 = tk.Frame(g.tabControl) g.tabControl.add(g.tab3, text='日线图') g.tabControl.select(g.tab3) axview3x(g.tab3,df3,t=g.stock+' '+g.stock_names[g.stock],n=2,f1='VOL',f2=g.gtype) g.tabControl.select(g.tab3) g.tabs=3
def bt(self,n=0): import HP_tdx as htdx mk=htdx.get_market(self.stock) df=htdx.get_company_info_category(mk,self.stock) self.F10text.delete(2.0,tk.END) self.F10text.insert(tk.INSERT,'\n\n') t=htdx.get_F10(self.stock,df.name[n]) self.F10text.insert(tk.INSERT,t)
def udestroy(): global timer timer.cancel() htdx.disconnect() #把结果保存到文件中 f = open('../../../Downloads/xb2e/data/zxg.dat', 'wb') pt=pickle.dumps(g.zxg,0) f.write(pt) f.close()
def hq3(): global hq if hq!=None: g.status.text(2,'正在下载代码表...请等待,如强制退出,将无法启动软件。') htdx.shcode() htdx.szcode() g.status.text(2,'代码表下载完成。') else: g.status.text(2,'没有连接行情服务器。')
def hq4(): global hq if hq==None: g.status.text(2,'没有连接行情服务器。') else: g.status.text(2,'正在下载财务报表...请等待,如强制退出,将无法启动软件。') htdx.get_szcw() htdx.get_shcw() g.status.text(2,'财务报表下载完成。')
def hq5(): global hq if hq==None: g.status.text(2,'没有连接行情服务器。') else: g.status.text(2,'正在下载板块数据...请等待,如强制退出,将无法启动软件。') df=htdx.get_block("block.dat") df=htdx.get_block("block_zs.dat") df=htdx.get_block("block_fg.dat") df=htdx.get_block("block_gn.dat") g.status.text(2,'板块数据下载完成。')
def hq1(): global hq g.status.text(2,'正在连接行情服务器...') hq=htdx.TdxInit(ip='180.153.18.171',port=7709) ##初始化通达信 if hq==None: g.status.text(2,'行情服务器连接失败!') else: g.status.text(2,'行情服务器连接成功!')
def hq2(): global hq if hq==None: g.status.text(2,'没有连接行情服务器。') else: hq=htdx.disconnect() ##断开通达信行情服务器 hq=None g.status.text(2,'已经断开行情服务器。')
def zxg6(): global tb1,tb2,tb3,tb4,tb5 item = tb6.tree.selection()[0] aa=tb6.tree.item(item, "values") bb=list(aa) g.stock=bb[2] g.vtitle=bb[3] stock.set(g.stock) g.gmarket=htdx.get_market(g.stock) g.zxg.append([g.gmarket,g.stock]) cd=get_szcode() cd2=get_shcode() cd=cd.append(cd2) cd=cd.reset_index(level=None, drop=True ,col_level=0, col_fill='') cds={} for i in range(len(cd)): cds[(cd.market[i],cd.code[i])]=cd.name[i] g.names=cds df=htdx.get_hq2(g.zxg) df=htdx.get_hq2(g.zxg) df['zd']=df['price']-df['last_close'] #涨跌 df['zdf1']=df['zd']*100/df['last_close'] #涨跌幅 df['vol']=df['vol']/10000 df=df.round(2) #改变符点数小数点后2位 df['zdf']=df['zdf1'].astype(str)+'%' df['code2']=['0'*(6-len(x)) + x for x in df.code.astype(str)] df['name']='' for i in range(len(df)): df.loc[i,'name']=cds[(df.loc[i,'market'],df.loc[i,'code2'])] df.to_csv('./data/hq.csv' , encoding= 'gbk') df=df[['code','name','zdf','price','zd','bid1','ask1','vol',\ 'high','open','low','last_close','market']] df.rename(columns={'code':'代码', 'name':'名称','zdf':'涨幅',\ 'price':'现价','zd':'涨跌','bid1':'买价',\ 'ask1':'卖价','vol':'总量(万)','open':'今开',\ 'high':'最高','low':'最低','last_close':'昨收',\ 'market':'市场'},\ inplace = True) tb5.clear() tb5.load_df(df) #把变量df的数据显示到表格中 tb5.brush() #用2种底色交替显示表格
def readbase(nMarket=0, code='000776'): global Cw global Code, Market, Setcode, Name, Py global Mindiff, Tqflag, Useddatanum, Multiplier global Totalcapital, Capital, Type2 if nMarket < 0: nMarket = htdx.get_market(code) Code = code Market = nMarket Cw = htdx.tdxapi.get_finance_info(nMarket, code) Totalcapital = Cw['zongguben'] Capital = int(Cw['liutongguben'] / 100) return Cw
def get_block(ss): import HP_tdx as htdx file = r'bk/' + ss + '.csv' df = pd.read_csv(file, encoding='gbk') df.rename(columns={'code':'code2'},\ inplace = True) df['code'] = ['0' * (6 - len(x)) + x for x in df.code2.astype(str)] df = df.drop('code2', axis=1) df['name'] = '' for i in range(len(df)): df.loc[i, 'name'] = g.names[(htdx.get_market(df.loc[i, 'code']), df.loc[i, 'code'])] return df
def init(self): import HP_tdx as htdx mk=htdx.get_market(self.stock) df=htdx.get_company_info_category(mk,self.stock) fr=tk.Frame(self.F10text) k=0 for i in range(self.r): for j in range(self.c): def kk(self=self, k=k): self.bt(k) self.button = tk.Button(fr,text=df.name[k],command=kk,cursor='hand2') self.b.append(self.button) self.button.grid(row=i, column=j, padx=1, pady=1, sticky=tk.E) k+=1 self.button2 = tk.Button(fr,text='切换股票',command=self.bt2,cursor='hand2') self.button2.grid(row=0, column=self.c+1, padx=1, pady=1, sticky=tk.E) fr.pack(side=tk.TOP) self.F10text.window_create(tk.INSERT,window=fr) self.F10text.insert(tk.INSERT,'\n\n') t=htdx.get_F10(self.stock,df.name[0]) self.F10text.insert(tk.INSERT,t)
def selectbk4(event): global tb6 ss=lba4.get(lba4.curselection()) df=g.bkdf[3] df=df[df.blockname==ss] df=df.reset_index(level=None, drop=True ,col_level=0, col_fill='') df['name']='' for i in range(len(df)): df.loc[i,'name']=g.names[(htdx.get_market(df.loc[i,'code']),df.loc[i,'code'])] df=df[['code_index','blockname','code','name']] df.rename(columns={'code_index':'序号', 'blockname':'板块名称',\ 'code':'代码','name':'名称'},\ inplace = True) tb6.clear() tb6.load_df(df) #把变量df的数据显示到表格中 tb6.brush() #用2种底色交替显示表格
def selectbk4(event): global bkv1, bkv2, bkv3, bkv4, bkv5, bkv6 import HP_tdx as htdx global tb6, usrbk, v2 ss = lba4.get(lba4.curselection()) df = g.bkdf[3] df = df[df.blockname == ss] df = df.reset_index(level=None, drop=True, col_level=0, col_fill='') df['name'] = '' mybk = [] usrbk = '' for i in range(len(df)): df.loc[i, 'name'] = g.names[(htdx.get_market(df.loc[i, 'code']), df.loc[i, 'code'])] mybk.append(df.loc[i, 'code'] + ' ' + df.loc[i, 'name']) usrbk += df.loc[i, 'code'] + ' ' bkv6.set(mybk) v2['text'] = "板块内股票(%d)" % len(df)
def F10b6(): item = tb6.tree.selection()[0] aa=tb6.tree.item(item, "values") bb=list(aa) g.stock=bb[2] g.vtitle=bb[3] stock.set(g.stock) g.gmarket=htdx.get_market(g.stock) try: filename= '../../../Downloads/xb2e/view/F10窗口.py' g.status.text(2,'查看'+bb[0]+' F10信息!') f = open(filename,'r',encoding='utf-8',errors='ignore') msg=f.read() f.close() exec(msg) except Exception as e: g.status.text(1,'') g.status.text(2,'用户代码出错:'+str(e)) tprint('用户代码出错:'+str(e)+'\n','red')
def selectbk5(event): global bkv1, bkv2, bkv3, bkv4, bkv5, bkv6 import HP_tdx as htdx global tb6, usrbk, v2 ss = lba5.get(lba5.curselection()) ss = ss.strip() file = r'bk/' + ss + '.csv' df = pd.read_csv(file, encoding='gbk') df.rename(columns={'code':'code2'},\ inplace = True) df['code'] = ['0' * (6 - len(x)) + x for x in df.code2.astype(str)] df = df.drop('code2', axis=1) df['name'] = '' mybk = [] usrbk = '' for i in range(len(df)): df.loc[i, 'name'] = g.names[(htdx.get_market(df.loc[i, 'code']), df.loc[i, 'code'])] mybk.append(df.loc[i, 'code'] + ' ' + df.loc[i, 'name']) usrbk += df.loc[i, 'code'] + ' ' bkv6.set(mybk) v2['text'] = "板块内股票(%d)" % len(df)
def get_security_bars(nCategory=4,nMarket =-1,code='000776',\ nStart=0, nCount=240): global tdxapi global Cw, Base2 global Mydf global Close, Low, High, Open, Vol, Amo global Vol global Period, Date, Time, Year, Month, Weekday, Day, Hour, Minute global Code, Market, Setcode, Name, Py global Mindiff, Tqflag, Useddatanum, Multiplier if nMarket < 0: nMarket = htdx.get_market(code) Code = code Setcode = Market = nMarket Period = nCategory Cw = readbase(Market, Code) Base2 = readbase2(Market, Code) result = htdx.tdxapi.get_security_bars(nCategory, nMarket, code, nStart, nCount) Mydf = htdx.tdxapi.to_df(result) Useddatanum = len(Mydf) Mydf['date'] = Mydf['datetime'] Mydf['volume'] = Mydf['vol'] Close = Mydf['close'] High = Mydf['high'] Open = Mydf['open'] Low = Mydf['low'] Vol = Mydf['volume'] Amo = Mydf['amount'] Date = Mydf['date'] Year = Mydf['year'] Month = Mydf['month'] Day = Mydf['day'] Hour = Mydf['hour'] Minute = Mydf['minute'] Time = Hour * 100 + Minute return Mydf
FigureCanvasTkAgg, NavigationToolbar2Tk) ##matplotlib 3.0.2 from matplotlib.backend_bases import key_press_handler from matplotlib.figure import Figure import math import HP_tdx as htdx import HP_lib as mylib from HP_sys import * import tkinter as tk import HP_global as g import HP_data as hp ds=g.hcdate_s.get() de=g.hcdate_e.get() stockn=g.hcstock.get() df2=htdx.get_k_data(stockn,ktype='D',start=ds,end=de,index=False,autype='qfq') df3=df2 ##数据规格化 df3.dropna(inplace=True) #df3.insert(0,'date',df3.index) #df3=df3.reset_index(level=None, drop=True ,col_level=0, col_fill='') df2=df3 ##双均线交易策略 df2=mylib.MA(df2,'close',5,'C5') #把5日均线存放到C5列中 df2=mylib.MA(df2,'close',20,'C20') #把20日均线存放到C20列中 df2=mylib.CROSS(df2,'C5','C20','B1') #把5日均线上穿20日均线,存放列B1,买入信号 df2=mylib.CROSS(df2,'C20','C5','S1') #把5日均线下穿20日均线,存放列S1,卖出信号 g.tabControl.select(g.tab5)
def main_init(): global tb,tb2,tb3,tb4,tb5,tb6 global mydf2,hq global svr_ip #行情服务ip global svr_port #行情服务端口 # logolabel.set('正在连接行情服务器...') hq=htdx.TdxInit(ip=svr_ip,port=svr_port) ##初始化通达信 sh1=get_shcode('指数板块') sh1=sh1.round(2) #改变符点数小数点后2位 tb.load_df(sh1) #把变量df的数据显示到表格中 tb.brush() #用2种底色交替显示表格 sh2=get_shcode('证券') sh2=sh2.round(2) #改变符点数小数点后2位 gp=sh2 tb2.load_df(sh2) #把变量df的数据显示到表格中 tb2.brush() #用2种底色交替显示表格 sz1=get_szcode('指数板块') sz1=sz1.round(2) #改变符点数小数点后2位 tb3.load_df(sz1) #把变量df的数据显示到表格中 tb3.brush() #用2种底色交替显示表格 sz2=get_szcode('证券') sz2=sz2.round(2) #改变符点数小数点后2位 gp=gp.append(sz2,ignore_index=True) tb4.load_df(sz2) #把变量df的数据显示到表格中 tb4.brush() #用2种底色交替显示表格 #print(gp) g.stock_names={} codes2=list(gp.code) names2=list(gp.name) i=0 for i in range(len(codes2)): g.stock_names.update({codes2[i]:names2[i]}) cd=get_szcode() cd2=get_shcode() cd=cd.append(cd2) cd=cd.reset_index(level=None, drop=True ,col_level=0, col_fill='') #cd.to_csv('./data/codes.csv' , encoding= 'gbk') cds={} for i in range(len(cd)): cds[(cd.market[i],cd.code[i])]=cd.name[i] g.names=cds df=htdx.get_hq2(g.zxg) df['zd']=df['price']-df['last_close'] #涨跌 df['zdf1']=df['zd']*100/df['last_close'] #涨跌幅 df['vol']=df['vol']/10000 df=df.round(2) #改变符点数小数点后2位 df['zdf']=df['zdf1'].astype(str)+'%' df['code2']=['0'*(6-len(x)) + x for x in df.code.astype(str)] df['name']='' for i in range(len(df)): df.loc[i,'name']=cds[(df.loc[i,'market'],df.loc[i,'code2'])] df.to_csv('./data/hq.csv' , encoding= 'gbk') df=df[['code','name','zdf','price','zd','bid1','ask1','vol',\ 'high','open','low','last_close','market']] df.rename(columns={'code':'代码', 'name':'名称','zdf':'涨幅',\ 'price':'现价','zd':'涨跌','bid1':'买价',\ 'ask1':'卖价','vol':'总量(万)','open':'今开',\ 'high':'最高','low':'最低','last_close':'昨收'},\ inplace = True) tb5 = htk.Table(mytab5) #创建表格控件 tb5.pack(expand = 1, fill = tk.BOTH) tb5.load_df(df) #把变量df的数据显示到表格中 tb5.brush() #用2种底色交替显示表格 bk=htdx.get_block2("block.dat") g.bkdf.append(bk) bk2=list(bk['blockname']) bk3=set(bk2) bk2=list(bk3) g.blockname.append(bk2) bkv1.set(bk2) bk=htdx.get_block2("block_zs.dat") g.bkdf.append(bk) bk2=list(bk['blockname']) bk3=set(bk2) bk2=list(bk3) g.blockname.append(bk2) bkv2.set(bk2) bk=htdx.get_block2("block_fg.dat") g.bkdf.append(bk) bk2=list(bk['blockname']) bk3=set(bk2) bk2=list(bk3) g.blockname.append(bk2) bkv3.set(bk2) bk=htdx.get_block2("block_gn.dat") g.bkdf.append(bk) bk2=list(bk['blockname']) bk3=set(bk2) bk2=list(bk3) g.blockname.append(bk2) bkv4.set(bk2)
stockn=stockn.zfill(6) g.stock_i.set(stockn) g.stock=stockn st=g.stock st2=st if int(time.strftime('%H%M',time.localtime(time.time())))<=930: ds=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60))+' 09:30:00' de=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60))+' 15:00:00' else: ds=time.strftime('%Y-%m-%d',time.localtime(time.time()))+' 09:30:00' de=time.strftime('%Y-%m-%d',time.localtime(time.time()))+' 15:00:00' #if g.login: df2b=htdx.get_security_bars(7,code=st) a=[x[0:10] for x in df2b.date] df2b['date2']=a df2b=df2b[df2b.date2==de2] df2b=df2b.reset_index(level=None, drop=True ,col_level=0, col_fill='') df2b.to_csv('temp/day01.csv' , encoding= 'gbk') #else: # #print('读本地数据!') # df2b=pd.read_csv('temp/day01.csv' , encoding= 'gbk') # st2=st xxx=view2c(g.tab6) axview3x_m(xxx.v[0],df2b,g.stock+' '+g.stock_names[g.stock]+' 分时图',6) xxx2=view2d(xxx.v[1])
l2, l3 = l[i] s = s + chr(10) + str(l2) + l3 return s def putzxgfile(l, file='ZXG2.blk'): f = open(file, 'w') s = putzxg(l) f.write(s) f.close() return s #测试 if __name__ == '__main__': tdxapi = htdx.TdxInit(ip='180.153.18.171') df = get_security_bars() print(df) # df=get_security_bars() # print(df) # print(df.columns) # now = dt.datetime.now() # print( MACHINETIME()) # x=readbase2() # x=WINNER(C) print(CW()) ################独狼荷蒲软件版权声明################### ''' 独狼荷蒲软件(或通通软件)版权声明 1、独狼荷蒲软件(或通通软件)均为软件作者设计,或开源软件改进而来,仅供学习和研究使用,不得用于任何商业用途。
import pandas as pd import numpy as np import HP_global as g import HP_data as hp from HP_view import * #菜单栏对应的各个子页面 import HP_tdx as htdx ''' 查询公司信息目录 name filename start length 0 最新提示 000776.txt 0 13477 1 公司概况 000776.txt 13477 18703 2 财务分析 000776.txt 32180 28283 3 股东研究 000776.txt 60463 16935 4 股本结构 000776.txt 77398 3437 5 资本运作 000776.txt 80835 18565 6 业内点评 000776.txt 99400 34554 7 行业分析 000776.txt 133954 38922 8 公司大事 000776.txt 172876 63519 9 港澳特色 000776.txt 236395 17899 10 经营分析 000776.txt 254294 20236 11 主力追踪 000776.txt 274530 14745 12 分红扩股 000776.txt 289275 139365 13 高层治理 000776.txt 428640 36667 14 龙虎榜单 000776.txt 600079 7961 15 关联个股 000776.txt 465307 134772 ''' txt=htdx.get_F10(g.mstock,'股东研究') tprint(txt)
#控件结构 g.G_root -〉 g.tabControl -〉g.tab1 #增加tab,用add() #删除tab,用forget() #当然用户可以设置更多的tab窗口。必须使用全局变量g.变量名 #重复建立新tab窗会出错,所以我们先检测是否None,不是就先做删除旧tab窗口。 g.gtype = g.book_s.get() stockn = g.stock_i.get() stockn = stockn.strip() stockn = stockn.zfill(6) g.stock_i.set(stockn) g.stock = stockn ds = g.date_s.get() de = g.date_e.get() g.sday = ds.strip() g.eday = de.strip() df2=htdx.get_k_data(g.stock,ktype='D',start=g.sday,\ end=g.eday,index=False,autype='qfq') if g.tab3 != None: g.tabControl.forget(g.tab3) g.tab3 = None #用户自建新画面 g.tab3 = tk.Frame(g.tabControl) g.tabControl.add(g.tab3, text='日线图') g.tabControl.select(g.tab3) axview3x(g.tab3, df2, t=g.stock + ' ' + g.stock_names[g.stock], n=2, f1='VOL', f2=g.gtype) g.tabControl.select(g.tab3)
def jsfx(): ds='2018-01-01' #行情开始日期 de=time.strftime('%Y-%m-%d',time.localtime(time.time())) #行情结束日期 df2a=htdx.get_k_data2(g.stock,ds,de) # 三指标图 hpv.axview3x(tab3,df2a,g.stock+' '+g.stock_names[g.stock])
import HP_global as g #建立全局数据域g import HP_tdx as htdx #导入通达信模块 #返回板块中所有股票 tdxapi=htdx.TdxInit() bk=htdx.getblock2('沪深300') print(bk) #获取股票所属板块名 bk2=htdx.getblock3('600030') print(bk2)
from PIL import Image, ImageTk, ImageDraw, ImageFont import sys sys.path.append("..") import HP_tk as htk #导入ht import HP_tdx as htdx import HP_global as g if g.tab7!=None: g.tabControl.forget(g.tab7) g.tab7=None #用户自建新画面 g.tab7 = tk.Frame(g.tabControl) g.tabControl.add(g.tab7, text='F10信息') mk=htdx.get_market(g.stock) class UserF10(tk.Frame): # 继承Frame类 def __init__(self, master=None,stock=''): tk.Frame.__init__(self, master) self.stock=stock if self.stock=='': self.stock=g.stock self.root = master #定义内部变量root self.button2=None self.r=1 self.c=8 self.b=[] self.F10text=scrolledtext.ScrolledText(self,undo=True,bg='#FFF8DC') self.F10text.pack(side=tk.TOP, fill=tk.BOTH, expand=1,ipady=1,pady=1,ipadx=1,padx=1) self.init()
g.tabControl.select(g.tab8) #把window划分4个子容器,在不同子容器中显示不同股票K线图 xxx = view4(g.tab8) g.gtype = g.book_s.get() stockn = g.stock_i.get() stockn = stockn.strip() stockn = stockn.zfill(6) g.stock_i.set(stockn) g.stock = stockn ds = g.date_s.get() de = g.date_e.get() g.sday = ds.strip() g.eday = de.strip() df2=htdx.get_k_data(g.stock,ktype='D',start=g.sday,\ end=g.eday,index=False,autype='qfq') ds = g.mds de2 = time.strftime('%Y-%m-%d', time.localtime(time.time())) de = time.strftime('%Y-%m-%d', time.localtime(time.time())) + ' 15:01:00' g.mde = de st = g.stock #nCategory -> K 线种类 #0 5 分钟K 线 #1 15 分钟K 线 #2 30 分钟K 线 #3 1 小时K 线 #4 日K 线 #5 周K 线
# ##读取股票数据 #df2a=htdx.get_k_data('000001',ktype='D',start=ds,end=de,index=False,autype='qfq') #df2b=htdx.get_k_data('000001',ktype='D',start=ds,end=de,index=False,autype='qfq') #df2c=htdx.get_k_data('600030',ktype='D',start=ds,end=de,index=False,autype='qfq') g.gtype = g.book_s.get() stockn = g.stock_i.get() stockn = stockn.strip() stockn = stockn.zfill(6) g.stock_i.set(stockn) g.stock = stockn ds = g.date_s.get() de = g.date_e.get() g.sday = ds.strip() g.eday = de.strip() df2=htdx.get_k_data(g.stock,ktype='D',start=g.sday,\ end=g.eday,index=False,autype='qfq') ds = g.mds de2 = time.strftime('%Y-%m-%d', time.localtime(time.time())) de = time.strftime('%Y-%m-%d', time.localtime(time.time())) + ' 15:01:00' g.mde = de stockn = g.stock_i.get() stockn = stockn.strip() stockn = stockn.zfill(6) g.stock_i.set(stockn) g.stock = stockn st = g.stock st2 = st if int(time.strftime('%H%M', time.localtime(time.time()))) <= 930:
listvariable=bkv6) lba6.pack(expand=tk.YES, fill=tk.BOTH, padx=5, pady=5) scrollbara6.config(command=lba6.yview) bkv7 = tk.StringVar() scrollbara7 = tk.Scrollbar(v4) scrollbara7.pack(side=tk.RIGHT, fill=tk.Y) lba7 = tk.Listbox(v4, selectmode=tk.BROWSE, yscrollcommand=scrollbara7.set, font='Helvetica %d' % fsize, listvariable=bkv7) lba7.pack(expand=tk.YES, fill=tk.BOTH, padx=5, pady=5) scrollbara7.config(command=lba7.yview) bk = htdx.get_block2("block.dat") g.bkdf.append(bk) bk2 = list(bk['blockname']) bk3 = set(bk2) bk2 = list(bk3) g.blockname.append(bk2) bkv1.set(bk2) bk = htdx.get_block2("block_zs.dat") g.bkdf.append(bk) bk2 = list(bk['blockname']) bk3 = set(bk2) bk2 = list(bk3) g.blockname.append(bk2) bkv2.set(bk2) bk = htdx.get_block2("block_fg.dat") g.bkdf.append(bk)