From 2aad45a9bdc2f919686542124d27791b6a603344 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 25 May 2021 18:41:24 -0700 Subject: [PATCH] Updated examples with toCurrency. --- .../java/com/example/CryptoPriceSample.java | 20 ++++++++++--------- .../kotlin/com/example/CryptoPriceExample.kt | 18 +++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/examples/src/main/java/com/example/CryptoPriceSample.java b/examples/src/main/java/com/example/CryptoPriceSample.java index 09ff615..2a533a8 100644 --- a/examples/src/main/java/com/example/CryptoPriceSample.java +++ b/examples/src/main/java/com/example/CryptoPriceSample.java @@ -12,11 +12,19 @@ public class CryptoPriceSample { try { // Get current Bitcoin market price. final CryptoPrice price = CryptoPrice.marketPrice("BTC"); - System.out.println("The current Bitcoin price is " + price.getAmount() + " in " + price.getCurrency()); + System.out.println("The current Bitcoin price is " + price.toCurrency()); // Get current Bitcoin market price in Euros. final CryptoPrice euroPrice = CryptoPrice.marketPrice("BTC", "EUR"); - System.out.println("The current Bitcoin price is " + euroPrice.getAmount() + " in Euros"); + System.out.println("The current Bitcoin price is " + euroPrice.toCurrency()); + + System.out.println(); + + // Get current Ethereum market price in Pound sterling. + final CryptoPrice gbpPrice = CryptoPrice.marketPrice("ETH", "GBP"); + System.out.println("The current Ethereum price is " + gbpPrice.toCurrency()); + + System.out.println(); // Get current Bitcoin buy price using API. // See: https://developers.coinbase.com/api/v2#get-buy-price @@ -27,15 +35,9 @@ public class CryptoPriceSample { Collections.emptyMap() ) ); - System.out.println("The current BTC buy price is " + buyPrice.getAmount() + System.out.println("The current " + buyPrice.getBase() + " buy price is " + buyPrice.getAmount() + " in " + buyPrice.getCurrency()); - System.out.println(); - - // Get current Ethereum market price in Pound sterling. - final CryptoPrice gbpPrice = CryptoPrice.marketPrice("ETH", "GBP"); - System.out.println("The current Ethereum price is " + gbpPrice.getAmount() + " in Pound sterling"); - } catch (CryptoException | IOException e) { System.err.println(e.getMessage()); } diff --git a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt index adb3dbd..53130db 100644 --- a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt +++ b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt @@ -7,20 +7,22 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice fun main(@Suppress("UNUSED_PARAMETER") args: Array) { // Get current Bitcoin market price. val price = marketPrice("BTC") - println("The current Bitcoin price is ${price.amount} in ${price.currency}") + println("The current Bitcoin price is ${price.toCurrency()}") // Get current Bitcoin market price in Euro. val euroPrice = marketPrice("BTC", "EUR") - println("The current Bitcoin price is ${euroPrice.amount} in Euros") - - // Get current Bitcoin buy price using API. - // See: https://developers.coinbase.com/api/v2#get-buy-price - val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice() - println("The current BTC buy price is ${buyPrice.amount} in ${buyPrice.currency}") + println("The current Bitcoin price is ${euroPrice.toCurrency()}") println() // Get current Ethereum market price in Pound sterling. val gbpPrice = marketPrice("ETH", "GBP") - println("The current Ehtereum price is ${gbpPrice.amount} in Pound sterling") + println("The current Ehtereum price is ${gbpPrice.toCurrency()}") + + println() + + // Get current Bitcoin buy price using API. + // See: https://developers.coinbase.com/api/v2#get-buy-price + val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice() + println("The current ${buyPrice.base} buy price is ${buyPrice.amount} in ${buyPrice.currency}") }