Added exception status code and message to examples.

This commit is contained in:
Erik C. Thauvin 2021-06-11 16:53:55 -07:00
parent 8f08fd738b
commit a704b955dc
5 changed files with 63 additions and 23 deletions

View file

@ -38,7 +38,10 @@ public class CryptoPriceSample {
System.out.println("The current " + buyPrice.getBase() + " buy price is " + buyPrice.getAmount()
+ " in " + buyPrice.getCurrency());
} catch (CryptoException | IOException e) {
} catch (CryptoException e) {
System.err.println("HTTP Status Code: " + e.getStatusCode());
System.err.println(e.getMessage());
} catch (IOException e) {
System.err.println(e.getMessage());
}
}

View file

@ -1,28 +1,38 @@
package com.example
import net.thauvin.erik.crypto.CryptoException
import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
import java.io.IOException
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
// Get current Bitcoin spot price.
val price = spotPrice("BTC")
println("The current Bitcoin price is ${price.toCurrency()}")
try {
// Get current Bitcoin spot price.
val price = spotPrice("BTC")
println("The current Bitcoin price is ${price.toCurrency()}")
println()
// Get current Ethereum spot price in Pound sterling.
val gbpPrice = spotPrice("ETH", "GBP")
println("The current Ehtereum price is ${gbpPrice.toCurrency()}")
println()
// Get current Ethereum spot price in Pound sterling.
val gbpPrice = spotPrice("ETH", "GBP")
println("The current Ehtereum price is ${gbpPrice.toCurrency()}")
// Get current Litecoin spot price in Euro.
val euroPrice = spotPrice("LTC", "EUR")
println("The current Litecoin price is ${euroPrice.toCurrency()}")
// Get current Litecoin spot price in Euro.
val euroPrice = spotPrice("LTC", "EUR")
println("The current Litecoin price is ${euroPrice.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}")
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}")
} catch (e: CryptoException) {
System.err.println("HTTP Status Code: ${e.statusCode}")
System.err.println(e.message)
} catch (e: IOException) {
System.err.println(e.message)
}
}