diff --git a/.circleci/config.yml b/.circleci/config.yml
index 2922277..edab9fe 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -29,11 +29,11 @@ defaults_gradle: &defaults_gradle
- store_test_results:
path: build/reports/
jobs:
- build_gradle_jdk17:
+ build_gradle_jdk18:
<<: *defaults
docker:
- - image: cimg/openjdk:17.0
+ - image: cimg/openjdk:18.0
<<: *defaults_gradle
@@ -50,4 +50,4 @@ workflows:
gradle:
jobs:
- build_gradle_jdk11
- - build_gradle_jdk17
+ - build_gradle_jdk18
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index 8556581..a0b7843 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
- java-version: [ 11, 17 ]
+ java-version: [ 11, 18 ]
steps:
- uses: actions/checkout@v2
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index cfd3ca8..d3ae3bd 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -21,5 +21,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..b1077fb
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index cbfe0de..c55072b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,8 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 797acea..0000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 33df4c6..c006e9f 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-[](https://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/cryptoprice/releases/latest) [](https://search.maven.org/search?q=g:%22net.thauvin.erik%22%20AND%20a:%22cryptoprice%22)
+[](https://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/cryptoprice/releases/latest) [](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/)
[](https://snyk.io/test/github/ethauvin/cryptoprice?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice) [](https://github.com/ethauvin/cryptoprice/actions/workflows/gradle.yml) [](https://circleci.com/gh/ethauvin/cryptoprice/tree/master)
-# Retrieve cryptocurrencies current prices
+# Retrieve cryptocurrencies current (buy, sell or spot) prices
-A simple Kotlin/Java/Android implementation of the spot price [Coinbase Public API](https://developers.coinbase.com/api/v2#get-spot-price).
+A simple Kotlin/Java/Android implementation of the prices [Coinbase Public API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
## Examples (TL;DR)
@@ -16,7 +16,10 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
val btc = spotPrice("BTC") // Bitcoin
println(btc.amount)
-val eth = spotPrice("ETH", "EUR") // Ethereum in Euros
+val eth = sellPrice("ETH", "EUR") // Ethereum in Euro
+println(eth.amount)
+
+val eth = buyPrice("LTC", "GBP") // Litecoin in Pound sterling
println(eth.amount)
```
@@ -28,21 +31,31 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
```gradle
dependencies {
- implementation("net.thauvin.erik:cryptoprice:0.9.0")
+ implementation("net.thauvin.erik:cryptoprice:1.0.0-SNAPSHOT")
}
```
-Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/artifact/net.thauvin.erik/cryptoprice/0.9.0/jar).
+Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/search?q=g:%22net.thauvin.erik%22%20AND%20a:%22cryptoprice%22).
-### Spot Price
+### Prices
-The `spotPrice` function defines the following parameters:
+The `spotPrice`, `buyPrice` and `sellPrice` functions define the following parameters:
```kotlin
spotPrice(
base: String, // Required
currency: String = "USD",
- date: LocalDate? = null,
+ date: LocalDate? = null
+)
+
+buyPrice(
+ base: String, // Required
+ currency: String = "USD"
+)
+
+sellPrice(
+ base: String, // Required
+ currency: String = "USD"
)
```
@@ -57,7 +70,7 @@ A `CryptoPrice` object is returned defined as follows:
```kotlin
CryptoPrice(val base: String, val currency: String, val amount: BigDecimal)
```
-The parameter names match the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price).
+The parameter names match the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
#### Format
@@ -86,7 +99,7 @@ println(price.toJson())
{"data":{"base":"BTC","currency":"USD","amount":"34567.89"}}
```
-The `data` object matches the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price). To specify a different (or no) key, use:
+The `data` object matches the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-spot-price). To specify a different (or no) key, use:
```kotlin
println(price.toJson("bitcoin"))
@@ -109,15 +122,15 @@ val eth = """{"ether":{"base":"ETH","currency":"USD","amount":"2345.67"}}""".toP
### Extending
-A generic `apiCall()` function is available to access other [API data endpoints](https://developers.coinbase.com/api/v2#data-endpoints). For example to retrieve the current [buy price](https://developers.coinbase.com/api/v2#get-buy-price) of a cryptocurrency:
+A generic `apiCall()` function is available to access other [data API endpoints](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies). For example to retrieve the [exchange rates](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates):
```kotlin
-apiCall(paths = listOf("prices", "BTC-USD", "buy"), params = emptyMap())
+apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
```
will return something like:
```json
-{"data":{"base":"BTC","currency":"USD","amount":"34554.32"}}
+{"data":{"currency":"BTC","rates":{"AED":"36.73","AFN":"589.50",...}}}
```
See the [examples](https://github.com/ethauvin/cryptoprice/blob/master/examples/) for more details.
diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml
index 7bd4e82..3b82903 100644
--- a/bitbucket-pipelines.yml
+++ b/bitbucket-pipelines.yml
@@ -1,4 +1,4 @@
-image: openjdk:17
+image: openjdk:18
pipelines:
default:
diff --git a/build.gradle.kts b/build.gradle.kts
index 0da33d5..89c96de 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,21 +8,21 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
id("application")
id("com.github.ben-manes.versions") version "0.42.0"
- id("io.gitlab.arturbosch.detekt") version "1.20.0"
+ id("io.gitlab.arturbosch.detekt") version "1.21.0"
id("java")
id("maven-publish")
- id("org.jetbrains.dokka") version "1.6.21"
- id("org.jetbrains.kotlinx.kover") version "0.5.0"
- id("org.sonarqube") version "3.3"
+ id("org.jetbrains.dokka") version "1.7.10"
+ id("org.jetbrains.kotlinx.kover") version "0.6.0"
+ id("org.sonarqube") version "3.4.0.2513"
id("signing")
- kotlin("jvm") version "1.6.21"
+ kotlin("jvm") version "1.7.10"
}
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
-description = "Retrieve cryptocurrencies current prices."
+description = "Retrieve cryptocurrencies prices."
group = "net.thauvin.erik"
-version = "0.9.0"
+version = "1.0.0-SNAPSHOT"
val deployDir = "deploy"
val gitHub = "ethauvin/$name"
@@ -43,9 +43,9 @@ repositories {
dependencies {
implementation(platform(kotlin("bom")))
- implementation(kotlin("stdlib-jdk8"))
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
- implementation("com.squareup.okhttp3:okhttp:4.9.3")
+ implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("org.json:json:20220320")
testImplementation(kotlin("test"))
@@ -71,7 +71,7 @@ sonarqube {
property("sonar.organization", "ethauvin-github")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.sourceEncoding", "UTF-8")
- property("sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/kover/report.xml")
+ property("sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/kover/xml/report.xml")
}
}
@@ -132,7 +132,7 @@ tasks {
register("deploy") {
description = "Copies all needed files to the $deployDir directory."
group = PublishingPlugin.PUBLISH_TASK_GROUP
- dependsOn(build, jar)
+ dependsOn(clean, build, jar)
outputs.dir(deployDir)
inputs.files(copyToDeploy)
mustRunAfter(clean)
diff --git a/detekt-baseline.xml b/detekt-baseline.xml
index 9c1ce93..d055a8e 100644
--- a/detekt-baseline.xml
+++ b/detekt-baseline.xml
@@ -2,6 +2,6 @@
- ThrowsCount:CryptoPrice.kt$CryptoPrice.Companion$ @JvmStatic @JvmOverloads @Throws(CryptoException::class, IOException::class) fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String
+ ThrowsCount:CryptoPrice.kt$CryptoPrice.Companion$@JvmStatic @JvmOverloads @Throws(CryptoException::class, IOException::class) fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String
diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts
index 050a260..bb8adad 100644
--- a/examples/build.gradle.kts
+++ b/examples/build.gradle.kts
@@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("application")
id("com.github.ben-manes.versions") version "0.42.0"
- kotlin("jvm") version "1.6.21"
+ kotlin("jvm") version "1.7.10"
}
// ./gradlew run
@@ -20,7 +20,8 @@ repositories {
}
dependencies {
- implementation("net.thauvin.erik:cryptoprice:0.9.0")
+ implementation("net.thauvin.erik:cryptoprice:1.0.0-SNAPSHOT")
+ implementation("org.json:json:20220320")
}
java {
diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties
index aa991fc..ae04661 100644
--- a/examples/gradle/wrapper/gradle-wrapper.properties
+++ b/examples/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/examples/src/main/java/com/example/CryptoPriceSample.java b/examples/src/main/java/com/example/CryptoPriceSample.java
index 049257a..967dc25 100644
--- a/examples/src/main/java/com/example/CryptoPriceSample.java
+++ b/examples/src/main/java/com/example/CryptoPriceSample.java
@@ -2,13 +2,14 @@ package com.example;
import net.thauvin.erik.crypto.CryptoException;
import net.thauvin.erik.crypto.CryptoPrice;
+import org.json.JSONObject;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class CryptoPriceSample {
- public static void main(String[] args) {
+ public static void main(final String[] args) {
try {
if (args.length > 0) {
final CryptoPrice price;
@@ -21,27 +22,27 @@ public class CryptoPriceSample {
+ price.getCurrency());
} else {
// Get current Bitcoin spot price.
- final CryptoPrice price = CryptoPrice.spotPrice("BTC");
+ final var price = CryptoPrice.spotPrice("BTC");
System.out.println("The current Bitcoin price is " + price.toCurrency());
System.out.println();
- // Get current Ethereum spot price in Pound sterling.
- final CryptoPrice gbpPrice = CryptoPrice.spotPrice("ETH", "GBP");
- System.out.println("The current Ethereum price is " + gbpPrice.toCurrency());
+ // Get current Ethereum buy price in Pound sterling.
+ final var gbpPrice = CryptoPrice.buyPrice("ETH", "GBP");
+ System.out.println("The current Ethereum buy price is " + gbpPrice.toCurrency());
- // Get current Litecoin spot price in Euros.
- final CryptoPrice euroPrice = CryptoPrice.spotPrice("LTC", "EUR");
- System.out.println("The current Litecoin price is " + euroPrice.toCurrency());
+ // Get current Litecoin sell price in Euros.
+ final var euroPrice = CryptoPrice.sellPrice("LTC", "EUR");
+ System.out.println("The current Litecoin sell price is " + euroPrice.toCurrency());
System.out.println();
- // Get current Bitcoin buy price using API.
- // See: https://developers.coinbase.com/api/v2#get-buy-price
- final CryptoPrice buyPrice = CryptoPrice
- .toPrice(CryptoPrice.apiCall(List.of("prices", "BTC-USD", "buy"), Collections.emptyMap()));
- System.out.println("The current " + buyPrice.getBase() + " buy price is " + buyPrice.getAmount()
- + " in " + buyPrice.getCurrency());
+ // Get exchange rate using API.
+ // See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates
+ final var response = CryptoPrice.apiCall(List.of("exchange-rates"),
+ Collections.singletonMap("currency", "USD"));
+ final var rates = new JSONObject(response).getJSONObject("data").getJSONObject("rates");
+ System.out.printf("The USD-EUR exchange rate is: %s%n", rates.getString("EUR"));
}
} catch (CryptoException e) {
System.err.println("HTTP Status Code: " + e.getStatusCode());
diff --git a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
index a1bdb39..e869095 100644
--- a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
+++ b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
@@ -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) {
@@ -19,20 +20,21 @@ fun main(args: Array) {
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}")
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index aa991fc..ae04661 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/pom.xml b/pom.xml
index 3d95e38..0fb30a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,9 +8,9 @@
4.0.0
net.thauvin.erik
cryptoprice
- 0.9.0
+ 1.0.0-SNAPSHOT
cryptoprice
- Retrieve cryptocurrencies current prices.
+ Retrieve cryptocurrencies prices.
https://github.com/ethauvin/cryptoprice
@@ -40,7 +40,7 @@
org.jetbrains.kotlin
kotlin-bom
- 1.6.10
+ 1.7.10
pom
import
@@ -50,19 +50,19 @@
org.jetbrains.kotlin
kotlin-stdlib-jdk8
- 1.6.10
+ 1.7.10
runtime
com.squareup.okhttp3
okhttp
- 4.9.3
+ 4.10.0
runtime
org.json
json
- 20211205
+ 20220320
runtime
diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
index 7ba8c8c..f8c5b4b 100644
--- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
+++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
@@ -42,11 +42,10 @@ import java.io.IOException
import java.math.BigDecimal
import java.text.NumberFormat
import java.time.LocalDate
-import java.util.Currency
-import java.util.Locale
+import java.util.*
/**
- * Retrieves and holds a cryptocurrency current spot price.
+ * Retrieves and holds a cryptocurrency price.
*
* @constructor Constructs a new [CryptoPrice] object.
*
@@ -116,6 +115,19 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
}
}
+ /**
+ * Retrieves the buy price.
+ *
+ * @param base The cryptocurrency ticker symbol, such as `BTC`, `ETH`, `LTC`, etc.
+ * @param currency The fiat currency ISO 4217 code, such as `USD`, `GPB`, `EUR`, etc.
+ */
+ @JvmStatic
+ @JvmOverloads
+ @Throws(CryptoException::class, IOException::class)
+ fun buyPrice(base: String, currency: String = "USD"): CryptoPrice {
+ return apiCall(listOf("prices", "$base-$currency", "buy"), emptyMap()).toPrice()
+ }
+
/**
* Prints the current prices for the specified cryptocurrencies.
*/
@@ -129,7 +141,20 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
}
/**
- * Retrieves the current spot price.
+ * Retrieves the sell price.
+ *
+ * @param base The cryptocurrency ticker symbol, such as `BTC`, `ETH`, `LTC`, etc.
+ * @param currency The fiat currency ISO 4217 code, such as `USD`, `GPB`, `EUR`, etc.
+ */
+ @JvmStatic
+ @JvmOverloads
+ @Throws(CryptoException::class, IOException::class)
+ fun sellPrice(base: String, currency: String = "USD"): CryptoPrice {
+ return apiCall(listOf("prices", "$base-$currency", "sell"), emptyMap()).toPrice()
+ }
+
+ /**
+ * Retrieves the spot price.
*
* @param base The cryptocurrency ticker symbol, such as `BTC`, `ETH`, `LTC`, etc.
* @param currency The fiat currency ISO 4217 code, such as `USD`, `GPB`, `EUR`, etc.
diff --git a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
index 6d7d95b..359bf18 100644
--- a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
@@ -33,11 +33,13 @@
package net.thauvin.erik.crypto
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.time.LocalDate
-import java.util.Locale
+import java.util.*
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@@ -54,28 +56,34 @@ class CryptoPriceTest {
@Test
@Throws(CryptoException::class)
fun testBitcoinPrice() {
- val price = spotPrice("BTC")
- assertEquals("BTC", price.base, "BTC")
- assertEquals("USD", price.currency, "is USD")
- assertTrue(price.amount.signum() > 0, "BTC > 0")
+ val prices = listOf(spotPrice("BTC"), buyPrice("BTC"), sellPrice("BTC"))
+ for (price in prices) {
+ assertEquals("BTC", price.base, "BTC")
+ assertEquals("USD", price.currency, "is USD")
+ assertTrue(price.amount.signum() > 0, "BTC > 0")
+ }
}
@Test
@Throws(CryptoException::class)
fun testEtherPrice() {
- val price = spotPrice("ETH", "EUR")
- assertEquals("ETH", price.base, "ETH")
- assertEquals("EUR", price.currency, "is EUR")
- assertTrue(price.amount.signum() > 0, "ETH > 0")
+ val prices = listOf(spotPrice("ETH", "EUR"), buyPrice("ETH", "EUR"), sellPrice("ETH", "EUR"))
+ for (price in prices) {
+ assertEquals("ETH", price.base, "ETH")
+ assertEquals("EUR", price.currency, "is EUR")
+ assertTrue(price.amount.signum() > 0, "ETH > 0")
+ }
}
@Test
@Throws(CryptoException::class)
fun testLitecoinPrice() {
- val price = spotPrice("LTC", "GBP")
- assertEquals("LTC", price.base, "LTC")
- assertEquals("GBP", price.currency, "is GBP")
- assertTrue(price.amount.signum() > 0, "LTC > 0")
+ val prices = listOf(spotPrice("LTC", "GBP"), buyPrice("LTC", "GBP"), sellPrice("LTC", "GBP"))
+ for (price in prices) {
+ assertEquals("LTC", price.base, "LTC")
+ assertEquals("GBP", price.currency, "is GBP")
+ assertTrue(price.amount.signum() > 0, "LTC > 0")
+ }
}
@Test
@@ -102,7 +110,7 @@ class CryptoPriceTest {
@Test
@Throws(CryptoException::class)
- fun testSpotPrice() {
+ fun testPrices() {
assertFailsWith(
message = "FOO did not fail",
exceptionClass = CryptoException::class,
@@ -112,11 +120,11 @@ class CryptoPriceTest {
assertFailsWith(
message = "BAR did not fail",
exceptionClass = CryptoException::class,
- block = { spotPrice("BTC", "BAR") }
+ block = { buyPrice("BTC", "BAR") }
)
try {
- spotPrice("FOOBAR")
+ sellPrice("FOOBAR")
} catch (e: CryptoException) {
assertNotEquals(400, e.statusCode, "FOOBAR status code is not 400")
}