# Get Stock Quote

**URL:** <https://www.ruby-forum.com/t/get-stock-quote/74413>\
**Category:** Ruby\
**Created:** [November 6, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/get-stock-quote/74413 "2006-11-06T12:50:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikashkumar051](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/eb9ed0/32.png) [@vikashkumar051](https://www.ruby-forum.com/u/vikashkumar051)\
**Post date:** [November 6, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/get-stock-quote/74413/1 "2006-11-06T12:50:35Z")

</div>

class RubyStock

def initialize  
end

require ‘net/http’

def RubyStock::getStocks(_symbols)  
Hash[_(symbols.collect{|symbol|[symbol,Hash[  
\*(Net::HTTP.get(‘[quote.yahoo.com](http://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.

---

<div class="post-metadata">

**Author:** ![vikashkumar051](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/eb9ed0/32.png) [@vikashkumar051](https://www.ruby-forum.com/u/vikashkumar051)\
**Post date:** [November 7, 2006, 11:06am UTC](https://www.ruby-forum.com/t/get-stock-quote/74413/2 "2006-11-07T11:06:20Z")

</div>

## 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/](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](http://www.gummy-stuff.org/Yahoo-data.htm)

eg  
[http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=sndp2hl1l1yr](http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=sndp2hl1l1yr)

CLS

---

<div class="post-metadata">

**Author:** ![vikashkumar051](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/eb9ed0/32.png) [@vikashkumar051](https://www.ruby-forum.com/u/vikashkumar051)\
**Post date:** [November 8, 2006, 12:30pm UTC](https://www.ruby-forum.com/t/get-stock-quote/74413/3 "2006-11-08T12:30:04Z")

</div>

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/](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](http://www.gummy-stuff.org/Yahoo-data.htm)
> 
> eg  
> [http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=sndp2hl1l1yr](http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=sndp2hl1l1yr)
> 
> CLS

Thanks it really works for me
