Realtime Cryptocurrency Rates API with coinlayer

By  on  
coinlayer

Last year when cryptocurrencies were gaining massively in value each month, I badly wanted to create a personal web project which would let me quickly buy and sell crypto outside of brokers like Coinbase; the problem I ran into was not having a reliable API for doing so.  I recently discovered coinlayer, an API which provides rates for hundreds of cryptocurrencies using values from dozens of cryptocurrency exchanges.

Quick Hits

  • coinlayer is free to use!
  • coinlayer provides rates for almost 300 cryptocurrencies
  • coinlayer provides rates from 25+ exchanges
  • coinlayer's API is well-designed and very easy to use
  • coinlayer supports JSONP

coinlayer

Using coinlayer

After getting your free API key, it's time to get started with querying the API for cryptocurrency rates.  Let's use cURL to grab the most basic rate result:

curl https://api.coinlayer.com/live?access_key=YOUR_KEY

You'll get a simple listing of cryptocurrency values for USD, which is the default base currency:

{
  "success": true,
  "terms": "https://coinlayer.com/terms",
  "privacy": "https://coinlayer.com/privacy",
  "timestamp": 1529571067,
  "target": "USD",
  "rates": {
    // ...
    "ADL": 121.5,
    "ADX": 0.427854,
    "ADZ": 0.02908,
    "AE": 2.551479,
    "AGI": 0.12555,
    "AIB": 0.005626,
    "AIDOC": 0.02605,
    // ...
  }
}

You can request crypto rates by date with from and to parameters, even providing an amount of a given cryptocurrency to multiply:

curl https://api.coinlayer.com/convert?from=BTC&to=ETH&amount=1&access_key=YOUR_KEY

You can also request data from a given time frame in the case you want to build a chart or track your profit:

# It's been a good month :)
curl https://api.coinlayer.com/timeframe?start_date=2018-07-01&end_date=2018-07-24&symbols=BTC,ETH&access_key=YOUR_KEY

/*
{
  "success": true,
  "terms": "https://coinlayer.com/terms",
  "privacy": "https://coinlayer.com/privacy",
  "timeframe": true,
  "start_date": "2018-07-01",
  "end_date": "2018-07-24",
  "target": "USD",
  "rates": {
    "2018-07-01": {
      "BTC": 6903.113849,
      "ETH": 383.02749
    },
    "2018-07-02": {
      "BTC": 7111.72678,
      "ETH": 387.273437
    },
    "2018-07-03": {
      "BTC": 7490.777653,
      "ETH": 421.655884
    },
    [...]
  }
}
*/

You can get extended rate information, like volume, high, and low using this API endpoint:

curl https://api.coinlayer.com/change?start_date=2018-07-01&end_date=2018-07-24&symbols=BTC,ETH&access_key=YOUR_KEY

/*
{
  "success": true,
  "terms": "https://coinlayer.com/terms",
  "privacy": "https://coinlayer.com/privacy",
  "change": true,
  "start_date": "2018-07-01",
  "end_date": "2018-07-24",
  "target": "USD",
  "rates": {
    "BTC": {
      "start_rate": 6903.113849,
      "end_rate": 9245.982724,
      "change": 2342.86887,
      "change_pct": 1.33939305
    },
    "ETH": {
      "start_rate": 383.02749,
      "end_rate": 670.440229,
      "change": 287.412739,
      "change_pct": 1.75037105
    }
  }
} 
*/

coinlayer goes the extra mile to provide support for JSONP:

// set endpoint and your API access key
const endpoint = 'live'
const access_key = 'YOUR_KEY';

// get the most recent exchange rates via the "live" endpoint:
$.ajax({
    url: 'https://api.coinlayer.com/api/' + endpoint + '?access_key=' + access_key,   
    dataType: 'jsonp',
    success: function(json) {
        // exchange rata data is stored in json.rates
        console.log(json.rates.BTC);
    }
});
coinlayer

I love having a service that provides cryptocurrency rates I can trust to be secure, reliable, and flexible.  APIs can be a nightmare but coinlayer's is so easy to use that you'll probably never need another crypto API again.  If only every API was so excellent!

Recent Features

  • By
    Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain).  Along with those assets are custom web fonts.  Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

Incredible Demos

  • By
    Redacted Font

    Back when I created client websites, one of the many things that frustrated me was the initial design handoff.  It would always go like this: Work hard to incorporate client's ideas, dream up awesome design. Create said design, using Lorem Ipsum text Send initial design concept to the client...

  • By
    Scrolling “Go To Top” Link Using Dojo

    One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!