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

# File eod_ino, July 2012

{
  End of day collection of market data

  Wed Jul 11 16:47:43 PDT 2012. 

  EOD collection is faltering and it is time to get CME E-quotes to
  do some tables for all the markets.  

  Collection on barchart is unreliable, and there appears to be no
  source that provides volume and open interest.  That's ok, and 
  when CME E-quotes can be used, they will be available.

  This script is a last-ditch effort to get pit end of day data so
  programs still run.  It does not have to be that accurate.

  INO.com is used for the 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 "eod_params" + "host" param_find "HOST" book

   host HOST <>
   IF " eod_ino: only on " . HOST . nl exit THEN

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

\  ontheweb
\  host "riggo" = or
\  IF " eod_ino: skipping electronic end of day collection" . nl
\     exit
\  THEN
  
   inline: eodECOLLECT ( --- hT) \ data ino
      [ 6 "KEEP" book ]

      tracklist "TRACK" book

      time push
      depth push
      "From script eod_ino"
      date neat

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

      " "
      TRACK rows 1st
      DO no "inoDATA" "ALL_HOSTS" bank \ just do one ino host

         TRACK I quote inoDATA any?
         IF " inoDATA for " TRACK I quote + . nl

         ELSE \ get EDATA if pit data fails  
            TRACK I quote inoEDATA any?
            IF " inoEDATA for " TRACK I quote + . nl
            ELSE ""
            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_ino: begin " date + . nl

   eodECOLLECT any? not
   IF eodECOLLECT any? not
      IF " eod_ino: 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_ino: 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_ino: temp file for pit pre-eod saved " date + . nl
   ELSE
      " eod_ino: failed " date + . nl
   THEN

   exit
