#!/bin/sh # # trading-shim.sh # # used to populate the stock ticker crawlbox from cron # # License: GPL, v.2 # Original script may be viewed at: # http://www.trading-shim.org/faq/trading-shim.sh.txt # # /usr/bin/yahooquote is provided by # perl-Finance-YahooQuote # which may be found for CentOS at: # ftp://ftp.owlriver.com/pub/mirror/ORC/smtm/ # along with a README on build environment dependencies # # Run with a root crontab entries thus: # (the second gets the market close overnight values) # # */5 9-15 * * 1-5 /root/bin/trading-shim.sh # 20 16 * * 1-5 /root/bin/trading-shim.sh # # We produce the scroll marquee inside php code thus: # cat - << END > /dev/null // print ""; print "
  "; print ""; include ("result.inc"); $TIM = date("H:i"); print "Current time: $TIM "; print "  
"; // END # DEST="/home/trading/public_html/template" WORK=$DEST/work.inc RESULT=$DEST/result.inc # DOW=`date +%u` [ $DOW -lt 1 ] && exit [ $DOW -gt 5 ] && exit HOD=`date +%k` [ $HOD -lt 9 ] && exit MOH=`date +%M` [ $HOD -eq 9 -a $MOH -lt 31 ] && exit # # ok -- we are building - go to it > $WORK [ $HOD -lt 16 ] && { date +"%A %d %B %Y %H:%M" >> $WORK echo " (delayed) ... " >> $WORK } || { date +"%A %d %B %Y" >> $WORK echo " (Market close) ... " >> $WORK } # AMD24.46 ... for i in `grep -v ^# /root/bin/symbols | sort | uniq `; do NONCE=`/usr/bin/yahooquote $i | tr '\t' '#' | \ awk -F# '{print $3}' ` # # awkwardly, sometimes we have too many digits right of the # decimal point, and shell math is integer only LHS=`echo "${NONCE}" | awk -F. '{print $1}'` RHS=`echo "${NONCE}00" | awk -F. '{print $2}' | cut -c -2` [ $HOD -gt 15 ] && { echo "${LHS}${RHS}" > $DEST/$i.prior [ -e $DEST/$i.last ] && rm -f $DEST/$i.last } # echo -n "$i" >> $WORK FONT="blue" [ -e $DEST/$i.prior ] && { PC=` head -1 $DEST/${i}.prior ` [ $PC -gt ${LHS}${RHS} ] && export FONT="red" [ $PC -lt ${LHS}${RHS} ] && export FONT="green" } || { # # we cheat and populate any missing ones intra-day echo "${LHS}${RHS}" > $DEST/$i.prior } echo -n "> $WORK echo -n "$FONT" >> $WORK echo -n "\" >${LHS}.${RHS} " >> $WORK # # last trade noted - only while the market is open # downarrow.gif evenarrow.gif uparrow.gif [ -e $DEST/$i.last -a $HOD -lt 16 ] && { echo -n "> $WORK TICK="blue" LT=` head -1 $DEST/${i}.last ` [ $LT -gt ${LHS}${RHS} ] && { export TICK="red" echo -n "downarrow.gif" >> $WORK } [ $LT -lt ${LHS}${RHS} ] && { export TICK="green" echo -n "uparrow.gif" >> $WORK } [ "x${LT}" = "xblue" ] && { echo -m "evenarrow.gif" >> $WORK } echo "\">" >> $WORK } echo " ..." >> $WORK echo "${LHS}${RHS}" > $DEST/$i.last done mv $WORK $RESULT #