Added examples
This commit is contained in:
parent
8cb6ac4c0b
commit
3517acf544
10 changed files with 139 additions and 33 deletions
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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue