Live Stock Quotes

By tv3636 on Apr 05, 2009

There is one other script just like this but it's very old and doesn't work anymore, so I took the liberty of writing my own. The usage is very simple:

  • Paste the code into a blank remote file
  • type /stock to use (no <>)
    Example:
    /stock GOOG
    echoes Real Time Price of GOOG: $369.78

Note: The output is in yellow because I use a black background and I think it works best, but it can easily be changed. Just change the 8 to whatever color you want.

That's about it, let me know if there are any features I should add.

I was considering adding something that would automatically search for a symbol if none was found..but that could add a few more seconds onto the script.

/*
Stock Information Script by tv3636
Use: /stock [ticker symbol]
Example: /stock GOOG
That's it, let me know if there's any more info I should add or any info I should remove.
*/

alias stock {
  if ($sock(stock.socket)) .sockclose stock.socket
  set %stock.name $1
  sockopen stock.socket finance.yahoo.com 80
}
on *:SOCKOPEN:stock.socket: {
  sockwrite -nt $sockname GET /q?s= $+ %stock.name HTTP/1.1
  sockwrite -nt $sockname Host: finance.yahoo.com
  sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:stock.socket: {
  if ($sockerr) {
    echo $active Sockread error, try again!
  }
  else {
    sockread %stockread
    if (<span id="yfs_l91 isin %stockread || The document has moved isin %stockread || <span id="yfs_l90 isin %stockread ) {
      if (<span id="yfs_l91 isin %stockread) {
        set %stock.realprice $between(%stockread,<span id="yfs_l91_ $+ %stock.name $+ ">,</span>,1)
        echo $active 8Real Time Price of $upper(%stock.name) $+ : $ $+ %stock.realprice
      }
      elseif (The document has moved isin %stockread) {
        echo $active 8Sorry, no price found for $upper(%stock.name) $+ .
      }
      else {
        set %stock.realprice $between(%stockread,<span id="yfs_l90_ $+ %stock.name $+ ">,</span>,1)
        echo $active 8Real Time Price of $upper(%stock.name) $+ : $ $+ %stock.realprice
      }
      sockclose stock.socket
    }
  }
}

alias between { 
  noop $regex($1,/\Q $+ $2 $+ \E(.*?)\Q $+ $3 $+ \E/gi) 
  return $regml($4) 
}

Comments

Sign in to comment.
FireRx   -  Nov 13, 2017

Hawkee, what happened to the newer script from 2016?
are you working on a new one?

 Respond  
Jethro   -  Jul 29, 2011

Don't sweat it. It happens to every one of us who hasn't been in touch with a particular subject for a long while. I'm certain you'll pick up in no time with a brief review of MSL.

 Respond  
tv3636   -  Jul 29, 2011

heh, whoops. I'm definitely rusty!
thanks Jethro_

 Respond  
Jethro   -  Jul 29, 2011

It's $2, not $1. $1 is the trigger !stock.

 Respond  
tv3636   -  Jul 29, 2011

syrusmx: Add this bit of code for that functionality:

on *:TEXT:!stock *:#:{ stock $1 }

It's been a while since I've written mIRC code so I'm not 100% sure about that but I think that's all you'd need. And if you just want it for one channel replace the "#" with the channel name (i.e. #channel)

 Respond  
syrusmx   -  Jul 29, 2011

If this were edited to be a pub cmd usable by a bot, it would be perfect.

 Respond  
Aucun50   -  Apr 05, 2009

Don't know anything about sockets really but it looks nice, good job.

 Respond  
Kirby   -  Apr 05, 2009

Ya, I know. :d

 Respond  
tv3636   -  Apr 05, 2009

¯(°_o)/¯ = dunno lol

 Respond  
Kirby   -  Apr 05, 2009

Eh, ¯(°_o)/¯

 Respond  
tv3636   -  Apr 05, 2009

Ah I forgot I don't need to declare it first, thanks.
As for putting the echoes there, ¯(°_o)/¯

 Respond  
Kirby   -  Apr 05, 2009
    ;lol get it ^

Ya I get it. :D

Looks nice tv3636, but interesting how you just echoed directly on sockread and not on sockclose.
You don't need

    var %stockread

either, you can just directly sockread the %stockread.

 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.