通达信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.

 

你可能感兴趣的:(证券开发,integer,function,constructor,string,button,class)