Updated examples.
This commit is contained in:
parent
a704b955dc
commit
2ef72938f2
9 changed files with 110 additions and 45 deletions
9
.idea/cryptoprice.iml
generated
Normal file
9
.idea/cryptoprice.iml
generated
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
36
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
36
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="INNER_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="METHOD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="FIELD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="IGNORE_DEPRECATED" value="false" />
|
||||||
|
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||||
|
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||||
|
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||||
|
<option name="myAdditionalJavadocTags" value="created,created,created" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/cryptoprice.iml" filepath="$PROJECT_DIR$/.idea/cryptoprice.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -6,6 +6,8 @@ plugins {
|
||||||
|
|
||||||
// ./gradlew run
|
// ./gradlew run
|
||||||
// ./gradlew runJava
|
// ./gradlew runJava
|
||||||
|
// ./gradlew run --args="btc"
|
||||||
|
// ./gradlew runJava --args="eth eur"
|
||||||
|
|
||||||
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
|
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ application {
|
||||||
tasks {
|
tasks {
|
||||||
register<JavaExec>("runJava") {
|
register<JavaExec>("runJava") {
|
||||||
group = "application"
|
group = "application"
|
||||||
main = "com.example.CryptoPriceSample"
|
mainClass.set("com.example.CryptoPriceSample")
|
||||||
classpath = sourceSets.main.get().runtimeClasspath
|
classpath = sourceSets.main.get().runtimeClasspath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
examples/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
examples/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
2
examples/gradlew
vendored
2
examples/gradlew
vendored
|
@ -72,7 +72,7 @@ case "`uname`" in
|
||||||
Darwin* )
|
Darwin* )
|
||||||
darwin=true
|
darwin=true
|
||||||
;;
|
;;
|
||||||
MINGW* )
|
MSYS* | MINGW* )
|
||||||
msys=true
|
msys=true
|
||||||
;;
|
;;
|
||||||
NONSTOP* )
|
NONSTOP* )
|
||||||
|
|
|
@ -10,34 +10,39 @@ import java.util.List;
|
||||||
public class CryptoPriceSample {
|
public class CryptoPriceSample {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
// Get current Bitcoin spot price.
|
if (args.length > 0) {
|
||||||
final CryptoPrice price = CryptoPrice.spotPrice("BTC");
|
final CryptoPrice price;
|
||||||
System.out.println("The current Bitcoin price is " + price.toCurrency());
|
if (args.length == 2) {
|
||||||
|
price = CryptoPrice.spotPrice(args[0], args[1]);
|
||||||
|
} else {
|
||||||
|
price = CryptoPrice.spotPrice(args[0]);
|
||||||
|
}
|
||||||
|
System.out.println("The current " + price.getBase() + " price is " + price.getAmount() + " in "
|
||||||
|
+ price.getCurrency());
|
||||||
|
} else {
|
||||||
|
// Get current Bitcoin spot price.
|
||||||
|
final CryptoPrice price = CryptoPrice.spotPrice("BTC");
|
||||||
|
System.out.println("The current Bitcoin price is " + price.toCurrency());
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
// Get current Ethereum spot price in Pound sterling.
|
// Get current Ethereum spot price in Pound sterling.
|
||||||
final CryptoPrice gbpPrice = CryptoPrice.spotPrice("ETH", "GBP");
|
final CryptoPrice gbpPrice = CryptoPrice.spotPrice("ETH", "GBP");
|
||||||
System.out.println("The current Ethereum price is " + gbpPrice.toCurrency());
|
System.out.println("The current Ethereum price is " + gbpPrice.toCurrency());
|
||||||
|
|
||||||
// Get current Litecoin spot price in Euros.
|
// Get current Litecoin spot price in Euros.
|
||||||
final CryptoPrice euroPrice = CryptoPrice.spotPrice("LTC", "EUR");
|
final CryptoPrice euroPrice = CryptoPrice.spotPrice("LTC", "EUR");
|
||||||
System.out.println("The current Litecoin price is " + euroPrice.toCurrency());
|
System.out.println("The current Litecoin price is " + euroPrice.toCurrency());
|
||||||
|
|
||||||
System.out.println();
|
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 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());
|
||||||
|
}
|
||||||
} catch (CryptoException e) {
|
} catch (CryptoException e) {
|
||||||
System.err.println("HTTP Status Code: " + e.getStatusCode());
|
System.err.println("HTTP Status Code: " + e.getStatusCode());
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
|
|
|
@ -7,28 +7,33 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
|
||||||
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
try {
|
try {
|
||||||
// Get current Bitcoin spot price.
|
if (args.isNotEmpty()) {
|
||||||
val price = spotPrice("BTC")
|
val price = if (args.size == 2) spotPrice(args[0], args[1]) else spotPrice(args[0])
|
||||||
println("The current Bitcoin price is ${price.toCurrency()}")
|
println("The current ${price.base} price is ${price.amount} in ${price.currency}")
|
||||||
|
} else {
|
||||||
|
// Get current Bitcoin spot price.
|
||||||
|
val price = spotPrice("BTC")
|
||||||
|
println("The current Bitcoin price is ${price.toCurrency()}")
|
||||||
|
|
||||||
println()
|
println()
|
||||||
|
|
||||||
// Get current Ethereum spot price in Pound sterling.
|
// Get current Ethereum spot price in Pound sterling.
|
||||||
val gbpPrice = spotPrice("ETH", "GBP")
|
val gbpPrice = spotPrice("ETH", "GBP")
|
||||||
println("The current Ehtereum price is ${gbpPrice.toCurrency()}")
|
println("The current Ehtereum price is ${gbpPrice.toCurrency()}")
|
||||||
|
|
||||||
// Get current Litecoin spot price in Euro.
|
// Get current Litecoin spot price in Euro.
|
||||||
val euroPrice = spotPrice("LTC", "EUR")
|
val euroPrice = spotPrice("LTC", "EUR")
|
||||||
println("The current Litecoin price is ${euroPrice.toCurrency()}")
|
println("The current Litecoin price is ${euroPrice.toCurrency()}")
|
||||||
|
|
||||||
println()
|
println()
|
||||||
|
|
||||||
// Get current Bitcoin buy price using API.
|
// Get current Bitcoin buy price using API.
|
||||||
// See: https://developers.coinbase.com/api/v2#get-buy-price
|
// See: https://developers.coinbase.com/api/v2#get-buy-price
|
||||||
val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice()
|
val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice()
|
||||||
println("The current ${buyPrice.base} buy price is ${buyPrice.amount} in ${buyPrice.currency}")
|
println("The current ${buyPrice.base} buy price is ${buyPrice.amount} in ${buyPrice.currency}")
|
||||||
|
}
|
||||||
} catch (e: CryptoException) {
|
} catch (e: CryptoException) {
|
||||||
System.err.println("HTTP Status Code: ${e.statusCode}")
|
System.err.println("HTTP Status Code: ${e.statusCode}")
|
||||||
System.err.println(e.message)
|
System.err.println(e.message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue