How to get live (spot) forex rate using API in C#?

< Back to Guides

C# is a general-purpose, multi-paradigm programming language. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming disciplines. This tutorial is how to get live forex rate using C# programming language.

Instructions

  1. Get a free API key to use by signing up at forexrateapi.com and replace REPLACE_ME with your API key.
  2. Update base value to a currency or remove this query param.
  3. Update currencies value to a list of values or remove this query param. Below is an example usage for foreign exchange conversion API in use.

For 2 and 3, you can find this documented at Offical Documentation

 

Fetch live forex rate in C# using ReSharp - NuGet version 107 and higher

var options = new RestClientOptions("https://api.forexrateapi.com/v1/latest?api_key=REPLACE_ME&base=USD&currencies=EUR,JPY,CAD")
RestClient client = new RestClient(options);
RestRequest request = new RestRequest("", Method.Get);
RestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

 

Fetch live forex rate in C# using ReSharp - NuGet version 106 and lower

var client = new RestClient("https://api.forexrateapi.com/v1/latest?api_key=REPLACE_ME&base=USD&currencies=EUR,JPY,CAD");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);