- Home /
Question by
zereda-games · Jan 13, 2021 at 03:25 PM ·
currency
Is there a way to display current live currency data in your app? if so, how and where to i access online data.
Say i wanted to display the difference of 2 said currencies lets just say Canadian Dollar Vs United States Dollar for this example. is there a way of accessing an online page of currencies like i dunno maybe something like 'www1.oanda.com' for instance (maybe there's a better place) to pull the current values from when needed? I've seenthis on apps like coinbase and stuff so it would be kind of neat to learn how to do.
Comment
Best Answer
Answer by andrew-lukasik · Jan 13, 2021 at 03:55 PM
Yes. Simplest way to do that is to use REST API. Find a service provider by googling something like "currency REST API". Then call that uri:
using System.Collections;
using UnityEngine.Networking;
IEnumerator Start ()
{
string uri = "https://api.coindesk.com/v1/bpi/currentprice.json";
var delay = new WaitForSeconds( 10f );
while( true )
{
var www = UnityWebRequest.Get( uri );
var asyncOp = www.SendWebRequest();
while( asyncOp.isDone==false )
yield return null;
if( www.result==UnityWebRequest.Result.ConnectionError )
{
Debug.LogWarning( www.error );
}
else
{
string response = www.downloadHandler.text;
Debug.Log($"Response: {response}");
}
yield return delay;
}
}
Effin eh thank person thats great to know! Thanks a bunch!!!!