Moved from Gradle to bld
This commit is contained in:
parent
5ec9020a9d
commit
da5aea6b26
68 changed files with 1520 additions and 792 deletions
47
examples/gradle/bin/main/com/example/CryptoPriceExample.kt
Normal file
47
examples/gradle/bin/main/com/example/CryptoPriceExample.kt
Normal file
|
@ -0,0 +1,47 @@
|
|||
package com.example
|
||||
|
||||
import net.thauvin.erik.crypto.CryptoException
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.buyPrice
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
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.toCurrency()}")
|
||||
} else {
|
||||
// Get current Bitcoin spot price.
|
||||
val price = spotPrice("BTC")
|
||||
println("The current Bitcoin price is ${price.toCurrency()}")
|
||||
|
||||
println()
|
||||
|
||||
// Get current Ethereum sell price in Pound sterling.
|
||||
val gbpPrice = sellPrice("ETH", "GBP")
|
||||
println("The current Ethereum sell price is ${gbpPrice.toCurrency()}")
|
||||
|
||||
// Get current Litecoin buy price in Euro.
|
||||
val euroPrice = buyPrice("LTC", "EUR")
|
||||
println("The current Litecoin buy price is ${euroPrice.toCurrency()}")
|
||||
|
||||
println()
|
||||
|
||||
// Get exchange rate using API.
|
||||
// See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates
|
||||
val response = apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
|
||||
val rates = JSONObject(response).getJSONObject("data").getJSONObject("rates")
|
||||
println("The USD-EUR exchange rate is: ${rates.getString("EUR")}")
|
||||
}
|
||||
} catch (e: CryptoException) {
|
||||
System.err.println("HTTP Status Code: ${e.statusCode}")
|
||||
System.err.println(e.message)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
System.err.println("Could not display the specified currency: ${args[1]}")
|
||||
} catch (e: IOException) {
|
||||
System.err.println(e.message)
|
||||
}
|
||||
}
|
BIN
examples/gradle/bin/main/com/example/CryptoPriceSample.class
Normal file
BIN
examples/gradle/bin/main/com/example/CryptoPriceSample.class
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue