通达信V6.1分时数据文件格式分析
通達信V6分時數據文件格式分析
文件位置
/jcb_zxjt/T0002/zst_cache/ sz399005.zst
說明:只有在瀏覽歷史分時圖時才生成相應文件。
?
/jcb_zxjt/T0002/hq_cache/sh.tfz
/jcb_zxjt/T0002/hq_cache/sz.tfz
說明:通達信當日分時數據, 包括所有瀏覽過的股票
?
?
數據格式
1、歷史分時數據格式
(1)、日期信息格式
| 數據含義 | 數據類型 |
| 日期 | Integer |
| 昨日收盤價 | single |
(2)、分時數據格式
| 數據含義 | 數據類型 | 備注 |
| 時間 | word | 如570/60=9.5,即9:30分 |
| 現價 | single | ? |
| 均價 | single | ? |
| 成交量 | Integer | ? |
| 預留 | ? | 12個字節 |
注意:
1)、每6508個字節為一天的數據。(6508 – 8 )/ 26 = 250
2)、每26個字節為一個分鐘的記錄。
?
2、當日分時數據格式
(1)、索引數據格式
| 數據含義 | 數據類型 | 備注 |
| 存儲標記 | Byte | 表示在指定地址是否有數據 |
| 起始地址 | Integer | 股票分時數據塊起始地址 |
注意:
1)、索引個數與“/jcb_zxjt/T0002/hq_cache/ shex.tnf”或“/jcb_zxjt/T0002/hq_cache/ szex.tnf”中的股票個數相同。
?
(2)、分時數據格式
| 數據含義 | 數據類型 | 備注 |
| 時間 | word | 如570/60=9.5,即9:30分 |
| 現價 | single | ? |
| 均價 | single | ? |
| 成交量 | Integer | ? |
| 預留 | ? | 12個字節 |
注意:
1)、每6240個字節為一天的數據。6240 / 26 = 240
2)、每26個字節為一個分鐘的記錄。
?
?
示例代碼
示例:顯示分時數據文件信息
單元:uDataBuffer
備注:uDataBuffer單元代碼在“大智慧Level2日線數據文件格式分析”文檔中。
?
?
單元:uZstData
unit uZstData;
?
interface
?
uses
??? uDataBuffer;
?
type
??? TDataRecord_min = packed record
??????? time: word; //--時間
??????? cur: single; //--現價
??????? avg: single; //--均價
??????? vol: Integer; //--成交量
??????? reservation: array[0..2] of Integer; //--保留
??? end;
?
??? TDataRecord_Zst = packed record
??????? date: Integer; //--日期
??????? Last: single; //--昨收盤
??????? min: array[0..249] of TDataRecord_min;
??? end;
??? PDataRecord_Zst = ^TDataRecord_Zst;
?
??? {歷史分時數據}
??? TStockDataStream_Zst = class(TRecordStream)
??? private
??????? function GetItems(Index: Integer): PDataRecord_Zst;
??? public
??????? constructor Create;
??????? //---
??????? property Items[Index: Integer]: PDataRecord_Zst read GetItems; default;
??? end;
?
implementation
?
constructor TStockDataStream_Zst.Create;
begin
??? inherited;
??? //---
??? DataSize := sizeof(TDataRecord_Zst);
end;
?
function TStockDataStream_Zst.GetItems(Index: Integer): PDataRecord_Zst;
begin
??? Result := self.Datas[Index];
end;
?
end.
?
單元:uTfzData
unit uTfzData;
?
interface
?
uses
??? uDataBuffer;
?
type
??? TIndexRecord_Tfz = packed record
??????? UseSign: byte; //--數據標記
??????? StartAddress: Longword; //--起始地址
??? end;
??? PIndexRecord_Tfz = ^TIndexRecord_Tfz;
?
??? TDataRecord_min_Tfz = packed record
??????? time: word; //--時間
??????? cur: single; //--現價
??????? avg: single; //--均價
??????? vol: Integer; //--成交量
??????? reservation: array[0..2] of Integer; //--保留
??? end;
?
??? TDataRecord_Tfz = packed record
??????? min: array[0..239] of TDataRecord_min_Tfz;
??? end;
??? PDataRecord_Tfz = ^TDataRecord_Tfz;
?
??? {當日分時數據}
??? TStockDataStream_Tfz = class(TCustomStringBuffer)
??? private
??????? FIndexCount: Integer;
??????? FIndexSize: Integer;
??????? FDataCount: word;
??????? FDataSize: Integer;
??????? function GetDatas(Index: Integer): PDataRecord_Tfz;
??????? function GetIndexs(Index: Integer): PIndexRecord_Tfz;
??? protected
??????? procedure ClearBuffer; override;
??????? procedure DoBufferChange; override;
??? public
??????? constructor Create;
??????? //---
??????? function GetDataStartAddress(const AIndex: Integer): Longword;
??????? //---
??????? property Datas[Index: Integer]: PDataRecord_Tfz read GetDatas;
??????? property DataCount: word read FDataCount;
??????? property Indexs[Index: Integer]: PIndexRecord_Tfz read GetIndexs;
??????? property IndexCount: Integer read FIndexCount;
??? end;
?
implementation
?
constructor TStockDataStream_Tfz.Create;
begin
??? inherited;
??? //---
??? FIndexSize := sizeof(TIndexRecord_Tfz);
??? FDataSize := sizeof(TDataRecord_Tfz);
end;
?
procedure TStockDataStream_Tfz.ClearBuffer;
begin
??? inherited;
??? //---
??? FIndexCount := 0;
??? FDataCount := 0;
end;
?
procedure TStockDataStream_Tfz.DoBufferChange;
const
??? CNT_MinStockCount = 1500;
??? //---
?? ?function _ReadIndex: Boolean;
??? var
??????? AIndexLen: integer;
??? begin
??????? AIndexLen := (self.BufferSize - FDataSize * FDataCount);
??????? FIndexCount := AIndexLen div FIndexSize;
??????? //---
??????? Result := (AIndexLen mod FIndexSize) = 0;
??? end;
??? //---
??? function _ReadData: Boolean;
??? begin
??????? FDataCount := (self.BufferSize - FIndexSize * CNT_MinStockCount) div FDataSize;
??????? Result := FDataCount > 0;
??? end;
begin
??? inherited;
??? //---
??? if FDataSize <= 0 then
????? ??self.ClearBuffer
??? else
??? begin
??????? if not (_ReadData and _ReadIndex) then
??????????? self.ClearBuffer;
??? end;
end;
?
function TStockDataStream_Tfz.GetDatas(Index: Integer): PDataRecord_Tfz;
begin
??? Result := Pointer(self.Buffer + FIndexSize * FIndexCount + FDataSize * Index);
end;
?
function TStockDataStream_Tfz.GetIndexs(Index: Integer): PIndexRecord_Tfz;
begin
??? Result := Pointer(self.Buffer + FIndexSize * Index);
end;
?
function TStockDataStream_Tfz.GetDataStartAddress(const AIndex: Integer):
??? Longword;
begin
??? Result := FIndexSize * FIndexCount + FDataSize * AIndex;
end;
?
end.
?
?
單元:Unit1
unit Unit1;
?
interface
?
uses
??? Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
??? Dialogs,StdCtrls,ExtCtrls;
?
type
??? TForm1 = class(TForm)
??????? Button1: TButton;
??????? ListBox1: TListBox;
??????? GroupBox1: TGroupBox;
??????? OpenDialog1: TOpenDialog;
??????? RadioGroup1: TRadioGroup;
??????? Panel1: TPanel;
??????? procedure FormCreate(Sender: TObject);
??????? procedure Button1Click(Sender: TObject);
??? private
??????? procedure ShowData_Zst(const AFile: string; const AListBox: TListBox);
??????? procedure ShowData_Tfz(const AFile: string; const AListBox: TListBox);
??? public
??????? procedure ShowData(const AFile: string; const AListBox: TListBox);
??? end;
?
var
??? Form1: TForm1;
?
implementation
?
uses uZstData,uTfzData;
?
{$R *.dfm}
?
procedure TForm1.FormCreate(Sender: TObject);
begin
??? with RadioGroup1.Items do
??? begin
??????? clear;
??????? Add('臨時分時數據');
??????? Add('當日分時數據');
??? end;
??? RadioGroup1.ItemIndex := 0;
??? //---
??? SendMessage(ListBox1.Handle,LB_SetHorizontalExtent,2000,longint(0));
end;
?
procedure TForm1.Button1Click(Sender: TObject);
begin
??? with self.OpenDialog1 do
??? begin
??????? if Execute then
??????????? self.ShowData(FileName,ListBox1);
??? end;
end;
?
procedure TForm1.ShowData(const AFile: string; const AListBox: TListBox);
begin
??? case RadioGroup1.ItemIndex of
??????? 0: ShowData_Zst(AFile,AListBox);
??????? 1: ShowData_Tfz(AFile,AListBox);
??? end;
end;
?
?
procedure TForm1.ShowData_Zst(const AFile: string;
??? const AListBox: TListBox);
var
??? AStream: TStockDataStream_Zst;
??? ADayIndex,AMinIndex: Integer;
begin
??? AStream := TStockDataStream_Zst.Create;
??? try
??????? with AListBox.Items do
??????? begin
??????????? BeginUpdate;
??????????? Clear;
??????????? with AStream do
??????????? begin
??????????????? if ReadFile(AFile) then
??????????????? begin
??????????????????? for ADayIndex := 0 to Count - 1 do
??????????????????? begin
??????????????????????? with items[ADayIndex]^ do
??????????????????????? begin
??????????????????????????? Add(Format('%.3d %d 昨%.2f', [ADayIndex,date,Last]));
??????????????????????????? for AMinIndex := Low(min) to high(min) do
??????????????????????????? begin
??????????????????????????????? with min[AMinIndex] do
??????????????????????????????????? Add(Format('%.3d %.2d:%.2d 現%.2f 均%.2f 量%d 保留%d %d %d', [AMinIndex,time div 60,time mod 60,
??????????????????????????????????????? cur,avg,vol,
??????????????????????????????????????????? reservation[0],reservation[1],reservation[2]]));
??????????????????????????? end;
???????????? ???????????end;
??????????????????? end;
??????????????? end;
??????????? end;
??????????? EndUpdate;
??????? end;
??? finally
??????? AStream.Free;
??? end;
end;
?
procedure TForm1.ShowData_Tfz(const AFile: string;
??? const AListBox: TListBox);
var
??? AStream: TStockDataStream_Tfz;
??? //---
??? procedure _ShowIndex;
??? var
??????? AIndex: Integer;
??? begin
??????? with AListBox.Items,AStream do
??????? begin
??????????? Add('--------索引---------');
??????????? //---
??????????? for AIndex := 0 to IndexCount - 1 do
??????????? begin
??????????????? with Indexs[AIndex]^ do
??????????????????? Add(Format('%.4d 數據標記:%d 起始地址:%.6x', [AIndex + 1,UseSign,StartAddress]));
??????????? end;
??????? end;
??? end;
??? //---
??? procedure _ShowData;
??? var
??????? ADataIndex,AMinIndex,AStartAddress: Integer;
??????? //---
??????? function _FindIndex(AStartAddress: Integer): integer;
??????? var
??????????? AIndex: integer;
??????? begin
??????????? with AStream do
??????????? begin
??????????????? for AIndex := 0 to IndexCount - 1 do
??????????????? begin
??????????????????? with Indexs[AIndex]^ do
??????????????????????? if (UseSign = 1) and (StartAddress = AStartAddress) then
??????????????????????? begin
??????????????????????????? Result := AIndex;
??????????????? ????????????exit;
??????????????????????? end;
??????????????? end;
??????????? end;
??????????? //---
??????????? Result := 0;
??????? end;
??? begin
??????? with AListBox.Items,AStream do
??????? begin
??????????? Add('--------數據---------');
??????????? for ADataIndex := 0 to DataCount - 1 do
??????????? begin
??????????????? Add(' ');
??????????????? //---
??????????????? AStartAddress := GetDataStartAddress(ADataIndex);
??????????????? Add(Format('%.3d 索引:%.3d 地址:%.6x', [ADataIndex + 1,_FindIndex(AStartAddress) + 1,AStartAddress]));
??????????????? //---
??????????????? with Datas[ADataIndex]^ do
??????????????? begin
??????????????????? for AMinIndex := Low(min) to high(min) do
??????????????????? begin
??????????????????????? with min[AMinIndex] do
?? ?????????????????????????Add(Format('%.3d %.2d:%.2d 現%.2f 均%.2f 量%d 保留%d %d %d', [AMinIndex + 1,
??????????????????????????????? time div 60,time mod 60,
??????????????????????????????????? cur,avg,vol,
??????????????????????????????????? reservation[0],reservation[1],reservation[2]]));
??????????????????? end;
??????????????? end;
??????????? end;
??????? end;
??? end;
begin
??? AStream := TStockDataStream_Tfz.Create;
??? try
??????? with AListBox.Items do
??????? begin
??????????? BeginUpdate;
?????????? ?Clear;
??????????? with AStream do
??????????? begin
??????????????? if ReadFile(AFile) then
??????????????? begin
??????????????????? _ShowIndex;
??????????????????? _ShowData;
??????????????? end;
??????????? end;
??????????? EndUpdate;
??????? end;
?? ?finally
??????? AStream.Free;
??? end;
end;
?
end.
?
總結
以上是生活随笔為你收集整理的通达信V6.1分时数据文件格式分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android多点触控,图片的拖拽与放大
- 下一篇: vim光速开发,你值得拥有