Get Stock Quote

V

Vikash Kumar

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top