Moved from Gradle to bld
This commit is contained in:
parent
5ec9020a9d
commit
da5aea6b26
68 changed files with 1520 additions and 792 deletions
55
examples/bld/.gitignore
vendored
Normal file
55
examples/bld/.gitignore
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
.gradle
|
||||
.DS_Store
|
||||
build
|
||||
lib/bld/**
|
||||
!lib/bld/bld-wrapper.jar
|
||||
!lib/bld/bld-wrapper.properties
|
||||
lib/compile/
|
||||
lib/runtime/
|
||||
lib/standalone/
|
||||
lib/test/
|
||||
|
||||
# IDEA ignores
|
||||
|
||||
# User-specific
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
3
examples/bld/.idea/.gitignore
generated
vendored
Normal file
3
examples/bld/.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
30
examples/bld/.idea/app.iml
generated
Normal file
30
examples/bld/.idea/app.iml
generated
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/build/main" />
|
||||
<output-test url="file://$MODULE_DIR$/build/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" relativeOutputPath="resources" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotln" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" scope="RUNTIME">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="file://$MODULE_DIR$/src/main/resources/templates" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="compile" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="runtime" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="test" level="project" />
|
||||
</component>
|
||||
</module>
|
14
examples/bld/.idea/bld.iml
generated
Normal file
14
examples/bld/.idea/bld.iml
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/build/bld" />
|
||||
<output-test url="file://$MODULE_DIR$/build/bld" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/src/bld">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/bld/java" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="bld" level="project" />
|
||||
</component>
|
||||
</module>
|
8
examples/bld/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
examples/bld/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ADDITIONAL_TAGS" value="created" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
17
examples/bld/.idea/libraries/bld.xml
generated
Normal file
17
examples/bld/.idea/libraries/bld.xml
generated
Normal file
|
@ -0,0 +1,17 @@
|
|||
<component name="libraryTable">
|
||||
<library name="bld">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<excluded>
|
||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||
</excluded>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
13
examples/bld/.idea/libraries/compile.xml
generated
Normal file
13
examples/bld/.idea/libraries/compile.xml
generated
Normal file
|
@ -0,0 +1,13 @@
|
|||
<component name="libraryTable">
|
||||
<library name="compile">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/compile" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/lib/compile" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
14
examples/bld/.idea/libraries/runtime.xml
generated
Normal file
14
examples/bld/.idea/libraries/runtime.xml
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
<component name="libraryTable">
|
||||
<library name="runtime">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/runtime" />
|
||||
<root url="file://$PROJECT_DIR$/src/main/resources" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/lib/runtime" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
14
examples/bld/.idea/libraries/test.xml
generated
Normal file
14
examples/bld/.idea/libraries/test.xml
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
<component name="libraryTable">
|
||||
<library name="test">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/test" />
|
||||
<root url="file://$PROJECT_DIR$/src/test/resources" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/lib/test" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
22
examples/bld/.idea/misc.xml
generated
Normal file
22
examples/bld/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<pattern value="com.example.CryptoPriceExampleBuild" method="runJava" />
|
||||
</component>
|
||||
<component name="PDMPlugin">
|
||||
<option name="customRuleSets">
|
||||
<list>
|
||||
<option value="K:\java\semver\config\pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../../../java/bld-pitest/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../../../java/bld-jacoco-report/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../../../java/bld-checkstyle/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../../../java/bld-exec/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../../../java/bld-testng/config/pmd.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build" />
|
||||
</component>
|
||||
</project>
|
9
examples/bld/.idea/modules.xml
generated
Normal file
9
examples/bld/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/app.iml" filepath="$PROJECT_DIR$/.idea/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
9
examples/bld/.idea/runConfigurations/Run Tests.xml
generated
Normal file
9
examples/bld/.idea/runConfigurations/Run Tests.xml
generated
Normal file
|
@ -0,0 +1,9 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Tests" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="com.example.ExampleTest" />
|
||||
<module name="app" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
6
examples/bld/.idea/vcs.xml
generated
Normal file
6
examples/bld/.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
11
examples/bld/.vscode/launch.json
vendored
Normal file
11
examples/bld/.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Run Tests",
|
||||
"request": "launch",
|
||||
"mainClass": "com.example.ExampleTest"
|
||||
}
|
||||
]
|
||||
}
|
15
examples/bld/.vscode/settings.json
vendored
Normal file
15
examples/bld/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"java.project.sourcePaths": [
|
||||
"src/main/java",
|
||||
"src/main/resources",
|
||||
"src/test/java",
|
||||
"src/bld/java"
|
||||
],
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.project.referencedLibraries": [
|
||||
"${HOME}/.bld/dist/bld-1.7.5.jar",
|
||||
"lib/compile/*.jar",
|
||||
"lib/runtime/*.jar",
|
||||
"lib/test/*.jar"
|
||||
]
|
||||
}
|
22
examples/bld/README.md
Normal file
22
examples/bld/README.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
## Kotlin Example
|
||||
To compile & run the Kotlin example:
|
||||
|
||||
```text
|
||||
./bld compile
|
||||
|
||||
./bld run
|
||||
./bld run --args="btc"
|
||||
./bld run --args="eth eur"
|
||||
```
|
||||
|
||||
## Java Example
|
||||
|
||||
To compile & run the Java example:
|
||||
|
||||
```text
|
||||
./bld compile
|
||||
|
||||
./bld run-java
|
||||
./bld run-java --args="btc"
|
||||
./bld run-java --args="eth eur"
|
||||
```
|
2
examples/bld/bld
Executable file
2
examples/bld/bld
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env sh
|
||||
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build com.example.CryptoPriceExampleBuild "$@"
|
4
examples/bld/bld.bat
Normal file
4
examples/bld/bld.bat
Normal file
|
@ -0,0 +1,4 @@
|
|||
@echo off
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build com.example.CryptoPriceExampleBuild %*
|
BIN
examples/bld/lib/bld/bld-wrapper.jar
Normal file
BIN
examples/bld/lib/bld/bld-wrapper.jar
Normal file
Binary file not shown.
7
examples/bld/lib/bld/bld-wrapper.properties
Normal file
7
examples/bld/lib/bld/bld-wrapper.properties
Normal file
|
@ -0,0 +1,7 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.0-SNAPSHOT
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.downloadLocation=
|
||||
bld.sourceDirectories=
|
||||
bld.version=1.7.5
|
|
@ -0,0 +1,59 @@
|
|||
package com.example;
|
||||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.BuildCommand;
|
||||
import rife.bld.extension.CompileKotlinOperation;
|
||||
import rife.bld.extension.CompileKotlinOptions;
|
||||
import rife.bld.operations.RunOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static rife.bld.dependencies.Repository.*;
|
||||
import static rife.bld.dependencies.Scope.compile;
|
||||
|
||||
public class CryptoPriceExampleBuild extends BaseProject {
|
||||
public CryptoPriceExampleBuild() {
|
||||
pkg = "com.example";
|
||||
name = "Example";
|
||||
version = version(0, 1, 0);
|
||||
|
||||
mainClass = "com.example.CryptoPriceExampleKt";
|
||||
|
||||
javaRelease = 11;
|
||||
downloadSources = true;
|
||||
autoDownloadPurge = true;
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY);
|
||||
|
||||
scope(compile)
|
||||
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", version(1, 9, 20)))
|
||||
.include(dependency("net.thauvin.erik", "cryptoprice", version(1, 0, 1)))
|
||||
.include(dependency("org.json", "json", "20231013"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new CryptoPriceExampleBuild().start(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile() throws Exception {
|
||||
new CompileKotlinOperation()
|
||||
.fromProject(this)
|
||||
.compileOptions(
|
||||
new CompileKotlinOptions()
|
||||
.jdkRelease(javaRelease)
|
||||
.verbose(true)
|
||||
)
|
||||
.execute();
|
||||
|
||||
// Also compile the Java source code
|
||||
super.compile();
|
||||
}
|
||||
|
||||
@BuildCommand(value = "run-java", summary = "Runs the Java example")
|
||||
public void runJava() throws Exception {
|
||||
new RunOperation()
|
||||
.fromProject(this)
|
||||
.mainClass("com.example.CryptoPriceSample")
|
||||
.execute();
|
||||
}
|
||||
}
|
18
examples/gradle/README.md
Normal file
18
examples/gradle/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Kotlin Example
|
||||
To compile & run the Kotlin example:
|
||||
|
||||
```text
|
||||
./gradlew run
|
||||
./gradlew run --args="btc"
|
||||
./gradlew run --args="eth eur"
|
||||
```
|
||||
|
||||
## Java Example
|
||||
|
||||
To compile & run the Java example:
|
||||
|
||||
```text
|
||||
./gradlew run
|
||||
./gradlew runJava --args="btc"
|
||||
./gradlew runJava --args="eth eur"
|
||||
```
|
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.
|
@ -6,11 +6,6 @@ plugins {
|
|||
kotlin("jvm") version "1.9.10"
|
||||
}
|
||||
|
||||
// ./gradlew run
|
||||
// ./gradlew runJava
|
||||
// ./gradlew run --args="btc"
|
||||
// ./gradlew runJava --args="eth eur"
|
||||
|
||||
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
|
||||
|
||||
repositories {
|
0
examples/gradlew → examples/gradle/gradlew
vendored
0
examples/gradlew → examples/gradle/gradlew
vendored
|
@ -0,0 +1,58 @@
|
|||
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.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CryptoPriceSample {
|
||||
public static void main(final String[] args) {
|
||||
try {
|
||||
if (args.length > 0) {
|
||||
final String currency;
|
||||
if (args.length == 2) {
|
||||
currency = args[1];
|
||||
} else {
|
||||
currency = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
|
||||
}
|
||||
final var price = CryptoPrice.spotPrice(args[0], currency);
|
||||
System.out.println("The current " + price.getBase() + " price is " + price.toCurrency());
|
||||
} else {
|
||||
// Get current Bitcoin spot price.
|
||||
final var price = CryptoPrice.spotPrice("BTC");
|
||||
System.out.println("The current Bitcoin price is " + price.toCurrency());
|
||||
|
||||
System.out.println();
|
||||
|
||||
// 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 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 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.println("The USD-EUR exchange rate is: " + rates.getString("EUR"));
|
||||
}
|
||||
} catch (CryptoException e) {
|
||||
System.err.println("HTTP Status Code: " + e.getStatusCode());
|
||||
System.err.println(e.getMessage() + " (" + e.getId() + ')');
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println("Could not display the specified currency: " + args[1]);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
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
|
||||
import java.util.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
if (args.isNotEmpty()) {
|
||||
val currency = if (args.size == 2) args[1] else Currency.getInstance(Locale.getDefault()).currencyCode
|
||||
val price = spotPrice(args[0], currency)
|
||||
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} (${e.id})")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
System.err.println("Could not display the specified currency: ${args[1]}")
|
||||
} catch (e: IOException) {
|
||||
System.err.println(e.message)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue