Stock Quotes

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I wanted to put together a simple batch file that could retrieve stock quote data. I threw the following together.

Usage: quote.btm [-D] symbol1 symbol2...

The optional -D switch will display debug data. This batch file does use my getopt.btm script. You can find that on this site here (make sure you grab the last one posted). You can also set the an http proxy. Run it without arguments to get usage information.

You can always grab the latest version at:


Please let me know what you think. I'd love to hear any ideas, comments (both good and bad). It's not perfect, but it meets my needs.

Regards,

Fross

Code:
SetLocal
rem -----------------------------------------------------------------------------------
rem quote.btm by Michael Fross
rem
rem Simple batch file to grab information from Yahoo finance on the stocks entered.
rem It also grabs the DOW information from Google.  Apparently you can't get the DOW
rem data from yahoo anymore.
rem 
rem URL to grab Yahoo Data.  In this example, the ACN and MSFT symbols are used.
rem     http://download.finance.yahoo.com/d/quotes.csv?s=ACN+MSFT&f=sl1c1oghkj
rem
rem  URL to grab google DOW information.
rem   http://finance.google.com/finance/info?client=ig&q=INDEXDJX%3A.DJI
rem
rem Detailed on options of the webservice.  Those following the &f= portion of the URL
rem     http://www.gummy-stuff.org/Yahoo-data.htm
rem
rem I hope these webservices / Google URL don't stop working :)
rem
rem -----------------------------------------------------------------------------------
 
:: Verify that command line options are accurate
call c:\utils\GetOpt.btm %$
 
:: Validate we've entered a parameter
iff not defined PARAM_0 then
    gosub SetColor Red
    echo ERROR:  Incorrect Usage
    echo    Usage:  quote.btm [-D] Symbol01 Symbol02 Symbol03 ...
    echo.
    echo For Proxy Server Configuration:
    echo    The Script will use the Proxy and ProxyPort TCC configuration.  If you wish
    echo    to override these, the HTTP_Proxy environment variable can be set.
    echo.
    echo    Format:  set HTTP_PROXY=servername:PORT
    echo    Example: set HTTP_PROXY=servername.domainname.com:8080
    gosub SetColor Normal
    quit
endiff
 
:: Turn on Debug if -D option is given on the command line
if defined OPTION_D set DEBUG=1
 
:: Manage the proxy configuration
iff defined HTTP_PROXY then
    :: Dissect the proxy string and set the Proxy and ProxyPort options
    gosub DebugPrint "HTTP_PROXY variable set.  Over-riding any that are are in %_ININame"
    option //Proxy=%@InStr[0,%@Index[%HTTP_PROXY,:],%HTTP_PROXY]
    option //ProxyPort=%@InStr[%@Inc[%@Index[%HTTP_PROXY,:]],,%HTTP_PROXY]
 
    gosub DebugPrint "Proxy Configuration from HTTP_PROXY environment variable:"
    gosub DebugPrint "  - HTTP_PROXY: %HTTP_PROXY"
    gosub DebugPrint "  - Proxy:      %@Option[Proxy]"
    gosub DebugPrint "  - Port:       %@Option[ProxyPort]"
    echo.
else
    gosub DebugPrint "Proxy Configuration from %_ININame:"
    gosub DebugPrint "  - Proxy:      %@Option[Proxy]"
    gosub DebugPrint "  - Port:       %@Option[ProxyPort]"
    echo.
endiff
 
:: Display results header information
gosub SetColor White
echo Quote.btm by Michael Fross
echo.
echo Symbol^tCurrent^tChange^tOpen^tDayLow^tDayHigh^t52WkLow^t52WkHigh
echo ----------------------------------------------------------------
 
:: Loop through each item givin on the command line and pull the data
do i = 1 to %PARAM_0
    set Result=%@ExecStr[type http://download.finance.yahoo.com/d/quotes.csv?s=%[PARAM_%i]^&f=sl1c1oghkj]
 
    :: If in Debug mode, show raw data from Yahoo
    iff defined DEBUG then
        echo.
        gosub DebugPrint "Raw data from Yahoo Query for symbol: %@Upper[%@Field[0,%Result]]]
        do i = 1 to %@Fields[^,,%Result]
            echo   [%i]: %@Field[%i,%Result]
        enddo
    endiff
 
    :: Only display if the symbol is valid (Current > 0)
    iff "%@Field[7,%Result]"=="N/A" then 
        echo.
        gosub SetColor Yellow
        echos %@Upper[%@UnQuote[%@Field[0,%Result]]]^t*Invalid Symbol*
        ITERATE
    endiff
 
    :: Display symbol name
    gosub SetColor Yellow
    echo.
    echos %@Upper[%@UnQuote[%@Field[0,%Result]]]
 
    :: Loop through results and display the items selected
    do j = 1 to %@Fields[^,,%Result]
        echos ^t%@Field[%j,%Result]
    enddo
enddo
echo.
 
:: Grab the DOW infomation and put it into the DowArray
setarray DOWArray[18]
set Dummy=%@ExecArray[DOWArray,type http://finance.google.com/finance/info?client=ig^&q=INDEXDJX^%3A.DJI] 
 
:: Provide raw debug information from Google's DOW query
iff defined DEBUG then
    echo.
    gosub SetColor Red
    echo DEBUG: Raw data from DOW information query
    do i = 1 to %@Eval[%_execarray-1]
        echo   [%i]:  %DOWArray[%i]
    enddo
    gosub SetColor Normal
endiff
 
:: Display the Dow Jones information
gosub SetColor White
echo.
echo Dow Jones Industrial Average:
echos Current: ^e[33;1m%@Unquote[%@Field[" . ",2,%DowArray[7]]]
echos   ^e[37;1mChange: ^e[33;1m%@Unquote[%@Field[" . ",2,%DowArray[11]]]
echo  (%@Unquote[%@Field[" . ",2,%DowArray[12]]]%%)
 
:: Display time/date stamp for results
gosub SetColor Normal
echo.
echo Results as of %_isodate %_time and may be 15 minutes delayed
 
:: Cleanup and Exit Program
unsetarray DOWArray
EndLocal
quit
 
 
rem -----------------------------------------------------------------------------------
rem DebugPrint [Message] Subroutine
rem -----------------------------------------------------------------------------------
:DebugPrint [Message]
    iff defined DEBUG then
        gosub SetColor Red
        echo DEBUG:  %@Unquote[%Message]
    endiff
return
 
 
rem -----------------------------------------------------------------------------------
rem SetColor [Clr]
rem -----------------------------------------------------------------------------------
:SetColor [Clr]
    Switch %@Upper[%Clr]
        Case YELLOW
            echos ^e[33;1m
 
        Case RED
            echos ^e[31;1m
 
        Case WHITE
            echos ^e[37;1m
 
        Case NORMAL
            echos ^e[0m
 
        Default
            echo ** ERROR Setting Color.  Unknown Directive:  '%Clr' **
    EndSwitch
return
 
#2
I'm not sure if everyone ever grabbed this or is interested, but I use it daily. I've made a few updates and wanted to let folks know.

The latest version can be found at:

https://bitbucket.org/frossm/quote.btm/src

If you would prefer a zip download, check out the 'download' tab.

Please let me know if you have any thoughts or questions.

Michael


Application Changelog:

* 2012-02-29 83454badeb02
Updated the "current as of" time from the time the batch file was run to the time retured by the google data.

* 2012-02-28 536ab20dd75f
Just fixed a tiny typo in debug mode. Nothing really.

* 2012-01-10 876faaab15af
Oops! Forgot a gosub before the DebugPrint. My bad. Sloppy. Anyway, it's corrected.

* 2012-01-10 da71886bedc1
Bug. The TYPE command I used to replace CURL.EXE did not respect the

*2012-01-05 31e0e82c4769
Sweet. I removed the need to use "curl.exe" an external program.

* 2012-01-05 0b0f4db7b6bc
Cleaned up a bit of color on debug output as well as made

*2011-12-21 ddf112f72442
Added a -D switch. This turns debug on for the option.btm program.

* 2011-12-21 1dfe1f9630c6
Code reorgization. Split out color directives and debug printing to

* 2011-12-21 6ebeba114d9c
Added code to print debug output showing data received from yahoo.

* 2011-12-20 7765ecffaa94
Added percentage change to the Dow Jones information.

*2011-12-20 997eecbf6d37
Simply updated the usage informaiton to describe the proxy

* 2011-12-20 fad26dc18fc1
Added debug data print for raw DOW Jones information from Google.

* 2011-12-20 646d1f283a3a
Big upgrade! Added DJIA information. Had to pull from google as

* 2011-12-09 bbc8991389fa
Added some color directives as well as a date/time line at the bottom.

* 2011-12-08 b63d951c7609
Added a proxy display if in debug mode.

* 2011-12-07 f9779ab57244
Initial load of batch file.