Retrieve cryptocurrencies current prices
https://github.com/ethauvin/cryptoprice
.circleci | ||
.github/workflows | ||
.idea | ||
examples | ||
gradle/wrapper | ||
src | ||
.gitattributes | ||
.gitignore | ||
.gitlab-ci.yml | ||
.travis.yml | ||
baseline.xml | ||
bitbucket-pipelines.yml | ||
build.gradle.kts | ||
gradlew | ||
gradlew.bat | ||
LICENSE.txt | ||
pom.xml | ||
README.md | ||
settings.gradle.kts |
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. |
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 something like:
{"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.