How to get live (spot) gold price 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 gold price using C# programming language.

Instructions

  1. Get a free API key to use by signing up at Metalpriceapi.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. In the example below, you will get precious metal rates for gold, silver, palladium, and platinum.

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

 

Fetch live gold price in C# using ReSharp - NuGet version 107 and higher

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

 

Fetch live gold price in C# using ReSharp - NuGet version 106 and lower

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