#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Using the yahoo finance gem


    I am trying to use the yahoo finance gem, but am having problems getting the information I want. When I get a quote it creates a hash, but there seems to only be one element which is a string with all the quote info. Is it possible to get the information individually as a fixnum? I am very new to ruby, so any help would be awesome.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2007
    Location
    India
    Posts
    3
    Rep Power
    0
    Here's a simple Ruby program that accesses Yahoo stock data:
    Code:
    require 'open-uri'
    require 'csv'
    
    unless ARGV.length == 1
      puts "Usage: jruby09.rb INTC"  
      exit  
    end
    
    url = "http://download.finance.yahoo.com/d/quotes.csv?s=#{ARGV[0]}&f=snl1d1t1c1ohgv&e=.csv"
    csv = CSV.parse(open(url).read)
    result = Array.new
    #parse csv data
    csv.each do |row|
      result += row
    end
    
    puts "Information current as of " + result[4] + " on " + result[3]
    puts result[0] +"'s (" + result[1] + ") last trade was - $" + result[2] + " (increase of " + result[5] + ")"
    puts
    puts "Opened at $" + result[6]
    puts "Range for the day $" + result[8] + " - $" + result[7]
    Is this what you are looking at? You can check this for more information on the kind of data you can download.

    Originally Posted by M-S-H
    I am trying to use the yahoo finance gem, but am having problems getting the information I want. When I get a quote it creates a hash, but there seems to only be one element which is a string with all the quote info. Is it possible to get the information individually as a fixnum? I am very new to ruby, so any help would be awesome.

IMN logo majestic logo threadwatch logo seochat tools logo