Updated examples with toCurrency.

This commit is contained in:
Erik C. Thauvin 2021-05-25 18:41:24 -07:00
parent 2590fe67b8
commit 2aad45a9bd
2 changed files with 21 additions and 17 deletions

View file

@ -12,11 +12,19 @@ public class CryptoPriceSample {
try { try {
// Get current Bitcoin market price. // Get current Bitcoin market price.
final CryptoPrice price = CryptoPrice.marketPrice("BTC"); 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. // Get current Bitcoin market price in Euros.
final CryptoPrice euroPrice = CryptoPrice.marketPrice("BTC", "EUR"); 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. // Get current Bitcoin buy price using API.
// See: https://developers.coinbase.com/api/v2#get-buy-price // See: https://developers.coinbase.com/api/v2#get-buy-price
@ -27,15 +35,9 @@ public class CryptoPriceSample {
Collections.emptyMap() 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()); + " 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) { } catch (CryptoException | IOException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }

View file

@ -7,20 +7,22 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) { fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
// Get current Bitcoin market price. // Get current Bitcoin market price.
val price = marketPrice("BTC") 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. // Get current Bitcoin market price in Euro.
val euroPrice = marketPrice("BTC", "EUR") val euroPrice = marketPrice("BTC", "EUR")
println("The current Bitcoin price is ${euroPrice.amount} in Euros") println("The current Bitcoin price is ${euroPrice.toCurrency()}")
// 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() println()
// Get current Ethereum market price in Pound sterling. // Get current Ethereum market price in Pound sterling.
val gbpPrice = marketPrice("ETH", "GBP") 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}")
} }