Retrieves the most recent exchange tickers for a coin

coin_tickers(coin_id, exchange_id, max_attempts = 3)

Arguments

coin_id

(character): ID of the coin of interest. An up-to-date list of supported coins and their IDs can be retrieved with the supported_coins() function.

exchange_id

(character): ID of the exchange to retrieve the data from. An up-to-date list of supported exchanges and their IDs can be obtained with the supported_exchanges() function.

max_attempts

(double, positive): specifies the maximum number of attempts to call the CoinGecko API (e.g., if the first call fails for some reason). Additional attempts are implemented with an exponential backoff. Defaults to 3.

Value

If the API call succeeds, the function returns a tibble with the following columns:

  • exchange_id (character): same as the argument exchange_id;

  • exchange_name (character): common name of the exchange;

  • coin_id (character): same as the argument coin_id;

  • name (character): common name of the coin;

  • base (character): symbol of the base currency in a trading pair;

  • target (character): symbol of the target currency in a trading pair;

  • trust_score (character): trust score of the trading pair ("green", "yellow", "red"; see this and this article on the CoinGecko website for details);

  • last_price (double): last price reported by this exchange for this trading pair;

  • last_fetch_at (POSIXct, UTC time zone): timestamp of when last_price was recorded;

  • last_traded_at (POSIXct, UTC time zone): timestamp of the most recent trade;

  • bid_ask_spread_percentage (double): percentage difference between the ask price (lowest price a seller is willing to sell for) and the bid price (highest price a buyer is willing to buy for; see Investopedia for details);

  • trading_volume_24h (double): trading volume (in target currency) recorded in the last 24 h (as of last_traded_at);

  • last_price_btc (double): last price reported by this exchange for this coin, expressed in Bitcoin;

  • last_price_eth (double): last price reported by this exchange for this coin, expressed in Ethereum;

  • last_price_usd (double): last price reported by this exchange for this coin, expressed in US dollar;

  • trading_volume_24h_btc (double): 24 hours trading volume expressed in Bitcoin (as of last_traded_at);

  • trading_volume_24h_eth (double): 24 hours trading volume expressed in Ethereum;

  • trading_volume_24h_usd (double): 24 hours trading volume expressed in US dollars;

  • cost_to_move_up_2percent_usd and cost_to_move_down_2percent_usd (double): 2% market depth (see this article on the CoinGecko website for details);

  • is_anomaly (logical): an indicator of whether the ticker's price is an outlier (see "Outlier detection" in Methodology on the GoinGecko website);

  • is_stale (logical): an indicator of whether the ticker's price has not been updated for a while (see "Outlier detection" in Methodology on the GoinGecko website);

  • trade_url (character): URL to this trading pair's page.

If no data can be retrieved (e.g., because of going over the API rate limit or mis-specifying the query parameters), the function returns nothing (NULL).

Details

This function is based on the public CoinGecko API, which has a rate limit of 10-30 calls per minute. Please keep this limit in mind when developing your applications.

Many exchanges offer a large number of target currencies, which necessitates pagination when querying the data. However, if the number of pages to retrieve is too large, the free version of the CoinGecko API fails due to hitting the rate limit. To avoid such failures, the coin_tickers() function retrieves up to 5 pages of data.

Examples

if (FALSE) {
r <- coin_tickers(coin_id = "cardano", exchange_id = "binance")
print(r)
}