0

I am just wondering if anyone knows of an online file that can be accessed from JavaScript or C# that contains up-to-date currency conversion rates on a daily basis, for example CAD ($) TO GBP (£)? Or any other method of achieving this goal?

Example code containing the hard-coded conversion rate:

 if (entity.Currency == "CAD ($)")
 {
     entity.UnitPrice = Convert.ToDecimal(entity.UnitPrice) * (decimal)0.524238;
     entity.Currency = "GBP (£)";
 }
Chris Mantle
  • 6,595
  • 3
  • 34
  • 48
Crezzer7
  • 2,265
  • 6
  • 32
  • 63
  • There are a number of currency conversion and currency pricing information APIs available online; please search for them and see if you can find one that's suitable for you. This question is off-topic for StackOverflow. – Chris Mantle Feb 19 '15 at 17:54
  • possible duplicate of [How do I get currency exchange rates via an API such as Google Finance?](http://stackoverflow.com/questions/3139879/how-do-i-get-currency-exchange-rates-via-an-api-such-as-google-finance) (also flagged as off-topic) – Filipe Borges Feb 19 '15 at 17:57

1 Answers1

1

You'll need to make use of an API if you want real-time updates. Open Exchange Rates API has tiered pricing, but they do seem to have a basic version which is free for personal use .

Otherwise you could make use of a library like Money.js that is essentially a wrapper to Open Exchange Rates API (looks like you still need to sign up for an account with Open Exchange).

Money.js seems super easy to use. They have an editor on their site so you can test out examples in JavaScript. This is how I tested it:

var price = 10;
fx.convert(price, {from: 'USD', to: 'GBP'});
//6.475340000000001
EnigmaRM
  • 7,523
  • 11
  • 46
  • 72
  • answers my initial question, any ideas how I use the money.js file? ive added it to my Project and now need to call it however using "fx." as it specifies does nothing – Crezzer7 Feb 19 '15 at 18:01
  • That is really a separate question. And I haven't used money.js before. But it looks like they have a good guide on how to get things set up: http://openexchangerates.github.io/money.js/#basic-install – EnigmaRM Feb 19 '15 at 18:03
  • I know it is, ill accept your answer when it lets me, thanks for the help – Crezzer7 Feb 19 '15 at 18:04
  • As the docs show you, you have to configure your rates and such (default rates). And then still signup for an account at Open Exchange it looks like. It seems to all be pretty well documented. – EnigmaRM Feb 19 '15 at 18:04
  • ahh, its not free, thought it was to good to be true – Crezzer7 Feb 19 '15 at 18:05
  • It looks like they have a more basic version for personal use, free: https://openexchangerates.org/signup/free – EnigmaRM Feb 19 '15 at 18:06