cryptoprice/README.md

3.5 KiB

License (3-Clause BSD) Release Maven Central

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.
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.

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.