Retrieve cryptocurrencies current prices https://github.com/ethauvin/cryptoprice
Find a file
2021-05-09 16:15:22 -07:00
.circleci Added CIs. 2021-05-08 16:23:12 -07:00
.github/workflows Added more CIs 2021-05-08 23:28:06 -07:00
.idea Cleanup. 2021-05-09 16:15:22 -07:00
examples Cleanup. 2021-05-08 23:09:50 -07:00
gradle/wrapper Initial commit. 2021-05-08 01:35:55 -07:00
src Cleanup. 2021-05-09 16:15:22 -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 Switched to JDK 11 on GitLab. 2021-05-08 23:47:03 -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
bitbucket-pipelines.yml Added more CIs 2021-05-08 23:28:06 -07:00
build.gradle.kts Cleanup. 2021-05-08 23:09:50 -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 Fixed example. 2021-05-08 23:55:30 -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
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:

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