GithubHelp home page GithubHelp logo

handayu / csharp-exchange-rates Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oanda/csharp-exchange-rates

0.0 2.0 0.0 336 KB

OANDA Exchange Rates API client module for C#

License: MIT License

C# 100.00%

csharp-exchange-rates's Introduction

csharp-exchange-rates

OANDA Exchange Rates API client class for C#

This class provides an easy interface to the OANDA Exchange Rates API using C#. The API documentation page has a full reference of all the endpoints. This service requires you to sign up for a trial or paying subscription to obtain an API key.

Installation

Include ExchangeRatesAPI.cs to your project.

Usage

using System;
using Oanda;
using System.Collections.Generic;

public class OANDAExchangeRates_Main
{
    public static void Main(string[] args)
    {
        // Initializing the API
        var api = new ExchangeRates("<API KEY>");

        // Example of listing currencies

        Console.WriteLine("\n********** Listing Currencies:");
        var responseCurrencies = api.GetCurrencies();

        if (responseCurrencies.IsSuccessful)
        {
            foreach (var currency in responseCurrencies.Currencies)
            {
                Console.WriteLine("{0}:{1}", currency.Code, currency.Description);
            }
        }
        else
        {
            Console.WriteLine("There was an error with the request: {0}", responseCurrencies.ErrorMessage);
        }


        // Example of checking RemainingQuotes

        var responseRemaingQuotes = api.GetRemainingQuotes();

        Console.WriteLine("\n********** Remaining Quotes:");
        if (responseRemaingQuotes.IsSuccessful)
        {
            Console.WriteLine("Remaining quotes: {0}", responseRemaingQuotes.RemainingQuotes);
        }
        else
        {
            Console.WriteLine("There was an error with the request: {0}", responseRemaingQuotes.ErrorMessage);
        }


        // Example of retrieving rates by specifying multiple fields.

        var responseGetRatesWithFields = api.GetRates("USD",
                quote: "EUR",
                start: "2014-01-01",
                end: "2014-01-05",
                fields: new List<ExchangeRates.RatesFields> { ExchangeRates.RatesFields.Averages, ExchangeRates.RatesFields.Midpoint });

        if (responseGetRatesWithFields.IsSuccessful)
        {
            Console.WriteLine("\n********** Rates - Averages and Midpoints:");
            foreach (var quote in responseGetRatesWithFields.Quotes)
            {
                Console.WriteLine("From {0} to {1}\nQuote:{2} Ask:{3,10} MidPoint:{4,10} Bid:{5,10}",
                        responseGetRatesWithFields.Meta.EffectiveParams.StartDate.Value.ToShortDateString(),
                        responseGetRatesWithFields.Meta.EffectiveParams.EndDate.Value.ToShortDateString(),
                        quote.Key,
                        quote.Value.Ask,
                        quote.Value.Midpoint,
                        quote.Value.Bid);

            }
        }
        else
        {
            Console.WriteLine("There was an error with the request: {0}", responseGetRatesWithFields.ErrorMessage);
        }

        // Example of retrieving rates by specifying multiple quotes.

        var responseGetRatesForSeveralQuotes = api.GetRates("USD",
                quote: new List<string> {"EUR", "CHF"} ,
                date: "2014-01-01",
                fields: ExchangeRates.RatesFields.Averages);

        if (responseGetRatesForSeveralQuotes.IsSuccessful)
        {
            Console.WriteLine("\n********** Rates for USD/EUR and USD/CHF:");
            foreach (var quote in responseGetRatesForSeveralQuotes.Quotes)
            {
                Console.WriteLine("{0} Quote:{1} Ask:{2,10} Bid:{3,10}",
                        quote.Value.Date,
                        quote.Key,
                        quote.Value.Ask,
                        quote.Value.Bid);

            }
        }
        else
        {
            Console.WriteLine("There was an error with the request: {0}", responseGetRatesWithFields.ErrorMessage);
        }

        Console.ReadKey();

    }
}

Author

Pedro Melendez <[email protected]>

Copyright and License

This software is copyright (c) 2014 by OANDA Corporation and distributed under MIT License.

Release History

csharp-exchange-rates's People

Contributors

pmelendez avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.