Get Stock Quote

Discussion in 'Ruby' started by Vikash Kumar, Nov 6, 2006.

  1. Vikash Kumar

    Vikash Kumar Guest

    class RubyStock

    def initialize
    end

    require 'net/http'

    def RubyStock::getStocks(*symbols)
    Hash[*(symbols.collect{|symbol|[symbol,Hash[\
    *(Net::HTTP.get('quote.yahoo.com','/d?f=nl1&s='+symbol).chop\
    .split(',').unshift("Name").insert(2,"Price"))]];}.flatten)];
    end
    end
    myHash = RubyStock::getStocks("IBM","YHOO","RHAT","MSFT","AOL");
    myHash.each { |key,value,v1|
    print "Symbol is: #{key}...";
    print "FullName: #{value['Name']}...";
    print "Price: #{value['Price']}\n";
    }


    It generates the output like

    Symbol is: YHOO...FullName: "YAHOO INC"...Price: 26.18
    Symbol is: AOL...FullName: "AOL"...Price: 0.00
    Symbol is: MSFT...FullName: "MICROSOFT CP"...Price: 28.73
    Symbol is: RHAT...FullName: "RED HAT INC"...Price: 16.67
    Symbol is: IBM...FullName: "INTL BUSINESS MAC"...Price: 91.41


    As we know by appending 'o', 'c', 'v', 'g', 't1', d1' to the URL we can
    get opening price, change, high, low, time, date, etc.

    But I am unable to get Opening price, change, high, low, time, date etc.
    What should be the modification in code to achieve this. Please send me
    the code. Thanks in advance.

    --
    Posted via http://www.ruby-forum.com/.
    Vikash Kumar, Nov 6, 2006
    #1
    1. Advertising

  2. Charles L. Snyder, Nov 6, 2006
    #2
    1. Advertising

  3. Vikash Kumar

    Vikash Kumar Guest

    Charles L. Snyder wrote:
    > Vikash Kumar wrote:
    > -------
    >>
    >> But I am unable to get Opening price, change, high, low, time, date etc.
    >> What should be the modification in code to achieve this. Please send me
    >> the code. Thanks in advance.
    >>
    >> --
    >> Posted via http://www.ruby-forum.com/.

    >
    > You need to add the correct tags to your code - the tags are listed
    > here:
    > http://www.gummy-stuff.org/Yahoo-data.htm
    >
    > eg
    > http://finance.yahoo.com/d/quotes.csv?s=XOM BBDb.TO JNJ MSFT&f=sndp2hl1l1yr
    >
    > CLS



    Thanks it really works for me

    --
    Posted via http://www.ruby-forum.com/.
    Vikash Kumar, Nov 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. f
    Replies:
    6
    Views:
    523
  2. Replies:
    8
    Views:
    427
    Roland
    Jan 24, 2005
  3. plato399
    Replies:
    1
    Views:
    369
    Tim Anderson
    Apr 16, 2004
  4. savvy
    Replies:
    1
    Views:
    475
    Cowboy \(Gregory A. Beamer\)
    Jun 28, 2006
  5. parvathi
    Replies:
    0
    Views:
    427
    parvathi
    Feb 3, 2009
Loading...

Share This Page