Free access to Tongdaxin K-line data

Tongdaxin Software officially provides free daily, 5-minute, and 1-minute K-line data downloads for Shanghai, Shenzhen, and Beijing. It also provides data downloads for the day after the market opens every day. The data update time is also very fast. For those who want to obtain reliable data for investment for free. is a good choice

data download

The steps to download Tongdaxin data for free are as follows:

  • First, download the Tongdaxin financial terminal software from the Tongdaxin official website
  • After downloading, install it in the default path C:\new_tdx
  • After installation, open it, click on the menu bar: Options --> After-hours data download, and the following panel will pop up:
  • Check the daily and real-time market data, select the data in the corresponding time range that needs to be downloaded, click to start downloading, and the data will be saved locally. The Shanghai Stock Exchange data will be downloaded to C:\new_tdx\vipdoc\sh\lday\sh000009.day, and the Shenzhen Stock Exchange data will be downloaded to C:\new_tdx\vipdoc\sz\lday\sz000009.day. Note that C:\new_tdx\ is the installation path. If it is not the default path, it needs to be replaced.

data analysis

The day file downloaded through Tongdaxin is a binary file, which can be parsed manually or using the lib library. The following are introduced respectively:

  • Manual parsing
def day2csv(source_dir, file_name, target_dir):
    # 以二进制方式打开源文件
    source_file = open(source_dir + os.sep + file_name, 'rb')
    buf = source_file.read()
    source_file.close()

    # 打开目标文件
    target_file = open(target_dir + os.sep + file_name[: file_name.rindex('.')] + '.csv', 'w')
    buf_size = len(buf)
    rec_count = int(buf_size / 32)
    begin = 0
    end = 32
    header = str('date') + ',' + str('open') + ',' + str('high') + ',' + str('low') + ',' \
             + str('close') + ',' + str('amount') + ',' + str('volume') + '\n'
    target_file.write(header)
    for i in range(rec_count):
        a = unpack('IIIIIfII', buf[begin:end])
        # 处理date数据
        year = a[0] // 10000
        month = (a[0] % 10000) // 100
        day = (a[0] % 10000) % 100
        date = '{}-{:02d}-{:02d}'.format(year, month, day)

        line = date + ',' + str(a[1] / 100.0) + ',' + str(a[2] / 100.0) + ',' \
               + str(a[3] / 100.0) + ',' + str(a[4] / 100.0) + ',' + str(a[5]) + ',' \
               + str(a[6]) + '\n'
        target_file.write(line)
        begin += 32
        end += 32
    target_file.close()
  • Use mootdx to parse

You need to install the mootdx library, use pip install -U mootdx to install it

from mootdx.reader import Reader

reader = Reader.factory(market='std', tdxdir='C:/new_tdx')

# 读取日线数据
reader.daily(symbol='600036')

# 读取1分钟数据
reader.minute(symbol='600036')

Due to limited space, only sample code is given above. For more complete code, you can follow the public account "Zhuge Shuo Talk" and join the group for communication.

Summary & communication

If you are interested in downloading and using Tongdaxin data or stock investment, please follow the official account and reply "Join the group" to get an invitation to join the A-share exchange group. The number of places is limited, so don't miss it.

Writing articles is not easy. If you think this article is helpful to you, please like and forward it to give me the motivation to keep writing good articles.

reference

Guess you like

Origin blog.csdn.net/richardzhutalk/article/details/130188349