CoinPaprika Swift SDK
The official Swift client library for the CoinPaprika API provides convenient, static access to cryptocurrency market data.Installation
Swift Package Manager (SPM)
Add the following package dependency to yourPackage.swift file or via Xcode:
CocoaPods
Add the following line to your Podfile and runpod install:
Quick Start
First, import the library:Coinpaprika.API object. All requests are asynchronous and return a Result type in a closure.
Using the Pro API
To use the Pro API, you must manually change the base URL in theConfiguration object before making any requests. This should be done once when your app launches.
Common Use Cases
Ticker Data for a Specific Coin
Coin Details
Historical Ticker Data
Note: Accessing historical data requires using the Pro API.Search
Error Handling
TheResult object in the completion handler provides a detailed RequestError case for failures.
Async/Await Support (iOS 13+ / macOS 10.15+)
The SDK supports modern concurrency withasync/await.
Available Methods
Global Data
global()- Get global market overview.
Coins
coins(additionalFields:)- List all coins.coin(id:)- Get coin by ID.coinTwitter(id:)- Get a coin’s Twitter timeline.coinEvents(id:)- Get coin events.coinExchanges(id:)- Get exchanges for a coin.coinMarkets(id:quotes:)- Get markets for a coin.
Tickers
tickers(quotes:page)- Get all tickers, with optional pagination.ticker(id:quotes:)- Get a specific ticker.historicalTicks(...)- Get historical tickers.
Exchanges
exchanges(quotes:)- List all exchanges.exchange(id:quotes:)- Get an exchange by ID.exchangeMarkets(id:quotes:)- Get markets for an exchange.
People & Tags
person(id:)- Get a person by ID.tags(additionalFields:)- List all tags.tag(id:additionalFields:)- Get a tag by ID.
Search & Tools
search(...)- Search across categories.priceConverter(...)- Convert between currencies.
FAQs
How do I use the Pro API in Swift?
How do I use the Pro API in Swift?
Set
Coinpaprika.Configuration.baseUrl to the Pro endpoint once at app startup; authenticate at the edge as needed.Where can I find coin IDs for methods like ticker(id:)?
Where can I find coin IDs for methods like ticker(id:)?
Use the Coverage Checker to obtain canonical IDs (e.g.,
btc-bitcoin).How do I fetch historical ticks/ohlcv?
How do I fetch historical ticks/ohlcv?
Configure the Pro base URL and call the relevant historical APIs with
start/end and quote.What is the recommended error handling?
What is the recommended error handling?
Inspect the failure case of
Result and map to app errors; for 429 responses, back off and retry.Requirements
- iOS 10.0+ / macOS 10.12+ / watchOS 3.0+ / tvOS 10.0+
- Swift 4.2+