Retrieve cryptocurrencies current prices https://github.com/ethauvin/cryptoprice
Find a file
2021-05-08 20:11:54 -07:00
.circleci Added CIs. 2021-05-08 16:23:12 -07:00
examples Added API reference. 2021-05-08 20:10:48 -07:00
gradle/wrapper Initial commit. 2021-05-08 01:35:55 -07:00
src Added examples 2021-05-08 15:54:16 -07:00
.gitattributes Initial commit. 2021-05-08 01:35:55 -07:00
.gitignore Initial commit. 2021-05-08 01:35:55 -07:00
.travis.yml Added CIs. 2021-05-08 16:23:12 -07:00
baseline.xml Added examples 2021-05-08 15:54:16 -07:00
build.gradle.kts Changed to Java 11 (LTS) compabitility. 2021-05-08 20:11:54 -07:00
gradlew Initial commit. 2021-05-08 01:35:55 -07:00
gradlew.bat Initial commit. 2021-05-08 01:35:55 -07:00
LICENSE.txt Initial commit. 2021-05-08 01:35:55 -07:00
pom.xml Added maven publishing info. 2021-05-08 02:17:40 -07:00
README.md Added readme. 2021-05-08 19:57:42 -07:00
settings.gradle.kts Added maven publishing info. 2021-05-08 02:17:40 -07:00

License (3-Clause BSD) Release Maven Central

Known Vulnerabilities Quality Gate Status Build Status CircleCI

Retrieve cryptocurrencies current market prices

A simple Kotlin/Java/Android implementation of the spot price Coinbase Public API.

Examples (TL;DR)

import net.thauvin.erik.crypto.CryptoPrice

// ...

val btc = marketPrice("BTC") // Bitcoin
print(btc.amount)

val eth = marketPrice("ETH", "EUR") // Ethereum in Euros
price(eth.amount)

Market Price

The marketPrice function defines the following parameters:

marketPrice(
    base: String, // Required 
    currency: String = "USD",
    date: LocalDate? = null,
)
Parameters Description
base The cryptocurrency ticker symbol (BTC, ETH, ETH2, etc.)
currency The fiat currency ISO 4217 code.
date The LocalDate for historical price data.

A CryptoPrice is returned defined as follows:

CryptoPrice(val base: String, val currency: String, val amount: Double)

The parameter names match the Coinbase API.

Extending

A generic apiCall() function is available to access other API data endpoints. For example to retried the current buy price of a cryptocurrency:

apiCall(paths = listOf("prices", "BTC-USD", "buy"), params = emptyMap())

will return:

{"data":{"base":"BTC","currency":"USD","amount":"58977.17"}}

See the examples for more details.

Gradle, Maven, etc.

Instructions for using with Gradle, Maven, Ivy, etc. can be found on Maven Central.