Cleanup and added Gradle wrapper.

This commit is contained in:
Erik C. Thauvin 2021-05-09 22:36:38 -07:00
parent 2c771ad286
commit 740e3a9d01
6 changed files with 288 additions and 9 deletions

View file

@ -1,12 +1,11 @@
package com.example;
import net.thauvin.erik.crypto.CryptoPrice;
import net.thauvin.erik.crypto.CryptoException;
import net.thauvin.erik.crypto.CryptoPrice;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class CryptoPriceSample {
public static void main(String[] args) {
@ -25,10 +24,11 @@ public class CryptoPriceSample {
CryptoPrice.toPrice(
CryptoPrice.apiCall(
List.of("prices", "BTC-USD", "buy"),
Collections.<String, String>emptyMap()
Collections.emptyMap()
)
);
System.out.println("The current BTC buy price is " + price.getAmount() + " in " + price.getCurrency());
System.out.println("The current BTC buy price is " + buyPrice.getAmount()
+ " in " + buyPrice.getCurrency());
System.out.println();

View file

@ -1,26 +1,26 @@
package com.example
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
// Get current Bitcoin market price.
var price = marketPrice("BTC")
val price = marketPrice("BTC")
println("The current Bitcoin price is ${price.amount} in ${price.currency}")
// Get current Bitcoin market price in Euro.
var euroPrice = marketPrice("BTC", "EUR")
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
var buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice()
val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice()
println("The current BTC buy price is ${buyPrice.amount} in ${buyPrice.currency}")
println()
// Get current Ethereum market price in Pound sterling.
var gbpPrice = marketPrice("ETH", "GBP")
val gbpPrice = marketPrice("ETH", "GBP")
println("The current Ehtereum price is ${gbpPrice.amount} in Pound sterling")
}