116 lines
5.4 KiB
Bash
Executable File
116 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run with faketime -f '-2d' $1 on non-trading day
|
|
#
|
|
|
|
if [ "$1" = "-t" ]; then
|
|
MAILTO=xpk@headdesk.me
|
|
else
|
|
MAILTO=list.k0k9oxbxrir2n3t7@headdesk.me
|
|
fi
|
|
|
|
MONTH=$(date +%b)
|
|
NEXTMONTH=$(date +%b -d 'next month')
|
|
BASETHRES=1000
|
|
THRESHOLD=`echo "$BASETHRES + $(date +%d)*15" | bc`
|
|
# THRESHOLD=1000
|
|
|
|
FILENAME1=$(curl -sq https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/dmreport8.htm | grep -A5 'Day Trading Session' | tail -1 | cut -d\" -f2)
|
|
links2 -dump "https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/$FILENAME1" > /tmp/hsio.txt
|
|
|
|
echo "* HSI options big player positions" > /tmp/msg
|
|
echo "3000 support | 4000 strong support | 5000 iron | 6000 steel" >> /tmp/msg
|
|
|
|
echo "" >> /tmp/msg
|
|
echo -e "*Resistance*" >> /tmp/msg
|
|
cat /tmp/hsio.txt | egrep -i "^ $MONTH" | egrep '^\ [A-Z]*\-.*C.*' | awk -v aTHRESHOLD=$THRESHOLD '{if ($21 > aTHRESHOLD) print $1,$2,$3,$21,$NF}' >> /tmp/msg
|
|
|
|
echo -e "\n*Support*" >> /tmp/msg
|
|
cat /tmp/hsio.txt | egrep -i "^ $MONTH" | egrep '^\ [A-Z]*\-.*P.*' | awk -v aTHRESHOLD=$THRESHOLD '{if ($21 > aTHRESHOLD) print $1,$2,$3,$21,$NF}' >> /tmp/msg
|
|
|
|
echo -e "\n*Resistance*" >> /tmp/msg
|
|
cat /tmp/hsio.txt | egrep -i "^ $NEXTMONTH" | egrep '^\ [A-Z]*\-.*C.*' | awk -v aTHRESHOLD=$THRESHOLD '{if ($21 > aTHRESHOLD) print $1,$2,$3,$21,$NF}' >> /tmp/msg
|
|
|
|
echo -e "\n*Support*" >> /tmp/msg
|
|
cat /tmp/hsio.txt | egrep -i "^ $NEXTMONTH" | egrep '^\ [A-Z]*\-.*P.*' | awk -v aTHRESHOLD=$THRESHOLD '{if ($21 > aTHRESHOLD) print $1,$2,$3,$21,$NF}' >> /tmp/msg
|
|
|
|
|
|
echo -e "\n* HSIF position day end" >> /tmp/msg
|
|
|
|
mkdir -p /tmp/hsif-tmp
|
|
FILENAME="DTOP_F_$(date +%Y%m%d).zip"
|
|
wget -q -O- "https://www.hkex.com.hk/eng/stat/dmstat/oi/$FILENAME" | bsdtar -C/tmp/hsif-tmp -xvf -
|
|
if [ -f "/tmp/hsif-tmp/${FILENAME%.*}/no_trading_activities.txt" ]; then
|
|
echo -e "Not a trading day, no data..." >> /tmp/msg
|
|
# terminate script
|
|
rm -rf /tmp/hsif-tmp
|
|
exit 0
|
|
else
|
|
cat /tmp/hsif-tmp/*dtop_f_hkcc_fut_dtl_hsi.rpt | grep ^HSI | head -1 | awk '{print $5,$6}' > /my/scripts/finance/hsif-today
|
|
paste /my/scripts/finance/hsif-last /my/scripts/finance/hsif-today | tr -d ',' \
|
|
| awk '{gc = $3 - $1; nc = $4 - $2; printf "Gross: %d %+d Net: %d %+d\n", $3, gc, $4, nc}' >> /tmp/msg
|
|
cat /my/scripts/finance/hsif-today > /my/scripts/finance/hsif-last
|
|
rm -f /my/scripts/finance/hsif-today
|
|
rm -rf /tmp/hsif-tmp
|
|
fi
|
|
|
|
# weekly option
|
|
echo -e "\n* Weekly option" >> /tmp/msg
|
|
echo THISMONTH=$(date +%b)
|
|
echo -e "\nUrl: https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/hsiwo$(date +%y%m%d).htm" >> /tmp/msg
|
|
http https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/hsiwo210416.htm | egrep "^[0-9].*${THISMONTH^^}.*[CP]" | sort -nr -k 21 | head -10 | awk '{print $1,$2,$3,$21,$22}' | sort >> /tmp/msg
|
|
|
|
# Get HSI today
|
|
echo -e "\n* HSI closing" >> /tmp/msg
|
|
links2 -dump 'http://www.aastocks.com/en/stocks/market/index/hk-index.aspx' | grep HSI | head -1 | awk '{print $2, $3, $5}' | cut -b4- >> /tmp/msg
|
|
|
|
# Calculate fluctuation based on VHSI
|
|
# reference: https://www.ifec.org.hk/web/common/pdf/ouhk2012/02.pdf
|
|
#VHSI=$(curl -sq 'https://hk.finance.yahoo.com/quote/%5EHSIL/' | elinks -dump | grep -B1 '收市價' | head -1 | awk -F[+-] '{print $1}')
|
|
#ONESD=$(bc <<< "scale=0; sqrt($VHSI)*0.5")
|
|
#HSICLOSE=`links2 -dump 'http://www.aastocks.com/en/stocks/market/index/hk-index.aspx' | grep HSI | head -1 | awk '{print $2}' | cut -b4- | tr -d ,`
|
|
|
|
# get HSI future price for this month
|
|
|
|
#elinks -dump https://www.investing.com/indices/hong-kong-40-futures-historical-data \
|
|
#| grep -A35 "Download Data" | head -35 | grep -i $(date +%b) > /tmp/investing.dat
|
|
|
|
#HSIF_HI=$(cat /tmp/investing.dat | awk '{print $6}' | sort -nr | head -1 | tr -d ,)
|
|
#HSIF_LO=$(cat /tmp/investing.dat | awk '{print $7}' | sort -n | head -1 | tr -d ,)
|
|
|
|
#FLUCT=`bc <<< "scale=6; $VHSI / sqrt(12) / 100 * $HSICLOSE"`
|
|
echo -e "\n* 用VHSI計未來30日波:" >> /tmp/msg
|
|
#echo "VHSI: $VHSI" >> /tmp/msg
|
|
#echo "未來30日波: ${FLUCT%.*} [1]" >> /tmp/msg
|
|
|
|
#PASS30DAYRANGE=$(bc <<< "scale=0; $HSIF_HI-$HSIF_LO")
|
|
#echo "即月期指高低差: ${PASS30DAYRANGE%.*}" >> /tmp/msg
|
|
#echo "即月期指低: ${HSIF_LO%.*}" >> /tmp/msg
|
|
#echo "即月期指高: ${HSIF_HI%.*}" >> /tmp/msg
|
|
#echo "[1] Today close x VSHI / sqrt(12) / 100" >> /tmp/msg
|
|
|
|
/my/scripts/finance/vhsi.py >> /tmp/msg
|
|
|
|
# Disclaimer and unsubscribe link
|
|
echo -e "\n--\nData in this message are extracted from HKEX and AASTOCKs and sent to you via MAILGUN. To unsubscribe, please use the link %mailing_list_unsubscribe_url%" >> /tmp/msg
|
|
|
|
echo -e "\n\nData sources: \nhttps://www.hkex.com.hk/eng/stat/dmstat/dayrpt/$FILENAME1 \nhttps://www.hkex.com.hk/eng/stat/dmstat/oi/$FILENAME \nhttp://www.aastocks.com/en/stocks/market/index/hk-index.aspx \nhttps://www.ifec.org.hk/web/common/pdf/ouhk2012/02.pdf \nhttps://hk.finance.yahoo.com/quote/%5EHSIL/ \nhttps://www.investing.com/indices/hong-kong-40-futures-historical-data \nhttps://www.hkex.com.hk/eng/stat/dmstat/dayrpt/hsiwo$(date +%y%m%d).htm" >> /tmp/msg
|
|
|
|
#mailx -s "HSIO HSIF Summary // $(date +%x)" -- list.k0k9oxbxrir2n3t7@headdesk.me < /tmp/msg
|
|
|
|
if [ "$1" = "-t" ]; then
|
|
cat /tmp/msg
|
|
rm -f /tmp/msg.mime /tmp/hsio.txt
|
|
else
|
|
# hsi list is on mailgun
|
|
makemime -c "text/plain; charset=utf-8" -a "Subject: HSIO 大戶位 / HSIF day end // $(date +%x)" \
|
|
-a "From: do-not-reply@headdesk.me" -o /tmp/msg.mime /tmp/msg
|
|
|
|
curl -s --user 'api:key-30aa61423c7d63a1432ede669c22da5e' \
|
|
https://api.mailgun.net/v3/headdesk.me/messages.mime \
|
|
-F to=$MAILTO \
|
|
-F message=@/tmp/msg.mime
|
|
|
|
rm -f /tmp/msg /tmp/msg.mime /tmp/hsio.txt
|
|
fi
|
|
|