Simple Bitcoin Calculator

Introduction

Hello, it's crypto time!!! I am going to show you how to use Bitcoin exchange rates and currency conversion that supports all major currencies. I am currently using Coindesk which provides API to make data programmatically available to others. 

To use the  API, you don't need to register, it is free!

You can check out the supported currencies available on their website. To use the endpoint, you make a request to:


The code parameter accepts a valid ISO 4217 currency code 

A sample request















Take a look at the result, you would notice the rate and the rate_float object, which contains the exchange rate for the local currency to BTC. Below is a formula to convert BTC to your local currency.

Formula = BTC Amount * Exchange Rate = Local currency Price

Building the Bitcoin Calculator

Using a client to consume the JSON data returned from the endpoint is the first thing to do. You can use Asp.Net HttpClient class, Jquery getJson() function which we are going to use here or you can use others you already know.

$.getJSON( "https://api.coindesk.com/v1/bpi/currentprice/usd.json", function( data) {
   var amountInBtc = 0.005; //convert 0.005 btc to usd
   var exchangeRate = parseInt(data.bpi.USD.rate_float);
   var amount = amountInBtc * exchangeRate;
   console.log(amount);
});


Use it on your projects to convert BTC to your local currency. Coin desk also supports other currencies too which is available on their website. Modify the code to suit your needs!

Follow Me On: 

Comments

Post a Comment

Popular posts from this blog

Solved: Jwt Authentication in Asp.Net Web Api And Mvc

Sending Notification Message with Firebase with JavaScript and .Net client

Using SignalR with Unity