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:
- Exchange rates are produced from quotes, trades, and metadata datasets.
- Symbols that are not data_type = "SPOT" are excluded from the calculation.
- Symbols from the data sources that were marked by us as not legitimate are excluded from the calculation.
- Quotes data where the spread is outside the range of
<0$; 67%>
are discarded.spreadPrc = (ask - bid) / ((ask + bid) / 2)
- 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.
- Volume from the trades is used to weight the midpoint prices in the VWAP24 algorithm.
- Midpoint data that has not been updated in the last 5 minutes and 1 second is discarded.
- 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).
- 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.
- Every 1 second, we update VWAP24 data for every asset pair across all data sources.
- 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.
- From the VWAP24 data, we are creating a tree structure where node/vertex = asset and edge = rate.
- 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
Parameter | Type | Description |
---|---|---|
asset_id_base | string | Requested exchange rate base asset identifier. Full list available here |
asset_id_quote | string | Requested exchange rate quote asset identifier. Full list available here |
time | timestring | Time at which exchange rate is calculated (optional, if not supplied then current rate is returned) |
Output variables
Variable | Description |
---|---|
time | Time in ISO 8601 of the market data used to calculate exchange rate |
asset_id_base | Exchange rate base asset identifier |
asset_id_quote | Exchange rate quote asset identifier |
rate | Exchange 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
Parameter | Type | Description |
---|---|---|
asset_id_base | string | Requested exchange rates base asset identifier. Full list available here |
filter_asset_id | string[] | Comma or semicolon delimited asset identifiers used to filter response. (optional, full list available here) |
invert | bool | True 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
Variable | Description |
---|---|
time | Time in ISO 8601 of the market data used to calculate exchange rates |
asset_id_base | Base asset identifier for all rates |
asset_id_quote | Quote asset identifier of specific rate |
rate | Exchange 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 unit | Period identifiers |
---|---|
Second | 1SEC, 2SEC, 3SEC, 4SEC, 5SEC, 6SEC, 10SEC, 15SEC, 20SEC, 30SEC |
Minute | 1MIN, 2MIN, 3MIN, 4MIN, 5MIN, 6MIN, 10MIN, 15MIN, 20MIN, 30MIN |
Hour | 1HRS, 2HRS, 3HRS, 4HRS, 6HRS, 8HRS, 12HRS |
Day | 1DAY, 2DAY, 3DAY, 5DAY, 7DAY, 10DAY |
Output variables
Variable | Description |
---|---|
period_id | Period identifier, used in other API calls |
length_seconds | Seconds part of period length |
length_months | Months part of period length |
unit_count | Period length in units |
unit_name | Type of unit (second/minute/hour/day) |
display_name | Display 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
Parameter | Type | Description |
---|---|---|
asset_id_base | string | Requested exchange rates base asset identifier. Full list available here |
asset_id_quote | string | Requested exchange rates base asset identifier. Full list available here |
period_id | string | Identifier of requested timeseries period (required, e.g. 5SEC or 1HRS , full list here) |
time_start | timestring | Timeseries starting time in ISO 8601 (required) |
time_end | timestring | Timeseries ending time in ISO 8601 (required) |
limit | int | Amount 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
Variable | Description |
---|---|
time_period_start | Period starting time (range left inclusive) |
time_period_end | Period ending time (range right exclusive) |
time_open | Time of first trade inside period range |
time_close | Time of last trade inside period range |
rate_open | First rate inside period range |
rate_high | Highest rate inside period range |
rate_low | Lowest rate inside period range |
rate_close | Last rate inside period range |