Develop Bitcoin Price Feed Plugin Using .Net Core

Crypto currency has become household topic of discussions. Especially with how NFT (non-fungible tokens) assets are being talked about, more and more people want to know about crypto currencies. There are a lot of crypto currencies out there. But the currency that people mostly talk about is Bitcoin. A lot more people are trading Bitcoins and other crypto currencies. A topic that people have on their mind is to know the current price of Bitcoin.

I decided to develop a plugin for my latest Blog framework. This plugin fetches current Bitcoin price from CoinDesk.

Bitcoin price plugin

See it in action at World of Hobby Craft blog site.

You can get the latest price by making a GET request for This returns the data in following Json structure.

{"time":{"updated":"Sep 18, 2013 17:27:00 UTC",
"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index. Non-USD currency 
data converted using hourly conversion rate from",
"description":"United States Dollar",
"description":"British Pound Sterling",

The price data is returned as a dictionary of currency and rates inside bpi property. Here is the code that I have put together fetch the feed and then serialize into a proper C# class.

Feed Data Structures

public record CoindeskFeedModel:BaseAmgrModel
        public PriceIndexUpdateTime UpdateTime { get; set; }
        public Dictionary PriceIndexValueDictionary { get; set; }

        public record PriceIndexUpdateTime
            public string UpdateTimeUtc { get; set; }
        public record PriceIndexValue
            public string Code { get; set; }
            public string Description { get; set; }
            public string Symbol { get; set; }
            public double Rate { get; set; }

.Net Core Http Client To Fetch Bitcoin Price

public class BitcoinPriceController: BasePluginController
        #region Fields

        private readonly IHttpClientFactory _httpClientFactory;
        private readonly ILogger _logger;
        private readonly CoindeskFeedSettings _feedSettings;
        private const string PriceIndexFeedUrl = "";

        public BitcoinPriceController(IHttpClientFactory httpClientFactory,
            CoindeskFeedSettings feedSettings,
            ILogger logger)
            _httpClientFactory = httpClientFactory;
            _feedSettings = feedSettings;
            _logger = logger;
        public async Task<IActionResult> LatestPrice()
                var httpClient = _httpClientFactory.CreateClient(AmgrHttpDefaults.DefaultHttpClient);
                var priceFeed = await httpClient.GetStringAsync(string.IsNullOrEmpty
                  (_feedSettings.PriceFeedUrl) ? PriceIndexFeedUrl: _feedSettings.PriceFeedUrl);
                var coinDeskPriceIndexModel = JsonConvert.DeserializeObject<CoindeskFeedModel>(priceFeed);
                var priceIndexValues = new List<BitcoinPriceModel>();
                if (null == coinDeskPriceIndexModel) return Json(priceIndexValues);
                foreach (var priceIndexModel in coinDeskPriceIndexModel.PriceIndexValueDictionary)
                    var dictionaryValue = coinDeskPriceIndexModel.PriceIndexValueDictionary[priceIndexModel.Key];
                    priceIndexValues.Add(new BitcoinPriceModel
                        UpdatedAtUtc = coinDeskPriceIndexModel.UpdateTime.UpdateTimeUtc,
                        Price = dictionaryValue.Rate,
                        Currency = dictionaryValue.Code,
                        CurrencySymbol = dictionaryValue.Symbol

                return Json(priceIndexValues);
            catch (Exception ex)
                await _logger.ErrorAsync($"Error getting latest bitcoin price", ex);

            return Json("");

I have wrapped the client side implementation in a jQuery ajax call that refreshes the data on a fixed interval.

<script asp-location="Footer" type="text/javascript">
    var bitCoinPriceUpdateInProgress = false;
    function getBitcoinPrices() {
        if (bitCoinPriceUpdateInProgress) return;
        bitCoinPriceUpdateInProgress = true;
            cache: false,
            type: "POST",
            url: "@Html.Raw(Url.RouteUrl("BitcoinPriceFeed"))",
            success: function (data, textStatus, jqXHR) {
                bitCoinPriceUpdateInProgress = false;
                if (null != data && data.length !== 0) {
                    var priceListElement = $("#bitcoin-price-list");
                    var updateTimeElement = $("#bitcoin-price-updatetime");
                    for (var i = 0; i < data.length; i++) {
                        var priceIndexValue = data[i];
                             ($("<li class='g-mb-2'><strong class='d-block g-font-size-30 g-line-height-1_2'>" 
                           + priceIndexValue.CurrencySymbol + priceIndexValue.Price + "</strong></li>"));
            error:function(jqXHR) {
                bitCoinPriceUpdateInProgress = false;
            complete: function (jqXHR, textStatus) {
                bitCoinPriceUpdateInProgress = false;
                setTimeout(getBitcoinPrices, @refreshFrequency);

    setTimeout(getBitcoinPrices, 0);

The plugin is developed along the guidelines of nopCommerce platform. If you are interested in including this in your nopCommerce plugin list, feel free to contact me. I can share the complete plugin with you. You will to have make some changes to adapt to namespace used by nopCommerce framework.




21.3 °C / 70.4 °F

weather conditions Clouds

Monthly Posts

Blog Tags