Swiftpack.co - Package - coinpaprika/coinpaprika-api-swift-client

Coinpaprika API Swift Client

Build Status codecov Version License Platform Carthage compatible Swift 5.0

Documentation | Repository | Installation

Usage

This library provides convenient way to use Coinpaprika.com API in Swift.

Coinpaprika delivers full market data to the world of crypto: coin prices, volumes, market caps, ATHs, return rates and more.

Import

Market Stats

import Coinpaprika

Coinpaprika.API.global().perform { (response) in
  switch response {
    case .success(let stats):
    // Successfully downloaded GlobalStats
    // stats.marketCapUsd - Market capitalization in USD
    // stats.volume24hUsd - Volume from last 24h in USD
    // stats.bitcoinDominancePercentage - Percentage share of Bitcoin MarketCap in Total MarketCap
    // stats.cryptocurrenciesNumber - Number of cryptocurrencies available on Coinpaprika
    case .failure(let error):
    // Failure reason as error
  }
}

Coins list

import Coinpaprika

Coinpaprika.API.coins().perform { (response) in
  switch response {
    case .success(let coins):
    // Successfully downloaded [Coin]
    // coins[0].id - Coin identifier, to use in ticker(id:) method
    // coins[0].name - Coin name, for example Bitcoin
    // coins[0].symbol - Coin symbol, for example BTC
    case .failure(let error):
    // Failure reason as error
  }
}

Ticker data for all coins

import Coinpaprika

Coinpaprika.API.tickers(quotes: [.usd, .btc]).perform { (response) in
  switch response {
    case .success(let tickers):
    // Successfully downloaded [Ticker]
    // tickers[0] - see the next method for Ticker properties
    case .failure(let error):
    // Failure reason as error
  }
}

Ticker data for selected coin

import Coinpaprika

Coinpaprika.API.ticker(id: "bitcoin-btc", quotes: [.usd, .btc]).perform { (response) in
  switch response {
    case .success(let ticker):
    // Successfully downloaded Ticker
    // ticker.id - Coin identifier, to use in ticker(id:) method
    // ticker.name - Coin name, for example Bitcoin
    // ticker.symbol - Coin symbol, for example BTC
    // ticker.rank - Position in Coinpaprika ranking (by MarketCap)
    // ticker.circulatingSupply - Circulating Supply
    // ticker.totalSupply - Total Supply
    // ticker.maxSupply - Maximum Supply
    // ticker.betaValue - Beta
    // ticker.lastUpdated - Last updated date
    //
    // Each Ticker could contain several Ticker.Quote (according to provided quotes parameter). To access to quote for given currency, use subscripting like:
    // - ticker[.usd] - Ticker.Quote in USD
    // - ticker[.btc] - Ticker.Quote in BTC
    // etc...
    //
    // So how to get this cryptocurrency price in USD and BTC?
    // - ticker[.usd].price - Coin price in USD
    // - ticker[.btc].price - Coin price in BTC
    //
    // Ticker.Quote contains following properties:
    // let currency: QuoteCurrency = .usd
    // - ticker[currency].price - Price
    // - ticker[currency].volume24h - Volume from last 24h
    // - ticker[currency].volume24hChange24h - Volume change in last 24h
    // - ticker[currency].marketCap - Market capitalization
    // - ticker[currency].marketCapChange24h - Market capitalization in last 24h
    // - ticker[currency].percentChange1h - Percentage price change in last 1 hour
    // - ticker[currency].percentChange12h - Percentage price change in last 12 hour
    // - ticker[currency].percentChange24h - Percentage price change in last 24 hour
    // - ticker[currency].percentChange7d - Percentage price change in last 7 days
    // - ticker[currency].percentChange30d - Percentage price change in last 30 days
    // - ticker[currency].percentChange1y - Percentage price change in last 1 year
    // - ticker[currency].athPrice - ATH price
    // - ticker[currency].athDate - ATH date
    // - ticker[currency].percentFromPriceAth - Percentage price change from ATH
    // - ticker[currency].volumeMarketCapRate - Volume/MarketCap rate
    case .failure(let error):
    // Failure reason as error
  }
}

Search

import Coinpaprika

Coinpaprika.API.search(query: "bitcoin", categories: [.coins, .exchanges, .icos, .people, .tags], limit: 20).perform { (response) in
  switch response {
    case .success(let searchResults):
    // Successfully downloaded SearchResults
    // searchResults.currencies - list of matching coins as [Search.Coin]
    // searchResults.icos - list of matching ICOs as [Search.Ico]
    // searchResults.exchanges - list of matching exchanges as [Search.Exchange]
    // searchResults.people - list of matching people as [Search.Person]
    // searchResults.tags - list of matching tags as [Search.Tag]
    case .failure(let error):
    // Failure reason as error
  }
}

More

Other endpoints could be found in CoinpaprikaAPI reference.

Installation

Swift Package Manager (SPM)

CoinpaprikaAPI is available through SPM. To install it, simply add the following dependency (for example in Xcode 11 built-in manager):

https://github.com/coinpaprika/coinpaprika-api-swift-client

Cocoapods

CoinpaprikaAPI is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CoinpaprikaAPI'

Run pod install to integrate CoinpaprikaAPI with your workspace.

Carthage

CoinpaprikaAPI is available through Carthage. To install it, simply add the following line to your Carthage file:

github "coinpaprika/coinpaprika-api-swift-client"  

Run carthage update to build the framework and drag the built CoinpaprikaAPI.framework into your Xcode project.

License

CoinpaprikaAPI is available under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 19

Dependencies

Used By

Total: 0

Releases

2.4.0 - 2019-08-19 07:36:42

  • Add an option to customize client User Agent
  • Add an option to provide custom Error Parser
  • [SPM] Add Coinpaprika prefix to Networking and NetworkingMocks modules

2.3 - 2019-06-25 12:56:52

  • Swift Package Manager
  • Add CoinType conformance to Ticker model

2.2 - 2019-05-15 14:46:41

  • Updated module name from CoinpaprikaAPI to Coinpaprika to allow use module prefix to resolve type ambiguity.

How to migrate?

Replace all import CoinpaprikaAPI occurrences with import Coinpaprika

More info in PR #7.

2.1.1 - 2019-04-10 13:19:49

  • Add support for custom request signer

2.1 - 2019-04-10 11:25:30

  • Convert to Swift 5
  • Add swift_versions (4.2 & 5.0) to podspec, required by Cocoapods 1.7
  • Add native Result type when compiled with Swift 5
  • Extract Request abstract to podspec CoinpaprikaAPI/Networking
  • Add support for Basic Auth and custom authorization headers in Request

2.0.6 - 2019-03-14 10:22:53

  • Add new properties (id, userImageLink , retweeetCount, likeCount) to Tweet model
  • Add description, websiteStatus, apiStatus properties to Exchange model
  • Add imgRev field (logo revision) to Coin model
  • Add createEvent endpoint
  • Add new top movers method with results number option
  • Add lead property to News model
  • Add top300 option to Top Movers
  • Add Person Tweets method
  • Expose TickerHistory and Ohlcv properties publicly (#5)

2.0.5 - 2019-01-23 11:58:45

New methods:

  • latestNews
  • historicalNews
  • topMovers
  • fiats

Other changes:

  • extended list of available Quotes (added fiat currencies)
  • switch to new links structure (with followers and other stats) in CoinExtended model
  • add imageLink to Tweet model
  • add marketCapChange24h & volume24hChange24h to GlobalStats model
  • add type to Coin model
  • add coinCounter & icoCounter fields to TagType protocol
  • add id property to Event model
  • fixed volumeMarketCapRate value

2.0.4 - 2018-12-13 12:52:40

Change type of following properties from Int64 to Decimal to be consistent with API Specification:

  • Exchange.reportedVolume24h, Exchange.adjustedVolume24h
  • GlobalStats.marketCapUsd, GlobalStats.volume24hUsd
  • Ohlcv.marketCap (+ add missing nullability to other numeric properties)
  • Ticker.circulatingSupply, Ticker.totalSupply, Ticker.maxSupply

2.0.3 - 2018-12-11 13:55:21

  • Change volume24h type from Int64 to Decimal (in Ticker.Quote)
  • Add nullability to url property in Event
  • Add Error to NSError bridge with HTTP Codes included
  • Add parent (Coin Platform) property to CoinExtended
  • Rename Person.Position model to Person.Project
  • Add coinName and coinSymbol to Person.Project

2.0.2 - 2018-11-27 14:32:00

  • Remove nullability from Exchange.fiats and Person.positions
  • Rename property Market.reportedVolumeShare to Market.reportedVolume24hShare
  • Rename property Person.Links.linkeding to Person.Links.linkedin
  • Add missing Event.description property
  • Add public visibility to property Person.Position.coinId and Person.Position.position

2.0.1 - 2018-11-22 08:37:23

  • Added manual CodingKeys mappings to speed up models parsing
  • Added common TagType protocol conformance to all models containing tag.id and tag.name
  • Changed OHLCV & tickers history endpoints url
  • Removed keyDecodingStrategy & keyEncodingStrategy properties (due to migration to CodingKeys)

2.0 - 2018-11-16 10:19:02

  • Quote (currency) - param in ticker & tickers endpoint
CoinpaprikaAPI.ticker(id: "btc-bitcoin", quotes: [.usd, .eth]).perform { (response) in
   let priceInEth= response.value?[.eth].price
   let priceInUsd = response.value?[.usd].price
} 
  • New tag & tags endpoints
  • New exchange & exchanges endpoints
  • New exchange markets endpoint
  • New coin details, coin exchanges and coin markets endpoints
  • New coin events endpoint
  • New coin twitter stream endpoint
  • New coin latest & historical OHLCV endpoint
  • New person details endpoint
  • New tickers history endpoint - to get historical ticker information for specific coin
  • Exposed JSON Encoder & Decoder used to handle API Models for convenient storing models in apps:
let ticker: Ticker = ...
let encoder = Ticker.encoder
let encodedData = try? encoder.encode(bitcoin)

1.1 - 2018-10-08 07:38:19

  • Add responseQueue: DispatchQueue option to perform method (default - main)

1.0.4 - 2018-09-28 11:36:51

  • add CoinpaparikaAPI.search endpoint
  • add Ico, Person, Exchange, Tag models

1.0.3 - 2018-09-26 16:39:53

  • add API errors parser and httpCodes validator

1.0.2 - 2018-09-26 13:16:54

  • support for macOS, tvOS and watchOS platform

- 2018-09-24 11:40:11

  • update documentation
  • add Carthage support