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.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
Interceptor to your OkHttp client to inject the API key header when using Pro endpoints.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?
Call the historical OHLCV service method with required parameters; Pro access is required for history.
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