#!/usr/local/bin/tops -s /usr/local/tops/sys -u /opt/mytops/usr/

# File eod_elec, January 2008

# End of day collection of electronic market data
{
  When a script has trouble, source this file at the ready prompt to
  troubleshoot.

  Tue Jul  5 19:54:13 PDT 2011.  Upgrades to site tch make it no longer
  accessible.  Site bch was fixed to handle intraday data.

  Thu Sep  9 15:18:16 PDT 2010.  Trouble with bc doing LC.  Switched
  so tch is tried first and it worked.

}
#-----------------------------------------------------------------------

   usrpath "mget.v" + source
   keys? not IF LOG-FILE set_sysout THEN

   ontheweb
   host "riggo" = or
   IF " eod_elec: skipping electronic end of day collection" . nl
      exit
   THEN
  
   inline: eodECOLLECT ( --- hT) \ data from bch or ino or tch
    \ This word is based upon inoCOLLECT and bcEOD, files ino.v and 
    \ bch.v.

      [ 6 "KEEP" book ]

      tracklist "TRACK" book

      time push
      depth push
      "From script eod_elec"
      date neat

      "Electronic trading" 
      "Showing: Open High Low Settle Close Chg Vol OpenInt"

      " "
      TRACK rows 1st
      DO \ tries bch, then ino, then tch:

         no "bcPROCESS" "EOD" bank
         TRACK I quote bcDATA any?
         IF " bcDATA for " TRACK I quote + . nl

         ELSE
            no "inoDATA" "ALL_HOSTS" bank \ just do one ino host
            TRACK I quote inoEDATA any?
            IF " inoEDATA for " TRACK I quote + . nl

            ELSE \ Tue Jul  5 19:54:13 PDT 2011: this branch will fail
               TRACK I quote tcEDATA any?
               IF " tcEDATA for " TRACK I quote + . nl
               ELSE ""
               THEN
            THEN
         THEN any? 
         IF (hT) 1st over rows KEEP min items reach (hT)

            "-----" " 0 " strp

             this 8 ndx word drop
             numerate totals ontop @ 1 max int$ "V" book
             this 9 ndx word drop
             numerate totals ontop @ 1 max int$ "OI" book

            TRACK I quote spaced
            " VOL and OI totals: " + V + spaced OI + neat

            swap

         ELSE TRACK I quote spaced date + " no data" +
         THEN
         " "
      LOOP
      depth pull less pilen

      "ET: " time pull less 60 slash "%0.1f" format +
      " minutes" + pile

      "eodECOLLECT" naming
   end

   " eod_elec: begin " date + . nl

   eodECOLLECT any? not
   IF eodECOLLECT any? not
      IF " eod_elec: two attempts failed" ersys "" THEN
   THEN

   (hT) any?
   IF (hT) mpath
      time GMT>LA ctime 1st quote strchop
      sysdate drop intstr "E.dat" + + (hT qFile) 2dup save
      " eod_elec: E file saved " date + . nl

{     The following non-E file lets pit eod be run now (called pre-
      eod), before final pit data has been received (which will be 
      later, in about 1.25 hours).  

      After the final pit data is received, pit eod will be run again 
      after files are reverted to the way they were before pre-eod was
      run.  See word revert, file eod.v.
}
      (hT qFile) "E" "" strp save \ temp file for pit pre-eod
      " eod_elec: temp file for pit pre-eod saved " date + . nl
   ELSE
      " eod_elec: failed " date + . nl
   THEN

   exit
