環境 : Linux Bash
說明 : 到期交所下載期貨交易記錄轉成 tick 檔
程式碼
( Bash Code )
#!/bin/sh # Get Tick # V 1.2.0 2016-02-27 change url # V 1.1.1 2015-04-24 change prg dir ( tick -> trade ) # V 1.1 2009-10-10 # 2016-02-26 change url # url_zipDailyFile=http://www.taifex.com.tw/DailyDownload/Daily_`date +%Y_%m_%d`.zip url_zipDailyFile=http://www.taifex.com.tw/DailyDownload/DailyDownload/Daily_`date +%Y_%m_%d`.zip dailyStoreDir=/home/redjoe/trade/prg_bash/daily/ tickStoreDir=/home/redjoe/trade/prg_bash/tick/ log_File=/home/redjoe/trade/prg_bash/rj_crontab.log ltd=`tac /home/redjoe/trade/last-trading-days/last-trading-days` wget -c -a $log_File -P $dailyStoreDir $url_zipDailyFile # Process Tick cd $dailyStoreDir workFile=`date +%Y_%m_%d` workday=`date +%Y%m%d` workMonth=`date +%Y%m` zip_DailyFile=Daily_$workFile.zip rpt_DailyFile=Daily_$workFile.rpt workmonth=./tmp1 wkproduct=`ls -l $zip_DailyFile | cut -d ' ' -f 5 ` # echo $wkproduct if [ "$wkproduct" -ne '93' ]; then unzip $zip_DailyFile # echo $rpt_DailyFile # echo $workFile.TX for td in $ltd do #echo "$td="$td , "$workday="$workday if [ "$td" -ge "$workday" ]; then #echo " $td > $workday " wkmonth=`echo $td` fi done echo $wkmonth > $workmonth wkproduct=`cut -c 1-6 $workmonth` # echo $wkproduct # TX 台指 head -n 1 $rpt_DailyFile > $workFile.TX sed '/MTX/d' $rpt_DailyFile | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TX echo "TickTime,Price,Vol" > txf$workday.csv sed '/MTX/d' $rpt_DailyFile | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> txf$workday.csv # MTX 小台 head -n 1 $rpt_DailyFile > $workFile.MTX sed -n '/MTX/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.MTX echo "TickTime,Price,Vol" > mxf$workday.csv sed -n '/MTX/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> mxf$workday.csv # TE 電指期 head -n 1 $rpt_DailyFile > $workFile.TE sed -n '/TE/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TE echo "TickTime,Price,Vol" > exf$workday.csv sed -n '/TE/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> exf$workday.csv ## TF 金指期 head -n 1 $rpt_DailyFile > $workFile.TF sed '/GTF/d' $rpt_DailyFile | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TF echo "TickTime,Price,Vol" > fxf$workday.csv sed '/GTF/d' $rpt_DailyFile | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> fxf$workday.csv rm $workmonth if [ ! -d $workMonth ]; then mkdir $workMonth fi mv $rpt_DailyFile $zip_DailyFile $workMonth/ if [ ! -d "/home/redjoe/trade/prg_bash/tick/$workMonth" ]; then mkdir /home/redjoe/trade/prg_bash/tick/$workMonth fi mv $workFile.TX txf$workday.csv $workFile.MTX mxf$workday.csv $workFile.TE exf$workday.csv $workFile.TF fxf$workday.csv $tickStoreDir$workMonth/ fi
沒有留言:
張貼留言