Read China Stock History Data Of Tdx With Python

download history data of tdx

select menu "download history data (day)" from tdx

find the data form disk

open windows explorer find *.day and we will find the data files are stored under the following folder in Windows 7 OS.

C:\Users\userabc\AppData\Local\VirtualStore\Program Files (x86)\CiticCs\new_zx_sum\vipdoc\sz\lday

C:>cd C:\Users\userabc\AppData\Local\VirtualStore\Program Files (x86)\CiticCs\new_zx_sum\vipdoc\sz\lday 
C:>dir

2013/02/20  10:36    <DIR>          .
2013/02/20  10:36    <DIR>          ..
2013/02/20  10:34               896 sz000001.day
...

check data struct with python

run python interpreter

C:>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> f=open('sz000001.day','rb')
# date
>>> struct.unpack('l',d[0:4])
(20130104,)
#open price (rmb * 100)
>>> struct.unpack('l',d[4:8])
(1632,)
#day's high (rmb * 100)
>>> struct.unpack('l',d[8:12])
(1645,)
#day's low (rmb * 100)
>>> struct.unpack('l',d[12:16])
(1592,)
#close price (rmb * 100)
>>> struct.unpack('l',d[16:20])
(1599,)
#volumn amount (rmb)
>>> struct.unpack('f',d[20:24])
(717567552.0,)
#volumn ( * 100)
>>> struct.unpack('l',d[24:28])
(44385137,)
#record flag
>>> struct.unpack('l',d[28:32])
(65536,)
#next record
>>> struct.unpack('l',d[32:36])
(20130107,)

Reference:
http://tech.cncms.com/ruanjian/office/excel/11121.html
http://syue.com/edu/Office/Excel/11338.html

http://oracle-abc.wikidot.com/vbs-china-stock-exchange-data-loader