The Gateway to Algorithmic and Automated Trading

5 Minute Developer: How to Build a Currency Converter in 5 Minutes

Xand : ChasCooper - 1st January 1970

The opinions expressed by this blogger and those providing comments are theirs alone, this does not reflect the opinion of Automated Trader or any employee thereof. Automated Trader is not responsible for the accuracy of any of the information supplied by this article.

Every five minutes, a business in the U.S. catches fire, someone in the UK swears, and a clock that took 5 years and £1 million to build before being unveiled by none other than Stephen Hawking, finally tells the time accurately for a second or two.

What will you do with your next 5 minutes?

Here's a thought: Why not build a real-time forex currency converter? Sound like fun? If so, give it a try using the steps below. Or, if you'd rather leave all the fun to someone else, why not just watch a video of us doing it?

Here's how it's done:

Step 1: Start a new Windows application project in Visual Studio.

Step 2: Create a Web reference to and call it XigniteCurrenciesService.

Step 3: On the Form1 design, drag and drop 3 text boxes, 2 labels, and a button, arranging them as shown in the picture. From left to right, give the text boxes the following names and default text: inputBaseAmount defaulting to 1000, inputBaseSymbol defaulting to USD, inputQuoteSymbol defaulting to EUR. One label should have a big equal sign in it and the other should have the name of labelQuoteAmount and zero for its text property. The button should read "Convert."

Real-Time Forex Currency Converter Built in 5 Minutes

Step 4: Double-click the button to create its click event handler, and give it the following 3 lines of code:

XigniteCurrenciesService.XigniteCurrencies XigniteCurrenciesWebService = new XigniteCurrenciesService.XigniteCurrencies();

XigniteCurrenciesService.ExchangeConversion Quote = XigniteCurrenciesWebService.ConvertRealTimeValue(inputBaseSymbol.Text, inputQuoteSymbol.Text, double.Parse(inputBaseAmount.Text));

labelQuoteAmount.Text = Quote.Result.ToString();

Step 5: Compile and run.

Authentication trouble? If you get an authentication error, it means you're not being authenticated from a cookie or your IP address. Don't worry. Just add 3 more lines after the first line of code to pass your authentication key through SOAP. Be sure to replace MYAUTHENTICATIONKEY with your own Xignite account authentication key. (Don't have an authentication key? Just sign up to get one. Your e-mail will be your initial authentication key.)

XigniteCurrenciesService.Header objHeader = new XigniteCurrenciesService.Header();

objHeader.Username = "MYAUTHENTICATIONKEY";

XigniteCurrenciesWebService.HeaderValue = objHeader;

Congratulations! You just spent the last five minutes far more productively than one U.S. business, one citizen of the UK, and one very expensive but very inaccurate clock.

Share and Enjoy: email Twitter Facebook LinkedIn Digg StumbleUpon Technorati Suggest to Techmeme via Twitter Google Bookmarks Live FriendFeed