Added examples
This commit is contained in:
parent
8cb6ac4c0b
commit
3517acf544
10 changed files with 139 additions and 33 deletions
6
examples/.gitattributes
vendored
Normal file
6
examples/.gitattributes
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
examples/.gitignore
vendored
Normal file
5
examples/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
31
examples/build.gradle.kts
Normal file
31
examples/build.gradle.kts
Normal file
|
@ -0,0 +1,31 @@
|
|||
plugins {
|
||||
id("org.jetbrains.kotlin.jvm") version "1.5.0"
|
||||
id("com.github.ben-manes.versions") version "0.38.0"
|
||||
application
|
||||
}
|
||||
|
||||
// ./gradlew run
|
||||
// ./gradlew runJava"
|
||||
|
||||
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("net.thauvin.erik:cryptoprice:0.9.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "com.example.CryptoPriceExampleKt"
|
||||
}
|
||||
|
||||
tasks {
|
||||
register<JavaExec>("runJava") {
|
||||
group = "application"
|
||||
main = "com.example.CryptoPriceSample"
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
}
|
||||
}
|
10
examples/settings.gradle.kts
Normal file
10
examples/settings.gradle.kts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/6.5.1/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = "examples"
|
41
examples/src/main/java/com/example/CryptoPriceSample.java
Normal file
41
examples/src/main/java/com/example/CryptoPriceSample.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package com.example;
|
||||
|
||||
import net.thauvin.erik.crypto.CryptoPrice;
|
||||
import net.thauvin.erik.crypto.CryptoException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CryptoPriceSample {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Get current Bitcoin market price.
|
||||
final CryptoPrice price = CryptoPrice.marketPrice("BTC");
|
||||
System.out.println("The current Bitcoin price is " + price.getAmount() + " in " + price.getCurrency());
|
||||
|
||||
// Get current Bitcoin market price in Euros.
|
||||
final CryptoPrice euroPrice = CryptoPrice.marketPrice("BTC", "EUR");
|
||||
System.out.println("The current Bitcoin price is " + euroPrice.getAmount() + " in Euros");
|
||||
|
||||
// Get current Bitcoin buy price using API.
|
||||
final CryptoPrice buyPrice =
|
||||
CryptoPrice.toPrice(
|
||||
CryptoPrice.apiCall(
|
||||
List.of("prices", "BTC-USD", "buy"),
|
||||
Collections.<String, String>emptyMap()
|
||||
)
|
||||
);
|
||||
System.out.println("The current BTC buy price is " + price.getAmount() + " in " + price.getCurrency());
|
||||
|
||||
System.out.println();
|
||||
|
||||
// Get current Ethereum market price in Pound sterling.
|
||||
final CryptoPrice gbpPrice = CryptoPrice.marketPrice("ETH", "GBP");
|
||||
System.out.println("The current Ethereum price is " + gbpPrice.getAmount() + " in Pound sterling");
|
||||
|
||||
} catch (CryptoException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
25
examples/src/main/kotlin/com/example/CryptoPriceExample.kt
Normal file
25
examples/src/main/kotlin/com/example/CryptoPriceExample.kt
Normal file
|
@ -0,0 +1,25 @@
|
|||
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.toPrice
|
||||
|
||||
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
|
||||
// Get current Bitcoin market price.
|
||||
var 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")
|
||||
println("The current Bitcoin price is ${euroPrice.amount} in Euros")
|
||||
|
||||
// Get current Bitcoin buy price using API.
|
||||
var 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")
|
||||
println("The current Ehtereum price is ${gbpPrice.amount} in Pound sterling")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue