Implemented buyPrice and sellPrice. Closes #1
This commit is contained in:
parent
c046cd7341
commit
bef4b2ee20
18 changed files with 152 additions and 98 deletions
|
@ -2,9 +2,10 @@ 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 net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
|
||||
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
@ -19,20 +20,21 @@ fun main(args: Array<String>) {
|
|||
|
||||
println()
|
||||
|
||||
// Get current Ethereum spot price in Pound sterling.
|
||||
val gbpPrice = spotPrice("ETH", "GBP")
|
||||
println("The current Ethereum price is ${gbpPrice.toCurrency()}")
|
||||
// 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 spot price in Euro.
|
||||
val euroPrice = spotPrice("LTC", "EUR")
|
||||
println("The current Litecoin price is ${euroPrice.toCurrency()}")
|
||||
// Get current Litecoin buy price in Euro.
|
||||
val euroPrice = buyPrice("LTC", "EUR")
|
||||
println("The current Litecoin buy 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}")
|
||||
// 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}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue