輸入 - C:\tmp\1.csv
輸出 - C:\tickhist\txf.csv
再配合 autoit 或 AutoHotKey , 就可以按一下自動補上今日K線資料
today1k.pl 程式
#!C:\Perl\bin\perl.exe
# 取出今天的K線, 去除最後一筆
# 輸入一分K線檔 - C:\tmp\1.csv
# 輸出一分K線檔 - C:\tickhist\txf.csv
use POSIX qw(strftime);
use integer;
$src_k1m = 'C:\\tmp\\1.csv'; # 1mk source file
$tmpfile = 'C:\\tickhist\\tmp001.csv'; # tmp file
$tar_k1m = 'C:\\tickhist\\txf.csv'; # 1mk target file
$today = strftime "%Y/%m/%d", localtime;
print "Process $today Today 1 Minute K To : $tar_k1m.\n";
open(infile, $src_k1m) || die("Cannot open $src_k1m.\n");
open(tempfile, ">$tmpfile");
$rec_no=0;
;
while(my $k1m_record = )
{
chomp $k1m_record;
# $k1m_record =~ s/ //g;
# ($kDate, $kTime, $kOpen, $kHigh, $kLow, $kClose, $kVol)=split(/, / , $k1m_record);
($kDateTime, $kOpen, $kHigh, $kLow, $kClose, $kVol)=split(/,/ , $k1m_record);
($kDate, $kTime)=split(/ / , $kDateTime);
if ($kDate eq $today ){
print tempfile "$kDate,$kTime,$kOpen,$kHigh,$kLow,$kClose,$kVol\n";
$rec_no = $rec_no + 1;
}
}
close(tempfile);
close(infile);
open(tmp_file, $tmpfile) || die("Cannot open $tmpfile.\n");
open(outfile, ">$tar_k1m");
print outfile "Date,Time,Open,High,Low,Close,Vol\n";
for ( $i=1; $i<$rec_no; $i++ ) {
my $tmp_record = ;
print outfile $tmp_record;
# print "$i\n";
}
close(tmp_file);
close(outfile);
# 刪除暫存檔
unlink $tmpfile;
註:
1.其時用附屬工具 grep 來做會更精簡。
2.看盤軟體"康和全都賺"匯出一分K, 會有將近三個月的K線資料。
---