Updated examples.

This commit is contained in:
Erik C. Thauvin 2021-06-20 01:31:52 -07:00
parent a704b955dc
commit 2ef72938f2
9 changed files with 110 additions and 45 deletions

View file

@ -7,32 +7,37 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
import java.io.IOException
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
fun main(args: Array<String>) {
try {
// Get current Bitcoin spot price.
val price = spotPrice("BTC")
println("The current Bitcoin price is ${price.toCurrency()}")
if (args.isNotEmpty()) {
val price = if (args.size == 2) spotPrice(args[0], args[1]) else spotPrice(args[0])
println("The current ${price.base} price is ${price.amount} in ${price.currency}")
} else {
// 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 Litecoin spot price in Euro.
val euroPrice = spotPrice("LTC", "EUR")
println("The current Litecoin price is ${euroPrice.toCurrency()}")
// Get current Ethereum spot price in Pound sterling.
val gbpPrice = spotPrice("ETH", "GBP")
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}")
// 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}")
}
} catch (e: CryptoException) {
System.err.println("HTTP Status Code: ${e.statusCode}")
System.err.println(e.message)
} catch (e: IOException) {
System.err.println(e.message)
System.err.println(e.message)
}
}