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
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

Incredible Demos

  • By
    Chris Coyier’s Favorite CodePen Demos IV

    Did you know you can triple-heart things on CodePen? We’ve had that little not-so-hidden feature forever. You can click that little heart button on any Pen (or Project, Collection, or Post) on CodePen to show the creator a little love, but you can click it again...

  • By
    JavaScript Speech Recognition

    Speech recognition software is becoming more and more important; it started (for me) with Siri on iOS, then Amazon's Echo, then my new Apple TV, and so on.  Speech recognition is so useful for not just us tech superstars but for people who either want to work "hands...

Discussion

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