- May
- 380
- 4
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
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