Delivers stock quotes to a chatroom using either @stock TICKER or !stock TICKER (@commands are public to the channel and !commands are noticed to the user)
Works with !stock and !price (uses Yahoo Finance)
This script will automatically notify you of script updates when you start mIRC
Copy entire code and paste into remote section of a new script (Hit alt+r, File New)
Sample output: @stock GOOG
GOOG (Alphabet Inc.) Last: 711.12 (+9.69, +1.38%) Vol: 2,043,140 Mkt. Cap: 489.48B Link: http://finance.yahoo.com/q?s=goog
(Different options and information about the stock are available to display as well)
Posted July 08, 2012
I can be contacted via a comment below
I can be found at irc.rizon.net:6667 name nick1
--Let me know when its broken//what you want changed.
--Feedback greatly appreciated
--If you don't like it lick it.
;Stock Quote Script (Financial Stock Data) v2.4
;Made by nick1
;View online and report bugs at http://hawkee.com/snippet/9578
;Last edit May 7, 2016
;2DO -- Add a dialog for this to select colors, public/private, what to display, etc.
;DISCLAIMER: Data and information provided may be delayed.
;Data and information is provided for informational purposes only, and is not intended for trading purposes. - Currency in USD
;NOTE: API is deprecated and unofficial, see http://tinyurl.com/mircstock3 for column options
alias -l stockVersion {
return v2.4
}
alias stock {
var %ticks $ticks
tokenize 32 $strip($1-)
if ($1) {
if ($1 == eurusd) { var %ticker EURUSD=X }
elseif ((*s&p* iswm $1) || (*SP500* iswm $1)) { var %ticker ^GSPC }
elseif ($1 == nasdaq) { var %ticker ^IXIC }
elseif ($1 == nyse) { var %ticker ^NYA }
else {
var %ticker $1
}
set $+(%,stock.,%ticks,.msgtype) echo -a
set $+(%,stock.,%ticks,.ticker) $replace(%ticker,^,$(%255E,0))
sockopen $+(stock.,%ticks) query.yahooapis.com 80
}
elseif ($1 == $null) {
echo -act info 4Incorrect Syntax - Use10 /stock <ticker symbol>
}
}
on *:input:*:{
$iif($istok(%nolinks,$active,44),return,noop)
$iif($istok(%youtubefetch,$active,44),return,noop)
if (($left($strip($1),1) == @) || ($left($strip($1),1) == !)) {
if (($remove($1,$left($strip($1),1)) == stock) || ($remove($1,$left($strip($1),1)) == stocks) || ($remove($1,$left($strip($1),1)) == stockquote) || ($remove($1,$left($strip($1),1)) == price) || ($remove($1,$left($strip($1),1)) == p) || ($remove($1,$left($strip($1),1)) == ystock)) {
if ($2) {
if ($2 == eurusd) { var %ticker EURUSD=X }
elseif ($2 == S&P500) || ($2-3 == s&p 500) { var %ticker ^GSPC }
elseif ($2 == nasdaq) { var %ticker ^IXIC }
elseif ($2 == nyse) { var %ticker ^NYA }
else {
var %ticker $2
}
var %ticks $ticks
set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $active,echo -a),msg $active)
set $+(%,stock.,%ticks,.ticker) $replace(%ticker,^,$(%255E,0))
sockopen $+(stock.,%ticks) query.yahooapis.com 80
}
elseif ($2 == $null) {
echo -a 4Incorrect Syntax - Use10 $1 <ticker symbol>
}
}
}
}
on $*:text:/^[!@](stock|stocks|stockquote|price|p|ystock)(\s|$)/Si:#:{
$iif($istok(%nolinks,$nick,44),return,noop)
$iif($istok(%youtubefetch,$chan,44),return,noop)
if ($($+(%,botflood.,$nick),2)) {
if ($($+(%,botflood.,$nick),2) >= 300) { ignore -u60 $address($nick,0) | msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot. | halt }
elseif ($($+(%,botflood.,$nick),2) >= 200) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
else { inc -z $+(%,botflood.,$nick) 25 }
}
else { inc -z $+(%,botflood.,$nick) 25 }
var %ticks $ticks
tokenize 32 $strip($1-)
if ($2) {
if ($2 == eurusd) { var %ticker EURUSD=X }
elseif ($2 == S&P500) || ($2-3 == s&p 500) { var %ticker ^GSPC }
elseif ($2 == nasdaq) { var %ticker ^IXIC }
elseif ($2 == nyse) { var %ticker ^NYA }
else {
var %ticker $2
}
set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $chan,notice $nick),msg $nick)
set $+(%,stock.,%ticks,.ticker) $replace(%ticker,^,$(%255E,0))
sockopen $+(stock.,%ticks) query.yahooapis.com 80
}
elseif ($2 == $null) {
notice $nick 4Incorrect Syntax - Use10 $1 <ticker symbol>
}
}
on *:sockopen:stock.*: {
var %sw sockwrite -nt $sockname
var %enc1 $(/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28",0)
var %enc2 $("%29&env=store://datatables.org/alltableswithkeys,0)
%sw GET $+(%enc1,$($+(%,$sockname,.ticker),2),%enc2) HTTP/1.1
%sw Host: query.yahooapis.com
%sw $crlf
}
alias -l months {
return January,February,March,April,May,June,July,August,September,October,November,December
}
on *:SOCKREAD:stock.*: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
var %ticks $remove($sockname,stock.)
var %url $+(http://finance.yahoo.com/q?s=,$($+(%,stock.,%ticks,.ticker),2))
sockread &t
bwrite temp $+ %ticks -1 -1 &t
bread temp $+ %ticks 0 $file(temp $+ %ticks).size &binvar2
if (*Average/><Name/>* iswm $bvar(&t,1-).text) {
$($+(%,stock.,%ticks,.msgtype),2) $+(7,$($+(%,stock.,%ticks,.ticker),2),) 04This symbol could not be found. $&
Please try again or search for it at12 %url
unset $+(%,stock.,$remove($sockname,stock.),*)
sockclose $sockname
}
elseif ($bfind(&binvar2,1,<query) != 0) && ($bfind(&binvar2,1,</query>) != 0) {
set $+(%,stock.,%ticks,.xml) $bvar(&binvar2,$+($bfind(&binvar2,1,<query),-,$calc($bfind(&binvar2,$bfind(&binvar2,1,<query),</query>) + 7))).text
var %change_percentchange $iif($left($stockparser(%ticks,change_percentchange),1) == +,03,04) $+ $replace($stockparser(%ticks,Change_PercentChange),$chr(32) $+ $chr(45) $+ $chr(32),$chr(44) $+ $chr(32))
$($+(%,stock.,%ticks,.msgtype),2) $+(7,$upper($stockparser(%ticks,symbol)),) $&
$parens($+(7,$replace($stockparser(%ticks,name),&,&,','))) $&
10Last: $stockparser(%ticks,LastTradePriceOnly) $&
$parens(%change_percentchange) $&
10Vol: $bytes($stockparser(%ticks,AverageDailyVolume),bd) $&
10Mkt. Cap: $stockparser(%ticks,MarketCapitalization) $&
10Link:12 %url
;The above section is meant to be customized yourself based on what options you want
;Look at the list of options below to customize yourself, just ask if you need help
;For example add in 10Daily Range: $parens($stockparser(%ticks,DaysRange)) $& for the daily range
unset $+(%,stock.,$remove($sockname,stock.),*)
sockclose $sockname
}
}
alias -l parens { return $+(01,$chr(40),$1-,01,$chr(41)) }
alias stockParser {
;Syntax $stockparser(ticks,DATA_TYPE) - Options for DATA_TYPE working as of v2.4 are:
;{Ask,AverageDailyVolume,Bid,BookValue,Change_PercentChange,Change,Currency,LastTradeDate,EarningsShareEPSEstimateCurrentYear,
;EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,MarketCapitalization,EBITDA,ChangeFromYearLow,
;PercentChangeFromYearLow,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime,LastTradePriceOnly,DaysRange,
;FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,
;ChangeFromFiftydayMovingAverage,PercentChangeFromFiftydayMovingAverage,Name,Open,PreviousClose,ChangeinPercent,PriceSales,
;PriceBook,PERatio,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,Symbol,ShortRatio,LastTradeTime,OneyrTargetPrice,
;Volume,YearRange,StockExchange,PercentChange}
var %xml $($+(%,stock.,$1,.xml),2)
if (*< $+ $2 $+ >* !iswm %xml) {
return $null
}
else {
return $remove($gettok(%xml,$calc($findtok(%xml,< $+ $2,1,62) + 1),62),</ $+ $2)
}
}
on *:start: .timerStockUpdate 1 60 StockUpdate
alias stockUpdate {
;echo -atc info 12[04Stock Script12] Checking for updates...
sockopen stockUpdate hawkee.com 80
}
on *:sockopen:stockUpdate: {
sockwrite -nt $sockname GET /snippet/9578/ HTTP/1.1
sockwrite -nt $sockname Host: hawkee.com
sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:stockUpdate: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
sockread %sockreader
if (*<title>* iswm %sockreader) {
tokenize 32 %sockreader
if ($StockVersion != $7) {
echo -atc info 12[04Stock Script12] Current: $StockVersion Latest: $7 Status: Please update at www.hawkee.com/snippet/9578/
}
unset %sockreader
sockclose $sockname
}
}
This is really an awesome script, we use it daily in my channel on my network.
Came back to get an update as it had stopped working. Updated the script but sometimes still get responses like this:
() Last: (2417wks 5days 10hrs ago) Change: () Mkt Cap: Link: http://finance.yahoo.com/q?s=tls.ax
Also just a note, I always have to edit the responses to be pub msgs and not notices, but I forget every time how to. Might be worth making that an easy option.
Should be fixed now! Good point about pub vs private, For version 2.4 change line 76 to be
set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $chan,msg $chan),msg $nick)
and it will always be private.
I've put that on my todo list to make that into an easy option and such will add that in to the next update whenever that happens.
@Fidel Cashflow yes - let me know here or in a private message the best way to reach you (email?) or where to find you on IRC and we can discuss the details. Happy to help!
You may have noticed that yahoo no longer allows DJI in the CSV because of some licensing stuff.
Would it be insanely difficult to grab all 30 of the DJI company's price fields and math out the average as a workaround?
Something like
;NON WORKING EXAMPLE
elseif ($2 == dji) {
;help!! insert code to grab 30 results here and return a total price of all 30
;list: MMM, AXP, T, BA, CAT, CVX, CSCO, KO, DD, XOM, GE, GS, HD, INTC, IBM, JNJ, JPM, MCD, MRK, MSFT, NKE, PFE, PG, TRV, UNH, UTX, VZ, V, WMT, DIS
var %indavg = total / 30
.msgtype DJI is currently at %indavg
}
I'm not sure if you can grab all these in one CSV file, or if a separate sock process is needed for each. Any help Would be most appreciated. Great work on this!
@abitterblu thanks for the heads up about this. I hadn't noticed ^DJI wasn't allowed for the CSV API. Hmm... does DIA work for you? It doesn't follow exactly, but it tracks pretty closely.
If you are looking for the exact points for the dow let me know and I can add up the prices from those 30 above.
@AddictedtoFM The API is now outdated and I need to do a rewrite. What new info would you like included? You mentioned market cap and ratios. Specifics? Perhaps just P/E ratio and mkt. cap?
@AddictedtoFM @mummy I did a complete rewrite of this script with the yahoo API instead. Results are posted above.
@AddictedtoFM i updated it to include the market cap in the result.
There aren't any ratios provided in the free API I am using. If you happen to know of a better API let me know (see below comments).
Glad you like it! Let me know if you need any other tweaks/suggestions.
Thank you so much! :D Would this API be any use to you? http://www.gummy-stuff.org/Yahoo-data.htm
@AddictedtoFM Now that I have said that, I actually don't feel like completely rewriting it with a different API (at least not right now). Sorry, and good luck with trading!
@illhawkthat seeing how I have a account with these people maybe you can use this link http://www.programmableweb.com/api/ameritrade
@rinzes That does look like it would work well, but I would need to login to TD Ameritrade in order to get access to their API.
I assume you don't want me doing that; if you do, PM me the login info.
@rinzes I just did some googling to see if I could find a better API than the current google resource it uses, but all of the financial APIs cost money so unless you want to pay for something this than no sorry.
If you find a good site that wouldn't be hard to parse then let me know.
@cptpan Glad it works. To get symbols on ASX attach .ax to the symbol e.g. compare /stock CBA to /stock CBA.AX
For the response to play in channel instead of noticing nick use the @command (@stock GOOG)
Let me know if you want anything else changed.
@cptpan Weird. Working for me, http://i.imgur.com/N64Xh.jpg - Can you tell me what version of mIRC you are running? I have only tested it with 7.25, but it should work with any recent one.
This doesn't return shlt?
§Stock§ () Last: () Change: (%) Link: http://ou.gs/stock_GOOG
@Sorasyn hey sorry I didn't reply. I was at the beach. You mean like as the title of the program? (what shows up on the taskbar) Sounds interesting and could be pretty useful.
this still doesn't work sir.
no stock amounts show up.