I signed up for a free tier API service with CoinMarketCap.com, to be able to quickly get the valuation of some cryptocurrencies I own. As it is, I use a web browser control to load up their page and go through a parsing process to extract the data I need, mostly the current values of a handful of their top 100 coins. But I discovered they offer a free API for personal use, and their API documentation has many examples of various languages. I can only code in Visual Basic, having been on this language since VB4. I tried to convert their C# example into VB, but the function they document fails in my VS2017 project, as I don't really understand the process or how to correctly integrate their C# sample into my VB.NET. If someone would kindly assist with understanding how I need to code this process?
Here is their C# example:
Code:using System;
using System.Net;
using System.Web;
class CSharpExample
{
private static string API_KEY = "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c";
public static void Main(string[] args)
{
try
{
Console.WriteLine(makeAPICall());
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}
static string makeAPICall()
{
var URL = new UriBuilder("https://undefined/v1/cryptocurrency/listings/latest");
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["start"] = "1";
queryString["limit"] = "5000";
queryString["convert"] = "USD";
URL.Query = queryString.ToString();
var client = new WebClient();
client.Headers.Add("X-CMC_PRO_API_KEY", API_KEY);
client.Headers.Add("Accepts", "application/json");
return client.DownloadString(URL.ToString());
}
}
============================================
And here is the conversion from Telerik Code Converter:
==================================Code:Imports System
Imports System.Net
Imports System.Web
Class CSharpExample
Private Shared API_KEY As String = "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c"
Public Shared Sub Main(ByVal args As String())
Try
Console.WriteLine(makeAPICall())
Catch e As WebException
Console.WriteLine(e.Message)
End Try
End Sub
Private Shared Function makeAPICall() As String
Dim URL = New UriBuilder("https://undefined/v1/cryptocurrency/listings/latest")
Dim queryString = HttpUtility.ParseQueryString(String.Empty)
queryString("start") = "1"
queryString("limit") = "5000"
queryString("convert") = "USD"
URL.Query = queryString.ToString()
Dim client = New WebClient()
client.Headers.Add("X-CMC_PRO_API_KEY", API_KEY)
client.Headers.Add("Accepts", "application/json")
Return client.DownloadString(URL.ToString())
End Function
End Class
According to their API documentation, they have a sandbox for testing the APIs, so I am guessing the correct address is :
Dim URL = New UriBuilder("https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest")
I signed up for and received my API key, while the sample key above is just that, a sample. So I have the sub and function and Private Shared API_KEY As String as converted, added into my project, but am at a loss on how to call the sub or function.