Stocks Script (Quote for Ticker Symbol) v1.4

Platform:  mIRC
Published  Jul 08, 2012
Updated  May 03, 2013

Screenshots

;StockQuote Script (Latest Price and Change) v1.4
;Made by nick1
;Last edit May 03, 2012

USAGE:
Used to deliver 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, !quote, and !price (uses Google 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
§Stock§ GOOG (Google Inc) Last: 585.98 (Jul 6, 2012) Change: -9.94 (-1.67%) Link: http://ou.gs/stock_GOOG

INFO:
Posted July 08, 2012
I can be contacted via reply.anonymouse+forward@gmail.com
I can be found at irc.rizon.net:6667 #rsbot_help name nick1
Quick Chat Link, feel free to leave a message for me https://qchat.rizon.net/?&channels=#rsbot_help&nick=Stocks.. or just to chat.

CHANGELOG:
**For a detailed changelog visit http://pastebin.com/qCn0hQAX
v1.0 (original July 08 2012) http://pastebin.com/BmmCaY6j -- Initial Upload (Quote and Info)
v1.4 (current May 03 2013) http://pastebin.com/b2ity3aq -- Added Market cap section to results

***********
--Let me know when its broken//what you want changed.
***********
--Feedback greatly appreciated

--If you don't like it lick it. ;StockQuote Script (Latest Price and Change) v1.4
;Made by nick1
;View online and report bugs at http://www.hawkee.com/snippet/9578
;Last edit May 03, 2013

alias -l stockVersion {
return v1.4
}
alias stock {
var %ticks $ticks
tokenize 32 $strip($1-)
if ($1) {
set $+(%,stock.,%ticks,.msgtype) echo -a
set $+(%,stock.,%ticks,.ticker) $1
if (!$istok(%stock.shortened,$1,44)) {
set $+(%,stock.,%ticks,.shorten) $upper($1)
sockopen $+(stocklink.,%ticks) ou.gs 80
}
sockopen $+(stock.,%ticks) www.google.com 80
}
elseif ($1 == $null) {
echo -act info 4Incorrect Syntax - Use10 /stock <ticker symbol>
}
}

on $*:text:/^[!@](stock|stocks|stockquote|price|q)(\s|$)/Si:#:{
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) {
set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $chan,notice $nick),msg $nick)
set $+(%,stock.,%ticks,.ticker) $2
if (!$istok(%stock.shortened,$2,44)) {
set $+(%,stock.,%ticks,.shorten) $upper($2)
sockopen $+(stocklink.,%ticks) ou.gs 80
}
sockopen $+(stock.,%ticks) www.google.com 80
}
elseif ($2 == $null) {
notice $nick 4Incorrect Syntax - Use10 $1 <ticker symbol>
}
}

on *:sockopen:stock.*: {
sockwrite -nt $sockname GET $+(/ig/api?stock=,$($+(%,stock.,$remove($sockname,stock.),.ticker),2)) HTTP/1.1
sockwrite -nt $sockname Host: www.google.com
sockwrite -nt $sockname $crlf
}

on *:SOCKREAD:stock.*: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
sockread &t
var %pos $bfind(&t,1,symbol data=)
var %pos2 $bfind(&t,%pos,<daylight_savings)
if (%pos != 0) {
var %ticks $remove($sockname,stock.)
set $+(%,stock.,%ticks,.xml) $bvar(&t,$+(%pos,-,$calc(%pos2 + 1))).text
if ($stockparser(%ticks,trade_timestamp) == Dec 31, 1969) {
$($+(%,stock.,%ticks,.msgtype),2) 4§Stock§7 $stockparser(%ticks,pretty_symbol) 04This symbol could not be found. Please try again or search12 $+(http://ou.gs/stock_,$upper($($+(%,stock.,%ticks,.ticker),2)))
unset $+(%,stock.,$remove($sockname,stock.),*)
sockclose $sockname
}
else {
var %colorcode $iif($left($stockparser(%ticks,change),1) == +,03,04)
var %mktcap $stockparser(%ticks,market_cap)
if ($len(%mktcap) <= 6) {
var %mktcap %mktcap $+ M
}
else {
var %mktcap $round($left($remove(%mktcap,$chr(46)),-5) $+ $chr(46) $+ $right($remove(%mktcap,$chr(46)),5),2) $+ B
}
if (%afterprice isnum) {
var %afterchange $iif($calc(%afterprice - $stockparser(%ticks,last)) >= 0,+ $+ $v1,$v1)
var %afterperc $calc(%afterchange / $stockparser(%ticks,last))
var %afterperc $iif($left(%afterperc,1) == -,$right(%afterperc,-1),%afterperc)
var %afterperc $round($calc(%afterperc * 100),2)
var %aftercode $iif($left(%afterchange,1) == +,03,04)
var %afterstring 7-10After Hours7-4 %afterprice $+(10Change:,%aftercode) %afterchange $+($openparens,%aftercode,$+(%afterperc,%),$closeparens)
}
$($+(%,stock.,%ticks,.msgtype),2) 4§Stock§7 $stockparser(%ticks,pretty_symbol) $+(,$openparens,07,$replace($stockparser(%ticks,company),&amp;,&,&#39;,'),$closeparens) $&
10Last:04 $stockparser(%ticks,last) $+(,$openparens,04,$stockparser(%ticks,trade_timestamp),$closeparens) $&
$+(10Change:,%colorcode) $stockparser(%ticks,change) $+($openparens,%colorcode,$+($stockparser(%ticks,perc_change),%),$closeparens) $&
%afterstring $&
10Mkt Cap:3 %mktcap $&
10Link:12 $+(http://ou.gs/stock_,$upper($($+(%,stock.,%ticks,.ticker),2)))
unset $+(%,stock.,$remove($sockname,stock.),*)
sockclose $sockname
}
}
}

on *:sockopen:stocklink.*: {
var %symbol $($+(%,stock.,$remove($sockname,stocklink.),.shorten),2)
sockwrite -nt $sockname GET $+(/index.php?url=http://www.google.com/finance?q=,%symbol,&alias=,stock_,%symbol) HTTP/1.1
set %stock.shortened $addtok(%stock.shortened,%symbol,44)
sockwrite -nt $sockname Host: ou.gs
sockwrite -nt $sockname $crlf
}

alias -l openparens { return $+(01,$chr(40)) }

alias -l closeparens { return $+(01,$chr(41)) }

alias -l stockParser {
;Syntax $stockparser(ticks,DATA_TYPE)
;Options for DATA_TYPE are {pretty_symbol,company,exchange,last,high,low,volume,avg_volume,market_cap,open,...
;y_close,change,perc_change,trade_timestamp,symbol_url,chart_url,isld_last,isld_trade_date_utc,isld_trade_time_utc}
return $gettok($($+(%,stock.,$1,.xml),2),$calc($findtok($($+(%,stock.,$1,.xml),2),$+(/><,$2-,$chr(32),data=),34) + 1),34)
}

on *:start: .timerStockUpdate 1 60 StockUpdate

alias stockUpdate {
echo -atc info 12[04Stock Script12] Checking for updates...
sockopen stockUpdate www.hawkee.com 80
}

on *:sockopen:stockUpdate: {
sockwrite -nt $sockname GET /snippet/9578/ HTTP/1.1
sockwrite -nt $sockname Host: www.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
echo -atc info 12[04Stock Script12] Current: $StockVersion Latest: $7 Status: $iif($StockVersion == $7,Up to date,Please update at www.hawkee.com/snippet/9578/)
unset %sockreader
sockclose $sockname
}
}

Comments

Sign in to comment.
AddictedtoFM   -  17 days ago
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  -  17 days ago
@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  -  14 days ago
Thank you so much! :D Would this API be any use to you? http://www.gummy-stuff.org/Yahoo-data.htm
illhawkthat  -  13 days ago
@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] <dutch> !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
@SunnyD 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  
SunnyD   -  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.