Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WMJi/f5fe3083961d26fbfbcc to your computer and use it in GitHub Desktop.
Save WMJi/f5fe3083961d26fbfbcc to your computer and use it in GitHub Desktop.
from struct import *
ofile=open('sz000680.day','rb')
buf=ofile.read()
ofile.close()
ifile=open('sz000680.txt','w')
num=len(buf)
no=num/32
b=0
e=32
line=''
for i in xrange(no):
a=unpack('IIIIIfII',buf[b:e])
line=str(a[0])+' '+str(a[1]/100.0)+' '+str(a[2]/100.0)+' '+str(a[3]/100.0)+' '+str(a[4]/100.0)+' '+str(a[5]/10.0)+' '+str(a[6])+' '+str(a[7])+' '+'\n'
print line
ifile.write(line)
b=b+32
e=e+32
ifile.close()
将文件保存为: tdx.py
然后再到通达信文件路径下:c:\tdx\Vipdoc\sz\lday将所要下载的股票代码COPY到当前路径下与tdx.py文件在同一路径下。
最后,运行:python tdx.py 即可在当前路径下生成TXT格式的数据文件。
--------------------------
一、通达信日线*.day文件
文件名即股票代码
每32个字节为一天数据
每4个字节为一个字段,每个字段内低字节在前
00 ~ 03 字节:年月日, 整型
04 ~ 07 字节:开盘价*100, 整型
08 ~ 11 字节:最高价*100, 整型
12 ~ 15 字节:最低价*100, 整型
16 ~ 19 字节:收盘价*100, 整型
20 ~ 23 字节:成交额(元),float型
24 ~ 27 字节:成交量(股),整型
28 ~ 31 字节:上日收盘*100, 整型
二、通达信5分钟线*.5文件
文件名即股票代码
每32个字节为一个5分钟数据,每字段内低字节在前
00 ~ 01 字节:日期,整型,设其值为num,则日期计算方法为:
year=floor(num/2048)+2004;
month=floor(mod(num,2048)/100);
day=mod(mod(num,2048),100);
02 ~ 03 字节: 从0点开始至目前的分钟数,整型
04 ~ 07 字节:开盘价*100,整型
08 ~ 11 字节:最高价*100,整型
12 ~ 15 字节:最低价*100,整型
16 ~ 19 字节:收盘价*100,整型
20 ~ 23 字节:成交额*100,float型
24 ~ 27 字节:成交量(股),整型
28 ~ 31 字节:(保留)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment