Changed marketPrice to spotPrice.
Using BigDecimal instead of Double.
This commit is contained in:
parent
07a7198455
commit
f252c1602b
7 changed files with 51 additions and 48 deletions
18
README.md
18
README.md
|
@ -2,32 +2,32 @@
|
|||
|
||||
[](https://snyk.io/test/github/ethauvin/cryptoprice?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice) [](https://github.com/ethauvin/cryptoprice/actions/workflows/gradle.yml) [](https://circleci.com/gh/ethauvin/cryptoprice/tree/master)
|
||||
|
||||
# Retrieve cryptocurrencies current market prices
|
||||
# Retrieve cryptocurrencies current prices
|
||||
|
||||
A simple Kotlin/Java/Android implementation of the spot price [Coinbase Public API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
|
||||
## Examples (TL;DR)
|
||||
|
||||
```kotlin
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
|
||||
|
||||
// ...
|
||||
|
||||
val btc = marketPrice("BTC") // Bitcoin
|
||||
val btc = spotPrice("BTC") // Bitcoin
|
||||
println(btc.amount)
|
||||
|
||||
val eth = marketPrice("ETH", "EUR") // Ethereum in Euros
|
||||
val eth = spotPrice("ETH", "EUR") // Ethereum in Euros
|
||||
println(eth.amount)
|
||||
|
||||
```
|
||||
- View [Kotlin](https://github.com/ethauvin/cryptoprice/blob/master/examples/src/main/kotlin/com/example/CryptoPriceExample.kt) or [Java](https://github.com/ethauvin/cryptoprice/blob/master/examples/src/main/java/com/example/CryptoPriceSample.java) Examples.
|
||||
|
||||
### Market Price
|
||||
### Spot Price
|
||||
|
||||
The `marketPrice` function defines the following parameters:
|
||||
The `spotPrice` function defines the following parameters:
|
||||
|
||||
```kotlin
|
||||
marketPrice(
|
||||
spotPrice(
|
||||
base: String, // Required
|
||||
currency: String = "USD",
|
||||
date: LocalDate? = null,
|
||||
|
@ -43,14 +43,14 @@ Parameters | Description
|
|||
A `CryptoPrice` is returned defined as follows:
|
||||
|
||||
```kotlin
|
||||
CryptoPrice(val base: String, val currency: String, val amount: Double)
|
||||
CryptoPrice(val base: String, val currency: String, val amount: BigDecimal)
|
||||
```
|
||||
The parameter names match the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
|
||||
To display the amount as a fomatted currency use the `toCurrency` function:
|
||||
|
||||
```kotlin
|
||||
val price = CryptoPrice("BTC", "EUR", 12345.67)
|
||||
val price = CryptoPrice("BTC", "EUR", 12345.67.toBigDecimal())
|
||||
println(price.toCurrency()) // will print €12,345.67
|
||||
```
|
||||
### Extending
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue