Exchange rates

Exchange rate is defined as (VWAP-24H) last 24 hour (rolling window over time) Volume Weighted Average Price across multiple data sources listed on our platform. We are selecting and managing the data sources that are used in the calculation based on multiple factors to provide data of highest quality.

Algorithm is described below:

  1. Exchange rates are produced from quotes, trades, and metadata datasets.
  2. Symbols that are not data_type = "SPOT" are excluded from the calculation.
  3. Symbols from the data sources that were marked by us as not legitimate are excluded from the calculation.
  4. Quotes data where the spread is outside the range of <0$; 67%> are discarded. spreadPrc = (ask - bid) / ((ask + bid) / 2)
  5. The midpoint from the quote data is used as a pricing reference and it's weighted by the passive cumulative volume resting on the best prices.
  6. Volume from the trades is used to weight the midpoint prices in the VWAP24 algorithm.
  7. Midpoint data that has not been updated in the last 5 minutes and 1 second is discarded.
  8. The last 24-hour volume for each symbol is updated every 4 hours when approximately 20% of the data in the sliding window changes (also, the list of eligible markets is updated at the same time).
  9. Everywhere in the algorithm below, we are using asset pairs only from exchanges that have the highest legitimacy rank, and the rest of the exchanges are discarded. As we establish the highest-ranking exchanges that have this data for each asset pair, we ensure that the highest quality data is used for each of them. The rank used for asset pairing is carried over to the following steps.
  10. Every 1 second, we update VWAP24 data for every asset pair across all data sources.
  11. For each asset pair, we also discard data that is outside the 3 sigma range if there are at least 3 exchanges for this asset pair.
  12. From the VWAP24 data, we are creating a tree structure where node/vertex = asset and edge = rate.
  13. By traversing the tree structure using the BFS algorithm and our secret sauce, we are able to establish the final exchange rates.

Get specific rate GET

curl https://rest.coinapi.io/v1/exchangerate/BTC/USD \
  --request GET
  --header "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY"

The above command returns JSON structured like this:

{
  "time": "2017-08-09T14:31:18.3150000Z",
  "asset_id_base": "BTC",
  "asset_id_quote": "USD",
  "rate": 3260.3514321215056208129867667
}

Get exchange rate between pair of requested assets at specific or current time.

HTTP Request

GET /v1/exchangerate/{asset_id_base}/{asset_id_quote}?time={time}

URL Parameters

ParameterTypeDescription
asset_id_basestringRequested exchange rate base asset identifier. Full list available here
asset_id_quotestringRequested exchange rate quote asset identifier. Full list available here
timetimestringTime at which exchange rate is calculated (optional, if not supplied then current rate is returned)

Output variables

VariableDescription
timeTime in ISO 8601 of the market data used to calculate exchange rate
asset_id_baseExchange rate base asset identifier
asset_id_quoteExchange rate quote asset identifier
rateExchange rate between assets

Get all current rates GET

HTTP Request

GET /v1/exchangerate/{asset_id_base}?invert={invert}

curl https://rest.coinapi.io/v1/exchangerate/BTC?invert=false \
  --request GET
  --header "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY"

The above command returns JSON structured like this:

{
  "asset_id_base": "BTC",
  "rates" : [
    {
      "time": "2017-08-09T14:31:37.0520000Z",
      "asset_id_quote": "USD",
      "rate": 3258.8875417798037784035133948
    },
    {
      "time": "2017-08-09T14:31:36.7570000Z",
      "asset_id_quote": "EUR",
      "rate": 2782.5255080599273092901331567
    },
    {
      "time": "2017-08-09T14:31:36.7570000Z",
      "asset_id_quote": "CNY",
      "rate": 21756.295595926054627342411501
    },
    {
      "time": "2017-08-09T14:31:36.7570000Z",
      "asset_id_quote": "GBP",
      "rate": 2509.6024203799580199765804823
    }
  ]
}

Get the current exchange rate between requested asset and all other assets.

HTTP Request

GET /v1/exchangerate/{asset_id_base}

URL Parameters

ParameterTypeDescription
asset_id_basestringRequested exchange rates base asset identifier. Full list available here
filter_asset_idstring[]Comma or semicolon delimited asset identifiers used to filter response. (optional, full list available here)
invertboolTrue will invert all the rates (optional, if true then rates will be calculated as rate = 1 / actual_rate eg. USD/BTC as BTC/USD)

Output variables

VariableDescription
timeTime in ISO 8601 of the market data used to calculate exchange rates
asset_id_baseBase asset identifier for all rates
asset_id_quoteQuote asset identifier of specific rate
rateExchange rate between assets

Timeseries periods GET

curl https://rest.coinapi.io/v1/exchangerate/history/periods \
  --request GET
  --header "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY"

You can also obtain historical exchange rates of any asset pair, grouped into time periods.

Get full list of supported time periods available for requesting exchange rates historical timeseries data.

HTTP Request

GET /v1/exchangerate/history/periods

The above command returns JSON structured like this:

[
  {
    "period_id": "1SEC",
    "length_seconds": 1,
    "length_months": 0,
    "unit_count": 1,
    "unit_name": "second",
    "display_name": "1 Second"
  },
  {
    "period_id": "30MIN",
    "length_seconds": 1800,
    "length_months": 0,
    "unit_count": 30,
    "unit_name": "minute",
    "display_name": "30 Minutes"
  },
  {
    "period_id": "10DAY",
    "length_seconds": 864000,
    "length_months": 0,
    "unit_count": 10,
    "unit_name": "day",
    "display_name": "10 Days"
  }
]

Timeseries periods

Time unitPeriod identifiers
Second1SEC, 2SEC, 3SEC, 4SEC, 5SEC, 6SEC, 10SEC, 15SEC, 20SEC, 30SEC
Minute1MIN, 2MIN, 3MIN, 4MIN, 5MIN, 6MIN, 10MIN, 15MIN, 20MIN, 30MIN
Hour1HRS, 2HRS, 3HRS, 4HRS, 6HRS, 8HRS, 12HRS
Day1DAY, 2DAY, 3DAY, 5DAY, 7DAY, 10DAY

Output variables

VariableDescription
period_idPeriod identifier, used in other API calls
length_secondsSeconds part of period length
length_monthsMonths part of period length
unit_countPeriod length in units
unit_nameType of unit (second/minute/hour/day)
display_nameDisplay name of period length

Timeseries data GET

curl https://rest.coinapi.io/v1/exchangerate/BTC/USD/history?period_id=1MIN&time_start=2016-01-01T00:00:00&time_end=2016-02-01T00:00:00 \
  --request GET
  --header "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY"

Get the historical exchange rates between two assets in the form of the timeseries.

HTTP Request

GET /v1/exchangerate/{asset_id_base}/{asset_id_quote}/history

URL Parameters

ParameterTypeDescription
asset_id_basestringRequested exchange rates base asset identifier. Full list available here
asset_id_quotestringRequested exchange rates base asset identifier. Full list available here
period_idstringIdentifier of requested timeseries period (required, e.g. 5SEC or 1HRS, full list here)
time_starttimestringTimeseries starting time in ISO 8601 (required)
time_endtimestringTimeseries ending time in ISO 8601 (required)
limitintAmount of items to return (optional, mininum is 1, maximum is 100000, default value is 100, if the parameter is used then every 100 output items are counted as one request)

The above command returns JSON structured like this:

[
  {
    "time_period_start": "2021-03-02T00:00:00.0000000Z",
    "time_period_end": "2021-03-02T00:01:00.0000000Z",
    "time_open": "2021-03-02T00:00:00.0000000Z",
    "time_close": "2021-03-02T00:01:00.0000000Z",
    "rate_open": 49642.89075974334,
    "rate_high": 49642.89075974334,
    "rate_low": 49642.89075974334,
    "rate_close": 49642.89075974334
  },
  {
    "time_period_start": "2021-03-02T00:01:00.0000000Z",
    "time_period_end": "2021-03-02T00:02:00.0000000Z",
    "time_open": "2021-03-02T00:01:00.0000000Z",
    "time_close": "2021-03-02T00:02:00.0000000Z",
    "rate_open": 49649.71537706716,
    "rate_high": 49649.71537706716,
    "rate_low": 49649.71537706716,
    "rate_close": 49649.71537706716
  },
  ...
  {
    "time_period_start": "2021-03-02T23:59:00.0000000Z",
    "time_period_end": "2021-03-03T00:00:00.0000000Z",
    "time_open": "2021-03-02T23:59:00.0000000Z",
    "time_close": "2021-03-03T00:00:00.0000000Z",
    "rate_open": 48348.04226728628,
    "rate_high": 48348.04226728628,
    "rate_low": 48348.04226728628,
    "rate_close": 48348.04226728628
  }
]

Output variables

VariableDescription
time_period_startPeriod starting time (range left inclusive)
time_period_endPeriod ending time (range right exclusive)
time_openTime of first trade inside period range
time_closeTime of last trade inside period range
rate_openFirst rate inside period range
rate_highHighest rate inside period range
rate_lowLowest rate inside period range
rate_closeLast rate inside period range

Copyright 2022 COINAPI LTD or its affiliates. All rights reserved.
StatusPage: