Sample Code & Wrappers



Run the following command in the Package Manager Console:

PM> Install-Package CSharpExchangeRatesAPI

Sample Code

Here is a minimalistic example to access the API without the API wrapper:

using System;
using System.Web.Script.Serialization;

using System.Collections.Generic;

using System.IO;
using System.Net;

public class ExampleAPI
    public static void Main(string[] args)
            var url = "";
            var request = (HttpWebRequest)WebRequest.Create(url);

            string json = "";
            string credentialHeader = String.Format("Bearer <YOUR_API_KEY_HERE>");
            request.Method = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", credentialHeader);

            HttpWebResponse webresponse = (HttpWebResponse)request.GetResponse();

            var sw = new StreamReader(webresponse.GetResponseStream(), System.Text.Encoding.ASCII);
            json = sw.ReadToEnd();

            var response = (new JavaScriptSerializer()).Deserialize<Dictionary<string, List<object>>>(json);

            foreach (Dictionary<string,object> currency in response["currencies"])
                Console.WriteLine("{0} : {1}", currency["code"], currency["description"]);
        catch(Exception e)
            Console.WriteLine("Exception: " + e.Message);





npm install oanda-exchange-rates --save

Sample Code

Here is a minimalistic example to access the API without the API wrapper:

var https = require('https');

   hostname: '',
   path: '/rates/api/v1/rates/USD.json?date=2014-01-01&quote=EUR',
   headers: {
      Authorization: 'Bearer ' + MY_API_KEY
}, function(response) {
      if (response.statusCode === 200) {
          response.on('data', function(data) {



With cpanm:

cpanm WebService::OANDA::ExchangeRates

With cpan:

cpan WebService::OANDA::ExchangeRates

Manual Build:

As a last resort, you can manually install it. Download the tarball, untar it,
then build it:

    % perl Makefile.PL
    % make && make test

Then install it:

    % make install

Sample Code

If you wish to develop your own code to access the API, here is a simple example using the LWP::UserAgent Module:

use strict;
use warnings;

use Data::Dumper;
use HTTP::Headers;
use LWP::UserAgent;
use JSON::XS;

my $ua = LWP::UserAgent->new(
    verify_hostname => 0,
    default_headers => HTTP::Headers->new(
        Authorization => sprintf 'Bearer %s', 'MY_API_KEY'


my $response = $ua->get(
if ($response->is_success) {
    print Dumper JSON::XS::decode_json( $response->content );


SPORE is a method of defining an API using a JSON specification. See the Implementations section on Github for information on generating a client. As of this writing, there are SPORE clients for:

  • Clojure
  • Javascript
  • Lua
  • Nodejs
  • Perl
  • Python
  • Ruby

The URL for use with a SPORE client is: