通达信数据格式-画线数据格式line.dat

Published

一、新版通达信tdxline.dat数据格式

1、新版通达信tdxline.dat导出数据样本

通达信主图加标注D:\Thirdprogram\国泰君安锐智版\T0002\tdxLine.dat文件结构 说明

版本:国泰君安期权v9.35

SZ300007 汉威科技	STANDK(K线)	日线	矩形	定位1:值:15.74/时:20191008;定位2:值:12.75/时:20191018;	
SH600929 湖南盐业	STANDK(K线)	日线	矩形	定位1:值:8.77/时:20190814;定位2:值:5.62/时:20191018;	
SH600929 湖南盐业	STANDK(K线)	日线	箭头	定位1:值:10.52/时:20190826;定位2:值:9.22/时:20190827;	
SH600929 湖南盐业	STANDK(K线)	日线	文字注释	参考300006	
SH600250 南纺股份	STANDK(K线)	日线	矩形	定位1:值:7.95/时:20180622;定位2:值:4.55/时:20181029;	
SZ000557 西部创业	STANDK(K线)	日线	矩形	定位1:值:3.98/时:20190709;定位2:值:2.98/时:20191021;	
SZ000557 西部创业	STANDK(K线)	日线	箭头	定位1:值:4.15/时:20190726;定位2:值:4.02/时:20190725;	
SZ000557 西部创业	STANDK(K线)	日线	文字注释	参考600250、300562,600887走势	

 2.

如下命令格式可以将多个二进制文件合并为一个二进制文件:

copy  /b  file1+file2+...+fileN  DestFile

3.文件格式

没有文件头,378个字节/记录,循序存放

002960 2019/12/13 箭头

只有1个箭头的记录如下:

00000000h: 00 30 30 32 39 36 30 00 00 00 00 00 00 00 00 00 ; .002960.........
00000010h: 00 00 00 00 00 00 00 00 02 53 54 41 4E 44 4B 00 ; .........STANDK.
00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000050h: 00 00 00 00 00 00 23 2B E4 41 50 17 DB 41 00 00 ; ......#+銩P.跘..
00000060h: 00 00 00 04 00 21 10 00 00 F7 17 34 01 1E 2B E4 ; .....!...?4..+?
00000070h: 41 00 00 00 00 F7 17 34 01 4B 17 DB 41 00 00 00 ; A....?4.K.跘...
00000080h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000090h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000a0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000b0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000c0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 ; ................
000000d0h: 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 ; ..............
000000e0h: 00 00 00 00 00 F7 17 34 01 01 00 00 00 00 00 00 ; .....?4........
000000f0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000100h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000110h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000120h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000130h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000140h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000150h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000160h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000170h: 00 00 00 00 00 00 00 00 00 00                   ; ..........

如果删除箭头,则删除对应的记录数据块

 

002960 2019/12/13 文字:test

00000000h: 00 30 30 32 39 36 30 00 00 00 00 00 00 00 00 00 ; .002960.........
00000010h: 00 00 00 00 00 00 00 00 02 53 54 41 4E 44 4B 00 ; .........STANDK.
00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000050h: 00 00 00 00 00 00 93 B7 DB 41 00 00 00 00 00 00 ; ......摲跘......
00000060h: 00 00 00 04 00 16 10 00 00 F7 17 34 01 8E B7 DB ; .........?4.幏?
00000070h: 41 00 00 00 00 74 65 73 74 00 00 00 00 00 00 00 ; A....test.......
00000080h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000090h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000a0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000b0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000c0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 ; ................
000000d0h: 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 ; ..............
000000e0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000f0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000100h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000110h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000120h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000130h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000140h: 00 00 00 00 00 00 00 00 00 00 00 00 00 F7 17 34 ; .............?4
00000150h: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000160h: 01 01 00 00 00 00 00 00 00 00 00 00 00 08 00 00 ; ................
00000170h: 00 FF FF 00 00 18 00 00 00 00                   ; ........

 

002960 2019/12/20-2019/12/13 矩形框

00000000h: 00 30 30 32 39 36 30 00 00 00 00 00 00 00 00 00 ; .002960.........
00000010h: 00 00 00 00 00 00 00 00 02 53 54 41 4E 44 4B 00 ; .........STANDK.
00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000050h: 00 00 00 00 00 00 E5 D8 DE 41 B8 70 CB 41 01 00 ; ......遑轆竝薃..
00000060h: 00 00 00 04 00 17 10 00 00 F4 17 34 01 E5 D8 DE ; .........?4.遑?
00000070h: 41 00 00 00 00 F7 17 34 01 B3 70 CB 41 00 00 00 ; A....?4.硃薃...
00000080h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000090h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000a0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000b0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000c0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 ; ................
000000d0h: 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 ; ..............
000000e0h: 00 00 00 00 00 F7 17 34 01 01 00 00 00 00 00 00 ; .....?4........
000000f0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000100h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000110h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000120h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000130h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000140h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000150h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000160h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
00000170h: 00 00 00 00 00 00 00 00 00 00                   ; ..........

二、老版通达信结构描述定义:

https://github.com/bluegrunt/pytdx/blob/53ef358e585b2af9edd494993c979f6f9dfdf787/tdx_const.py

java

/**
	 * 读取通达信line.bat文件 文件格式: 一个记录的长度是298个字节 1、第一个字节是00,表示深圳;01表示上海
	 * 2、下面6个字节,股票代码。 3、ascii码下面2个字节,占位符 4、下面6个字节standk,标准k线或其他技术指标(猜的)
	 * 5、下面4个字节占位符 6、下面一个字节,周期类型, 298个字节
	 * 7、对于价格通道来讲,第25字节到第28字节,日期;第37字节到第40字节,日期;第45字节到第48字节,日期;
	 * 第29字节到第32字节,价格;第41字节到第44字节,价格;第85字节到第88字节,价格;
	 * 8、第21个字节一般为41,不知道什么意思,22字节为line的类型(直线07、线段06、射线30、平行线25),没有这两个字节显示不出来
	 * 
	 * @param fileName
	 */
	public static void readFileByBytes_linedat(String fileName) {

		InputStream in = null;
		byte[] bytesInOneRecord = new byte[298];
		byte[] dateBytesOne = new byte[4];
		byte[] dateBytesTwo = new byte[4];
		byte[] PriceBytesOne = new byte[4];
		byte[] PriceBytesTwo = new byte[4];

		byte[] marketName = new byte[1];
		byte[] stockIdBytes = new byte[6];
		byte[] indicatortype = new byte[6];
		byte[] periodName = new byte[1];

		byte[] other1 = new byte[2]; //划线类型
		
		byte[] other2 = new byte[2];//平行线信息
		byte[] other3 = new byte[2];//平行线信息
		byte[] other4 = new byte[3];//平行线信息

		try {
			in = new FileInputStream(fileName);

			int count = 0;

			int bytesRead = 0;
			int totalBytesRead = 0;

			while ((bytesRead = in.read(bytesInOneRecord)) != -1) {
				++count;
				totalBytesRead += bytesRead;

				System.arraycopy(bytesInOneRecord, 0, marketName, 0, 1);
				System.arraycopy(bytesInOneRecord, 1, stockIdBytes, 0, 6);
				System.arraycopy(bytesInOneRecord, 9, indicatortype, 0, 6);
				System.arraycopy(bytesInOneRecord, 19, periodName, 0, 1);

				// other1
				System.arraycopy(bytesInOneRecord, 21, other1, 0, 2);

				System.arraycopy(bytesInOneRecord, 25, dateBytesOne, 0, 4);
				System.arraycopy(bytesInOneRecord, 29, PriceBytesOne, 0, 4);
				System.arraycopy(bytesInOneRecord, 37, dateBytesTwo, 0, 4);
				System.arraycopy(bytesInOneRecord, 41, PriceBytesTwo, 0, 4);
				
				//other2
				System.arraycopy(bytesInOneRecord, 84, other2, 0, 2);
				System.arraycopy(bytesInOneRecord, 84, other4, 0, 3);
				System.arraycopy(bytesInOneRecord, 86, other3, 0, 2);
				
				String marketNameStr = "";
				int marketInt = bytesToInt(marketName);
				if (marketInt == 0) {
					marketNameStr = "深圳市场";
				} else {
					marketNameStr = "上海市场";
				}
				System.out.print("所在交易所 \t " + marketNameStr + "\t");
				String stockIdStr = (new String(stockIdBytes)).trim();
				System.out.print("股票代码 \t " + stockIdStr + "\t");

				String indicatortypeStr = (new String(indicatortype)).trim();
				System.out.print("主图名称 \t " + indicatortypeStr + "\t");
				int periodInt = bytesToInt(periodName);
				int[] intTwo = new int[2];
				if (periodInt < 4) {
					intTwo = BytesOf4To2Int(dateBytesOne);
					System.out.print("月份\t" + (intTwo[0] / 100) + "日期\t"
							+ (intTwo[0] % 100) + "\t" + (intTwo[1] / 60)
							+ "时\t" + (intTwo[1] % 60) + "分钟 \t ");
					System.out.print("日期\t" + intTwo[0] + "\t" + "时间\t"
							+ intTwo[1] + "\t");
					intTwo = BytesOf4To2Int(dateBytesTwo);
					System.out.print("月份\t" + (intTwo[0] / 100) + "日期\t"
							+ (intTwo[0] % 100) + "\t" + (intTwo[1] / 60)
							+ "时\t" + (intTwo[1] % 60) + "分钟 \t ");

				}
				System.out.print("周期名称 \t " + periodInt + "\t");
				System.out.print("日期之一\t" + bytesToInt(dateBytesOne) + "\t");
				System.out
						.print("价格之一\t"
								+ (float) (Math
										.round(Float
												.intBitsToFloat(bytesToInt(PriceBytesOne)) * 100))
								/ 100 + "\t");
				System.out.print("日期之二\t" + bytesToInt(dateBytesTwo) + "\t");
				System.out
						.println("价格之二\t"
								+ (float) (Math
										.round(Float
												.intBitsToFloat(bytesToInt(PriceBytesTwo)) * 100))
								/ 100);

				System.out.println("other1......" + bytesToInt(other1));
				System.out.println("other2......" + bytesToInt(other2)+" "+ bytesToInt(dateBytesOne));
				System.out.println("other3......" + bytesToInt(other3)+" "+ bytesToInt(dateBytesOne));
				System.out.println("other4......" + bytesToInt(other4)+" "+ bytesToInt(dateBytesOne));
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
					in = null;
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		}
	}