首页 > 学院 > 开发设计 > 正文

[python]沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上

2019-11-14 16:58:47
字体:
来源:转载
供稿:网友

将沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上

原理:python读取前一次处理完的计算5日后涨跌幅输出的csv文件

文件名前加"[paint]"

安照通达信的画图文件和板块文件格式,输出文件

用通达信的导入功能,导入画图文件和板块文件即可

事前数据截图:

处理后所得文件:

导入通达信后板块截图:

k线截图:

代码:

  1 #coding=utf-8  2   3 #读取'[paint]'开头的csv文件  4 #copyright @ WangXinsheng  5 #http://www.VEVb.com/wangxinsheng/  6 import os  7 import struct  8 import time  9 import datetime 10  11 def getPRiceByte(infile,arg,code,ss,day): 12     dirc = {"-5":-3,"-3":-2,"-1":-1,"1":1,"3":2,"5":3,"7":4,"9":5,"11":6} 13     first = 0 14     second = 0 15     a = float(arg) 16     for i in [-5,-3,-1,1,3,5,7,9,11]: 17         ib = i - 2 18         if(a>=2**ib and a<2**i): 19             #print(str(a)+":["+str(2**ib)+","+str(2**i)+"]"+"i:"+str(i)+" ib:"+str(ib)) 20             first = ib 21             break; 22     #print(first) 23     chushu = 2**first 24     if(arg >= chushu*2): 25         second = arg / chushu 26         #print(second) 27         second = int(second*64) 28     else: 29         second = arg / chushu -1 30         #print(second) 31         second = int(second*128) 32      33     if(first<0): 34         first = 64 + dirc[str(first)] 35     else: 36         first = 63 + dirc[str(first)] 37     ''' 38     print(first) 39     print(second) 40     print(struct.pack('B',first)) 41     print(struct.pack('B',second)) 42     ''' 43     #print(struct.pack('B',first)) 44     #print(struct.pack('B',second)) 45  46     infile.write(struct.pack('B',ss)) 47     infile.write(code.encode()) 48     infile.write(b'/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00') 49     infile.write(b'/x03') 50     infile.write('STANDK'.encode()) 51     infile.write(b'/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00') 52     infile.write(b'/x04') 53     infile.write(b'/x00') 54     infile.write(b'/x1a/x10/x00/x00') 55     infile.write(struct.pack('i',int(day))) 56     infile.write(b'/x00/x00') 57     infile.write(struct.pack('B',second)) 58     infile.write(struct.pack('B',first)) 59     infile.write(b'/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/xdcz3/x01/x01/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00') 60  61     print(str(code)+':已在 '+day+"日,价格:"+str(arg)+"加入标记") 62 #infile = open("tdxline.eld","rw") 63 #getPriceByte(5.55) 64 file = open("WXSline.eld","wb") 65 zxg = '' 66 path=r'.' 67 files = os.listdir(path) 68 files.sort() 69 j=0 70 for f in files: 71     if(f.startswith('[paint]') and f.endswith('.csv')): 72         print('读取文件:'+path+'/'+f) 73          74         f=open(path+'/'+f,'rt') 75         infos = f.readlines() 76         f.close() 77         i=0 78         for info in infos: 79             if(i==0): 80                 i=i+1 81                 continue 82             tmp = info.split(',')             83             if(len(tmp)<2): 84                 continue 85             code = str(tmp[1].replace('"','').replace("'","")) 86             if(code.startswith('6')): 87                 ss = 1 88             else: 89                 ss = 0 90             addzxg = '' 91             try: 92                 zxg.index(str(ss)+code) 93             except: 94                 addzxg = str(ss)+code+"/n" 95                  96             if(addzxg!=''): 97                 zxg = zxg + str(ss)+code+"/n"             98             if(len(tmp)<10): 99                 continue100 101             days = tmp[0].split('-')102             if(len(days)<2):103                 days = tmp[0].split('/')104                 105             if(len(days)<2):106                 continue107             108             if(len(days[1])<2):109                 days[1] = '0'+days[1]110             if(len(days[2])<2):111                 days[2] = '0'+days[2]112             day = days[0]+days[1]+days[2]113             #print(day)114             115             priceArr = tmp[9].replace('"','').split('%')116             if(len(priceArr)<2):117                 continue118             a = float(priceArr[1].replace('[','').replace(']',''))*(1-float(priceArr[0].replace('%',''))/100)119             a = round(a,2)120             code = str(tmp[1].replace('"','').replace("'",""))121             if(code.startswith('6')):122                 ss = 1123             else:124                 ss = 0125             126             getPriceByte(file,a,code,ss,day)127             '''128             if(j>3):129                 break130             else:131                 j=j+1132             '''133                 134 fileA = open("WXS条件股.ebk","w")135 fileA.write(zxg)136 fileA.close()137 file.close()138 print('处理完了/n画图文件地址:./WXSline.eld')139 print('/n板块文件地址:./WXS条件股.ebk')

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表