通达信接口

https://rainx.gitbooks.io/pytdx/content/pytdx_pool.html

https://www.55188.com/viewthread.php?tid=8597268&page=1#pid153249932

https://github.com/rainx/pytdx/issues/3

https://www.myquant.cn/docs/data/data_stock_payout
https://uqer.io/data/search/分红

import struct,time,re
path = r'/media/debian9/New Volume/dzh/Download/PWR/'
name = ['full_sh.PWR','full_sz.PWR']
data = []
for i in name:
    exFile = open(path+i,'rb')
    exFile.seek(8)
    while True:
        exContent = exFile.read(120)
        if not exContent:
            break
        if exContent[:4] == b'\xff\xff\xff\xff':
            code = exContent[4:12].decode('gbk')
        elif len(exContent) > 0:
            date= struct.unpack("I", exContent[:4])[0]
            date= time.localtime(date)
            exlist = exContent[20:].decode('gbk').split('\x00')[0][2:].split()
            present = 0
            bonus = 0
            rationed = 0
            price = 0
            for i in exlist:
                if '送' in i:
                    present += float(re.findall(r"\d+\.?\d*",i)[0])
                if '增' in i:
                    present += float(re.findall(r"\d+\.?\d*",i)[0])
                if '派' in i:
                    bonus += float(re.findall(r"\d+\.?\d*",i)[0])
                if '价' in i:
                    price += float(re.findall(r"\d+\.?\d*",i)[0])
                if '配' in i:
                    rationed += float(re.findall(r"\d+\.?\d*",i)[0]) - price
            data.append({'code':code[2:],'date':date,'present':present,'bonus':bonus,'price':price,'rationed':rationed})

你可能感兴趣的:(通达信接口)