Retrieve cryptocurrencies current prices https://github.com/ethauvin/cryptoprice
Find a file
2021-05-25 22:59:15 -07:00
.circleci Added CIs. 2021-05-08 16:23:12 -07:00
.github/workflows Removed TravisCI. 2021-05-20 19:37:17 -07:00
.idea Cleanup 2021-05-16 23:03:10 -07:00
examples Added toCurrency(Locale). 2021-05-25 22:59:15 -07:00
gradle/wrapper Updated to Gradle 7.0.2 2021-05-16 07:52:48 -07:00
src Added toCurrency(Locale). 2021-05-25 22:59:15 -07:00
.gitattributes Initial commit. 2021-05-08 01:35:55 -07:00
.gitignore Initial commit. 2021-05-08 01:35:55 -07:00
.gitlab-ci.yml Using system wide Gradle. 2021-05-21 13:10:31 -07:00
baseline.xml Improved exceptions. 2021-05-09 17:54:48 -07:00
bitbucket-pipelines.yml Added more CIs 2021-05-08 23:28:06 -07:00
build.gradle.kts Added toCurrency(Locale). 2021-05-25 22:59:15 -07:00
detekt-baseline.xml Improved Javadocs. 2021-05-23 14:19:12 -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 snapshot badge. 2021-05-25 13:59:12 -07:00
README.md Added toCurrency 2021-05-25 17:57:46 -07:00
settings.gradle.kts Added maven publishing info. 2021-05-08 02:17:40 -07:00

License (3-Clause BSD) Release Maven Central Nexus Snapshot

Known Vulnerabilities Quality Gate Status GitHub CI 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.Companion.marketPrice

// ...

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

val eth = marketPrice("ETH", "EUR") // Ethereum in Euros
println(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. (USD, GBP, EUR, etc.)
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.

To display the amount as a fomatted currency use the toCurrency function:

val price = CryptoPrice("BTC", "EUR", 12345.67)
println(price.toCurrency()) // will print €12,345.67

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 something like:

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

See the examples for more details.

Gradle, Maven, etc.

To use with Gradle, include the following dependency in your build file:

dependencies {
    implementation("net.thauvin.erik:cryptoprice:0.9.0")
}

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