본문 바로가기
취미/Soft

키움 CDT 데이타 형식 및 텍스트 컨버전

by MDabsurd 2015. 8. 17.

 << 네이버 블로그에 예전에 썼던거 옮겨 놓습니다 >>

 

 

---- 키움 CDT 화일 writing 하는 간단한 코드 ----

 

unit kiwoom_dataloader;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, dateutils, strutils;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


function encodeKiwoomDateTime(sMyDate, sMyTime: string) : UINT64;

var
  Form1: TForm1;



implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
ByteArray4_Dummy : array [1..4] of Byte = (1,0,0,0);

var
F: file;

ByteArray8_DateTime : array [1..8] of byte;
MyDateTime : UINT64 absolute ByteArray8_DateTime;

ByteArray4_DataCount : array [1..4] of byte;
MyDataCount : LongWord absolute ByteArray4_DataCount;

MyDoubleArray : array[1..7] of Double;
OriginDate: UINT64;

sMyDate, sMyTime : String;
I: integer;

begin

  sMyDate := '20100925';
  sMyTime := '1515';

  MyDateTime := encodeKiwoomDateTime(sMyDate,sMyTime);
  MyDataCount := 2;

  MyDoubleArray[1] := 234.10; //시가
  MyDoubleArray[2] := 235.10; //고가
  MyDoubleArray[3] := 232.15; //저가
  MyDoubleArray[4] := 235.00; //종가
  MyDoubleArray[5] := 100; //거래량
  MyDoubleArray[6] := 150; //거래대금
  MyDoubleArray[7] := 50; //미결제약정



  AssignFile(F,'d:\kiwoom_data\Mydata.cdt');
  ReWrite(F,4);

  // Data Write

  Blockwrite(F,ByteArray4_Dummy,1);
  Blockwrite(F,MyDataCount,1);
  Blockwrite(F,MyDateTime, 2);
  for I:=1 to 7 do
    begin
      Blockwrite(F,MyDoubleArray[I],2);
    end;

  Blockwrite(F,MyDateTime, 2);
  for I:=1 to 7 do
    begin
      Blockwrite(F,MyDoubleArray[I],2);
    end;


  closefile(F);

end;

function encodeKiwoomDateTime(sMyDate, sMyTime: string) : UINT64;
var
OriginDate : UINT64;
MyYear,MyMonth,MyDate : Integer;
MyHour,MyMin, MySec : Integer;
begin

  // Date, Time format
  // MyDate : 20100925 <= 2010년 9월 25일
  // MyTime : 1515 <=  15시 15분 00초

  OriginDate := $42B1EAC3808800;    // 1970년 00월 00일 00시 00분 00초

  MyYear := StrToInt(LeftStr(sMyDate,4));
  MyYear := MyYear - 1970;
  MyMonth := StrToInt(MidStr(sMyDate,5,2));
  MyDate := StrToInt(RightStr(sMyDate,2));
  MyHour := StrToInt(LeftStr(sMyTime,2));
  MyMin :=  StrToInt(RightStr(sMyTime,2));

  Result := 256* (OriginDate + MyMin *100 + MyHour*10000 + MyDate*1000000 + MyMonth*100000000+ MyYear*10000000000);

end;
end.


 

CDT_conv.rar

 

 

 

 

댓글