Stock Quote Script (Financial Stock Data) v2.4

By illhawkthat on Jul 08, 2012

Screenshots

This script is now deprecated and in an unusable state due to an API change of Yahoo Finance.

  • Stock Quote Script (Financial Stock Data) v2.4
  • Made by nick1
  • Last edit May 7, 2016

USAGE:

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

DIRECTIONS:

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)

INFO:

Posted July 08, 2012
I can be contacted via a comment below
I can be found at irc.rizon.net:6667 name nick1

CHANGELOG:


--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),&amp;,&,&#39;,'))) $&
      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
  }
}

Comments

Sign in to comment.
cptpan   -  Jan 24, 2018

Update this already

FireRx  -  Mar 09, 2018

this still doesn't work sir.

no stock amounts show up.

illhawkthat  -  Mar 14, 2018

Hi guys, sorry for the delayed response. This script is unfortunately deprecated and won't receive future updates due to an API change for both yahoo and google finance. Sorry about the inconvenience!

cptpan  -  Aug 30, 2019

Damn that fuc king sucks brah

Sign in to comment

FireRx   -  Nov 28, 2017

Illhawkthat, could you please update the script so it will work again. Thanks you in advance,. ,:)

 Respond  
FireRx   -  Nov 08, 2017

Any chance this will be updated soon? Thanks

 Respond  
illhawkthat   -  Nov 03, 2017

Unfortunately, this script is now deprecated and in an unusable state due to an API change of Yahoo Finance.

FireRx  -  Nov 10, 2017

HAwk, can it be updated?

FireRx  -  Mar 09, 2018

illhawkthat,
Could you please make a new script snippet available for this stock quote bot.
thank you :)

Sign in to comment

jackcane   -  Oct 25, 2016

I have to spam the command to get it to output the stock. I would do @stock goog and nothing happens. It isn't delayed it just doesn't always return the stock

 Respond  
dma   -  May 03, 2016

Thanks For The Fix.. i really love it

illhawkthat  -  May 07, 2016

Should be working now in v2.4!

Sign in to comment

cptpan   -  May 03, 2016

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.

illhawkthat  -  May 07, 2016

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.

cptpan  -  May 07, 2016

Awesome! Thanks for fixing it. We literally use this every day and it's been in my bot for years now so I appreciate you keeping it updated (not many users do that these days!).

I've updated and it seems to be working fine.

Thanks again

Sign in to comment

Kent Baez   -  Apr 01, 2016

Excellent work, are you able to add premarket and after-hours quoting information as well?

illhawkthat  -  May 07, 2016

Unfortunately, no :( I tried to get that to work but it's not available in the API I have.

Sign in to comment

dma   -  Jan 06, 2016

IT DONT WORK ANYMORE ;(

dma  -  Jan 08, 2016

i was re learning the stock market.. im from NYC too lol go figure

illhawkthat  -  Jan 22, 2016

@dma I'll work on a fix for this thanks for letting me know

Sign in to comment

dma   -  Dec 18, 2015

this is geat to bad you dont have for sports

illhawkthat  -  Dec 18, 2015

@dma what would that look like? Might be able to help

dma  -  Dec 19, 2015

i would like one for one for sports, and maybe nsfw thanks in advance

illhawkthat  -  Dec 19, 2015

Can you give me an example input and output?

dma  -  Dec 19, 2015

inout !sports output like one below the other Giants Dallas Jets just random stuff like scores red zone TD's! something like that
NSFW on that for well you know cya soon dma

illhawkthat  -  Dec 22, 2015

Thanks for the suggestion - will try to get to this next time I code an mIRC project, have a few other things to do first though

Sign in to comment

Fidel Cashflow   -  May 15, 2015

Could I pay you some extra to tweak this for me and add changes?

Thanks

illhawkthat  -  May 16, 2015

@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!

Sign in to comment

cptpan   -  Dec 28, 2014

This script is awesome dude. Good work :)

illhawkthat  -  Dec 29, 2014

Thanks!

Sign in to comment

abitterblu   -  Dec 06, 2014

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!

illhawkthat  -  Dec 07, 2014

@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.

Sign in to comment

illhawkthat   -  Nov 02, 2013

@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?

illhawkthat  -  Nov 04, 2013

@AddictedtoFM @mummy I did a complete rewrite of this script with the yahoo API instead. Results are posted above.

Sign in to comment

AddictedtoFM   -  May 02, 2013

I hate to be a pain but would it be possible for you to adjust the script so it will display ratios and market caps as well? I'm afraid I don't have the scripting ability to do the modification myself.

Thank you so much for this really useful script. :)

illhawkthat  -  May 03, 2013

@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.

AddictedtoFM  -  May 05, 2013

Thank you so much! :D Would this API be any use to you? http://www.gummy-stuff.org/Yahoo-data.htm

illhawkthat  -  May 06, 2013

@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!

Sign in to comment

rinzes   -  Feb 10, 2013

@illhawkthat seeing how I have a account with these people maybe you can use this link http://www.programmableweb.com/api/ameritrade

illhawkthat  -  Feb 10, 2013

@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.

Sign in to comment

rinzes   -  Feb 07, 2013

@illhawkthat Thanks for your help... Any chance you could incorporate latest news for the stock symbol?

illhawkthat  -  Feb 08, 2013

@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.

Sign in to comment

rinzes   -  Feb 06, 2013

Tried your script and this is all that was returned.

[20:18] !stock goog
[20:18] [Stock Script] Checking for updates...
[20:18] [Stock Script] Current: v1.3 Latest: v1.3 Status: Up to date

illhawkthat  -  Feb 06, 2013

Resolved in chat. THanks for the comment.

Sign in to comment

cptpan   -  Aug 28, 2012

Yea I already edited those things so it displays to $chan etc.

Thanks for the heads up about the .AX

 Respond  
illhawkthat   -  Aug 27, 2012

@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.

 Respond  
cptpan   -  Aug 25, 2012

I've made a few edits, the response now plays in the channel instead of noticing the nick, and I've stripped some junk (symbols, colours etc) - Thanks for a good script!

 Respond  
cptpan   -  Aug 25, 2012

Upgraded my client and it works fine! Thanks :D

 Respond  
cptpan   -  Aug 24, 2012

The bot running it is 6.35. LOL. Maybe time to upgrade.

 Respond  
illhawkthat   -  Aug 22, 2012

@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.

 Respond  
cptpan   -  Aug 22, 2012

This doesn't return shlt?

§Stock§ () Last: () Change: (%) Link: http://ou.gs/stock_GOOG

 Respond  
illhawkthat   -  Jul 15, 2012

@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.

 Respond  
Sorasyn   -  Jul 08, 2012

Would be interesting if you could toggle an actual Stock Ticker to scroll across as a window title.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.