Do your own quantitative trading software (21) Read and write program of Tongdaxin self-selected stock files

Do your own quantitative trading software (21) Read and write program of Tongdaxin self-selected stock files

I have done the conversion program of the self-selected stock files and sector data of various stock software before, see the figure below.
Insert picture description here
This article introduces how to use Python to read and write the optional stock file of Tongdaxin Software.
We can use Tongdaxin software in conjunction with the quantification program.
1. We use the quantitative program to select the stock pool after the market and store it in the self-selected stock section of Tongdaxin Software for monitoring.
2. We use Tongdaxin software to select self-selected stocks. Use Python to implement intra-disk monitoring and automatic order placement.
The catalog of the optional
stock file of Tongdaxin Software is: C:\tdx\T0002\blocknew The optional stock file name is:'ZXG.blk'.
Use the shortcut command number '06' and press Enter in the Tongdaxin software, and a list of self-selected stocks will appear. The name of the optional stock file is:'ZXG.blk'.
In Tongdaxin software, the stock code format is: (market, code)
such as: Shenzhen index (0, '399001'), Shanghai market (1, '999999').
The data is stored in 8 bytes in'ZXG.blk'.
Shenzhen Index (0, '399001'), the storage format is chr(10)+'0399001'.
Shanghai market (1, '999999'), the storage format is chr(10)+'1999999'.
So we can easily write python code.
The picture below is a list of Tongdaxin self-selected stocks.
Insert picture description here
The program code is given below:

#自选股数据转通达信股票列表
def getzxg(z):
    z2=z.split(chr(10))
    l=[]
    for i in range(1,len(z2)):
        z3=z2[i]
        l.append((int(z3[0:1]),z3[1:9]))
    return l

def getzxgfile(file='ZXG.blk'):
    f = open(file,'r')
    z=f.read()
    f.close()
    return getzxg(z)

#通达信股票列表转自选股数据转
def putzxg(l):
    s=''
    for i in range(len(l)):
        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__':
    zxg=getzxgfile('ZXG.blk')
    print(zxg)
    putzxgfile(zxg,'ZXG2.blk')
    zxg3=getzxgfile('ZXG2.blk')
    print(zxg3)

Program running results:

[(1, '600519'), (0, '399001'), (1, '999999'), (1, '600030'), (0, '000776')]
[(1, '600519'), (0, '399001'), (1, '999999'), (1, '600030'), (0, '000776')]

#独狼荷蒲qq:2775205
#通通小白python Quantitative Group: 524949939
#电话微信:18578755056 #WeChat
public account: Lonewolf stock analysis

Guess you like

Origin blog.csdn.net/hepu8/article/details/106425443