gregwinn / ystock

Yahoo market data, (realtime) stock data.
http://winn.ws
15 stars 3 forks source link

Getting error when bundle update #2

Closed Znow closed 11 years ago

Znow commented 11 years ago

Hi, since you have pushed a new version, you have changed the usual Ystock.find to Ystock::Yahoo.quote etc.

All though, my rake task used to work just fine, until I upgraded to the newest version.

rake aborted!
undefined method []' for nil:NilClass /home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:28:inblock (2 levels) in <top (required)>'
/home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:27:in each' /home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:27:inblock in <top (required)>'
/home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in eval' /home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in

'
Tasks: TOP => stock_info_update
(See full trace by running task with --trace)

# encoding: utf-8
desc "rake task to update stock info from Yahoo"
task :stock_info_update  => :environment do
  stock_data = Ystock::Yahoo.quote([
    "MAERSK-A.CO", # A.P. Møller Mærsk A
    "MAERSK-B.CO", # A.P. Møller Mærsk B
    "CARL-B.CO",   # Carlsberg
    "CHR.CO",      # Chr. Hansen Holding
    "COLOB.CO",   # Coloplast
    "DANSKE.CO",   # Danske Bank
    "DSV.CO",      # DSV
    "FLS.CO",      # FLSmidth & Co
    "GN.CO",       # GN Store Nord
    "LUN.CO",      # H. Lundbeck
    "JYSK.CO",     # Jyske Bank
    "NDA-DKK.CO",  # Nordea Bank
    "NOVO-B.CO",   # Novo Nordisk
    "NZYM-B.CO",   # Novozymes
    "PNDORA.CO",   # Pandora
    "TDC.CO",      # TDC
    "TOP.CO",      # Topdanmark
    "TRYG.CO",     # Tryg
    "VWS.CO",      # Vestas
    "WDH.CO"       # William Demant Holding
  ])

  stock_data.each do |key, hash|
    stockdata = StockData.where(:symbol => hash[:symbol]).last
    if stockdata.present?
      stockdata.update_attributes(:price => hash[:price], :change => hash[:change],:volume => hash[:volume])
    end
  end  

  puts "Rake[:stock_info_update] => StockData updated at #{Time.now.strftime("%D @ %H%M %z")}"
end

This is very urgent! I need the fix ASAP!

Atm, im running at version 0.3.8 just for getting this to work.

gregwinn commented 11 years ago

I will look into this for you.

gregwinn commented 11 years ago

This is now resolved with 0.4.3.

There was an issue with the way the a multi stock quote was returning... Old: [[{stock_data}], [{stock_data}]] Now: [{stock_data}, {stock_data}]

Please let me know if this resolves your issue!

Znow commented 11 years ago

Thanks alot man, great support!

Ill try it out later today and give you a notice.

Znow commented 11 years ago

Sorry, but the problem persists

rake aborted!                                                                                                                                                                                                                                                                     
undefined method `[]' for nil:NilClass                                                                                                                                                                                                                                            
/home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:28:in `block (2 levels) in <top (required)>'                                                                                                                                                                
/home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:27:in `each'                                                                                                                                                                                                
/home/action/workspace/advicecapital/lib/tasks/stock_info_update.rake:27:in `block in <top (required)>'                                                                                                                                                                           
/home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'                                                                                                                                                                                                       
/home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'                                                                                                                                                                                                     
Tasks: TOP => stock_info_update                                                                                                                                                                                                                                                   
(See full trace by running task with --trace)                                                                           
gregwinn commented 11 years ago

That is because hash is nil, in this case you are not using key so you can just simply run:

stock_data.each do |stock|
    stockdata = StockData.where(:symbol => stock[:symbol]).last
    if stockdata.present?
      stockdata.update_attributes(:price => stock[:price], :change => stock[:change],:volume => stock[:volume])
    end
end

I am going to close this issue, please reopen if you need additional help with getting the gem to run.