CoinPaprika Kotlin SDK
The official Kotlin library for the CoinPaprika API provides a set of Retrofit interfaces and data models to access cryptocurrency market data. This allows for easy integration into any Android or Kotlin project that uses Retrofit for networking. This library provides the building blocks, not a pre-configured client. You are responsible for creating and configuring your ownRetrofit instance.
Installation
Add the library dependency to your module’sbuild.gradle or build.gradle.kts file.
INTERNET permission in your AndroidManifest.xml.
Quick Start
1. Create a Retrofit Instance
First, configure and build aRetrofit instance. You must provide the base URL and a converter factory.
2. Create a Service
Use your Retrofit instance to create an implementation of one of the library’s service interfaces, such asTickersService.
3. Make an API Call
Now you can use the service within a coroutine to make API calls.Authenticating with a paid plan
Paid plans (Starter / Pro / Business / Ultimate / Enterprise) live on a separate hostname,https://api-pro.coinpaprika.com/v1/, and require an API key in the Authorization header. The library doesn’t provide a Pro-aware base URL constant; configure it on your Retrofit builder along with an OkHttp Interceptor that injects the key on every request.
RetrofitClient from Quick Start pointed at COINPAPRIKA_BASE_URL without an interceptor.
Available Services
This library provides the following Retrofit service interfaces.CoinsService
Used to fetch coin details and history.getCoins(): Lists all available coins.getCoin(id): Retrieves details for a specific coin ID.getCoinEvents(id): Gets events related to a coin.getCoinExchanges(id): Gets exchanges where a coin is listed.getCoinMarkets(id, quotes): Gets market data for a coin.getCoinTweets(id): Gets the latest tweets for a coin.getCoinOHLCV(id, quotes): Gets the latest OHLCV data.getHistoricalCoinOHLCV(...): Gets historical OHLCV data.
ExchangesService
Used to fetch data about exchanges.getExchanges(quotes): Lists all exchanges.getExchange(id, quotes): Retrieves details for a specific exchange.getExchangeMarkets(id, quotes): Gets all markets for a specific exchange.
GlobalStatsService
Used to get global market data.getGlobalStats(quotes): Retrieves global cryptocurrency market statistics.
PeopleService
Used to get information about people in the crypto space.getPerson(id): Retrieves details for a specific person by ID.
SearchService
Used to perform searches.search(...): Searches for coins, exchanges, people, and more.
TagsService
Used to get information about tags.getTags(sortBy): Lists all tags.getTag(id): Retrieves details for a specific tag.
TickersService
Used to fetch ticker price and market data.getTicker(id, quotes): Retrieves the ticker for a specific coin ID.getTickers(quotes, page): Lists tickers for all coins.
FAQs
How do I authenticate with Retrofit?
How do I authenticate with Retrofit?
Add an OkHttp
Interceptor that adds the Authorization header (bare key, no Bearer prefix) and point your Retrofit builder at https://api-pro.coinpaprika.com/v1/. See the “Authenticating with a paid plan” section above.Where do I find coin IDs for service methods?
Where do I find coin IDs for service methods?
Use the Coverage Checker to discover canonical IDs (e.g.,
btc-bitcoin).How do I request historical OHLCV?
How do I request historical OHLCV?
Historical OHLCV requires a paid plan. Use the
ProRetrofitClient from the Pro authentication section, then call CoinsService.getHistoricalCoinOHLCV(…) with start/end in ISO date format and a quote like “usd”.What’s the recommended error handling?
What’s the recommended error handling?
Catch
HttpException for non-2xx responses (e.g., 404, 429) and IOException for network failures; apply backoff before retries.Error Handling
When using this library, you should wrap your API calls in atry-catch block to handle potential exceptions, such as HttpException from Retrofit for non-2xx responses or IOException for network failures.
Requirements
- Kotlin-enabled project (Android or pure Kotlin)
retrofit2moshi(or another JSON converter)okhttp3