Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange rate sometimes inexplicably 1.0 #4

Closed
jgarber opened this issue Jul 21, 2011 · 5 comments
Closed

Exchange rate sometimes inexplicably 1.0 #4

jgarber opened this issue Jul 21, 2011 · 5 comments

Comments

@jgarber
Copy link

jgarber commented Jul 21, 2011

I've dug through the code, but I can't figure out why sometimes in my Rails application, a few currencies come out with an exchange rate of 1.0.

In an initializer, I'm setting ISO4217::Currency.base_currency = 'GBP'

Yet somehow:

>> ISO4217::Currency.from_code("EUR")
=> #<ISO4217::Currency:0xb667a3c @exchange_rate=1.0, @exchange_currency="GBP", @symbol="€", @code="EUR", @name="Euro">
>> ISO4217::Currency.from_code("EUR").load_exchange_rate
=> 0.8814
>> ISO4217::Currency.from_code("EUR").exchange_rate
=> 1.0

I understand that load_exchange_rate doesn't actually store it in @exchange_rate, I just wanted to show that it's getting it successfully from Yahoo Finance. What I don't understand is how @exchange_rate got to be 1.0 in the first place. My only call to the Currency class is in a model...

  # Value of this currency in the default currency (defined in config/initializers/currencies.rb)
  def exchange_rate
    ISO4217::Currency.from_code(iso4217_code).exchange_rate
  end
@jgarber
Copy link
Author

jgarber commented Jul 21, 2011

I've got $100 for anyone who can replicate it and show a solution (not just a workaround).

@jgarber
Copy link
Author

jgarber commented Jul 21, 2011

Here's the smallest bit of code that will produce the inconsistent results. It only does it on my production server, not on my development machine (not even in production mode).

rails@li354-33:/srv/tinefcon-orders/current$ ./script/console production
Loading production environment (Rails 2.3.8)
>> ["AUD", "CAD", "EUR", "HKD", "PLN", "RUB", "ZAR", "GBP", "USD"].map {|c| ISO4217::Currency.from_code(c).exchange_rate }
=> [1.0, 0.6493, 0.8819, 0.0787, 0.2209, 0.0221, 1.0, 1.0, 505571776.0]
>> ["AUD", "CAD", "EUR", "HKD", "PLN", "RUB", "ZAR", "GBP", "USD"].map {|c| ISO4217::Currency.from_code(c).exchange_rate }
=> [1.0, 0.6493, 0.8819, 0.0787, 0.2209, 0.0221, 1.0, 1.0, 505571776.0]
>> exit
rails@li354-33:/srv/tinefcon-orders/current$ ./script/console production
Loading production environment (Rails 2.3.8)
>> ["AUD", "CAD", "EUR", "HKD", "PLN", "RUB", "ZAR", "GBP", "USD"].map {|c| ISO4217::Currency.from_code(c).exchange_rate }
=> [0.665, 0.6493, 0.8819, 0.0787, 1.0, 0.0221, 0.0906, 1.0, 0.6135]
>> exit

@jgarber
Copy link
Author

jgarber commented Jul 21, 2011

Mystery solved. It's actually coming from Yahoo that way.

?> ["AUD", "CAD", "EUR", "HKD", "PLN", "RUB", "ZAR", "GBP", "USD"].each {|c| puts get_yahoo_response(c) }
"AUDGBP=X",1.00,"N/A","N/A"
"CADGBP=X",0.6494,"7/21/2011","12:59pm"
"EURGBP=X",0.8821,"7/21/2011","12:59pm"
"HKDGBP=X",0.0787,"7/21/2011","12:59pm"
"PLNGBP=X",1.00,"N/A","N/A"
"RUBGBP=X",1.00,"N/A","N/A"
"ZARGBP=X",1.00,"N/A","N/A"
"GBPGBP=X",1.00,"N/A","N/A"
"USDGBP=X",0.6134,"7/21/2011","12:59pm"

Now to figure out why.

@jgarber
Copy link
Author

jgarber commented Jul 22, 2011

I'm going to use https://github.com/RubyMoney/eu_central_bank instead. So long and thanks for all the fish.

@jgarber jgarber closed this as completed Jul 22, 2011
@hexorx
Copy link
Owner

hexorx commented Jul 26, 2011

Sorry for the slow response, I have been planning my wedding and very swamped. I will take a look at Yahoo and see if they changed something or are just mucking it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants