diff --git a/examples/pom.xml b/examples/pom.xml index 269eada..3d91ebd 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -11,12 +11,28 @@ kraken-api-examples + + 2.23.0 + + dev.andstuff.kraken kraken-api ${project.version} + + org.apache.logging.log4j + log4j-core + ${log4j.version} + runtime + + + org.apache.logging.log4j + log4j-slf4j2-impl + ${log4j.version} + runtime + diff --git a/examples/src/main/java/dev/andstuff/kraken/example/Examples.java b/examples/src/main/java/dev/andstuff/kraken/example/Examples.java index 624c764..0d6f34f 100644 --- a/examples/src/main/java/dev/andstuff/kraken/example/Examples.java +++ b/examples/src/main/java/dev/andstuff/kraken/example/Examples.java @@ -13,48 +13,48 @@ import dev.andstuff.kraken.api.model.endpoint.market.response.AssetPair; import dev.andstuff.kraken.api.model.endpoint.market.response.ServerTime; import dev.andstuff.kraken.api.model.endpoint.market.response.SystemStatus; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class Examples { public static void main(String[] args) { - /* Public endpoint examples */ KrakenAPI publicAPI = new KrakenAPI(); ServerTime serverTime = publicAPI.serverTime(); - System.out.println(serverTime); + log.info("{}", serverTime); SystemStatus systemStatus = publicAPI.systemStatus(); - System.out.println(systemStatus); + log.info("{}", systemStatus); Map assets1 = publicAPI.assetInfo(List.of("BTC", "ETH")); - System.out.println(assets1); + log.info("{}", assets1); Map assets2 = publicAPI.assetInfo(List.of("DOT", "ADA"), "currency"); - System.out.println(assets2); + log.info("{}", assets2); Map pairs1 = publicAPI.assetPairs(List.of("ETH/BTC", "ETH/USD")); - System.out.println(pairs1); + log.info("{}", pairs1); Map pairs2 = publicAPI.assetPairs(List.of("DOT/USD", "ADA/USD"), AssetPair.Info.MARGIN); - System.out.println(pairs2); + log.info("{}", pairs2); JsonNode ticker = publicAPI.query(KrakenAPI.Public.TICKER, Map.of("pair", "XBTEUR")); - System.out.println(ticker); + log.info("{}", ticker); JsonNode trades = publicAPI.queryPublic("Trades", Map.of("pair", "XBTUSD", "count", "1")); - System.out.println(trades); + log.info("{}", trades); /* Private endpoint example */ Properties apiKeys = readFromFile("/api-keys.properties"); - KrakenAPI api = new KrakenAPI(apiKeys.getProperty("key"), apiKeys.getProperty("secret")); JsonNode balance = api.query(KrakenAPI.Private.BALANCE); - System.out.println(balance); + log.info("{}", balance); JsonNode order = api.query(KrakenAPI.Private.ADD_ORDER, Map.of( "ordertype", "limit", @@ -64,6 +64,6 @@ public static void main(String[] args) { "price", "1000", "oflags", "post,fciq", "validate", "true")); - System.out.println(order); + log.info("{}", order); } } diff --git a/examples/src/main/java/dev/andstuff/kraken/example/JacksonTest.java b/examples/src/main/java/dev/andstuff/kraken/example/JacksonTest.java deleted file mode 100644 index a9c46ed..0000000 --- a/examples/src/main/java/dev/andstuff/kraken/example/JacksonTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.andstuff.kraken.example; - -import java.util.Optional; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; - -public class JacksonTest { - - private static final ObjectMapper OBJECT_MAPPER; - - static { - OBJECT_MAPPER = JsonMapper.builder() - .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .addModules(new JavaTimeModule(), new Jdk8Module()) - .build(); - } - - public static void main(String[] args) throws JsonProcessingException { - MyRecord myRecord = OBJECT_MAPPER.readValue("{}", MyRecord.class); - System.out.println(myRecord); - System.out.println(myRecord.result().isEmpty()); - } - - public record MyRecord(Optional result) {} - - public class MyClass {} -} diff --git a/examples/src/main/java/dev/andstuff/kraken/example/TotalRewards.java b/examples/src/main/java/dev/andstuff/kraken/example/TotalRewards.java index d59daaa..2434fba 100644 --- a/examples/src/main/java/dev/andstuff/kraken/example/TotalRewards.java +++ b/examples/src/main/java/dev/andstuff/kraken/example/TotalRewards.java @@ -4,14 +4,11 @@ import static java.util.Arrays.asList; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.toList; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.math.BigDecimal; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.util.HashMap; import java.util.Iterator; @@ -28,15 +25,15 @@ */ public class TotalRewards { - public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException { + public static void main(String[] args) throws IOException, InterruptedException { Properties apiKeys = readFromFile("/api-keys.properties"); KrakenAPI api = new KrakenAPI(apiKeys.getProperty("key"), apiKeys.getProperty("secret")); - Map params = Map.of( - "type", "staking", - "without_count", "true", - "ofs", "0"); + Map params = new HashMap<>(); + params.put("type", "staking"); + params.put("without_count", "true"); + params.put("ofs", "0"); Map rewards = new HashMap<>(); @@ -76,7 +73,7 @@ public static void main(String[] args) throws IOException, NoSuchAlgorithmExcept List assetRewards = groupedRewards.get(asset).stream() .filter(e -> !asList("migration", "spottostaking").contains(e.findValue("subtype").textValue())) .sorted(comparing(e -> e.get("time").asInt())) - .collect(toList()); + .toList(); BigDecimal assetTotalRewardAmount = assetRewards.stream() .map(e -> new BigDecimal(e.findValue("amount").textValue()) diff --git a/examples/src/main/resources/log4j2.xml b/examples/src/main/resources/log4j2.xml new file mode 100644 index 0000000..d4aa8bc --- /dev/null +++ b/examples/src/main/resources/log4j2.xml @@ -0,0 +1,18 @@ + + + + [%d{ISO8601}] [%-20.20c{1.}] [%-7.7t] [%-5.5p] %m%n + + + + + + + + + + + + + + diff --git a/library/src/main/java/dev/andstuff/kraken/api/rest/DefaultKrakenRestRequester.java b/library/src/main/java/dev/andstuff/kraken/api/rest/DefaultKrakenRestRequester.java index e35d659..f652fb3 100644 --- a/library/src/main/java/dev/andstuff/kraken/api/rest/DefaultKrakenRestRequester.java +++ b/library/src/main/java/dev/andstuff/kraken/api/rest/DefaultKrakenRestRequester.java @@ -21,10 +21,12 @@ import dev.andstuff.kraken.api.model.endpoint.priv.PostParams; import dev.andstuff.kraken.api.model.endpoint.priv.PrivateEndpoint; import dev.andstuff.kraken.api.model.endpoint.pub.PublicEndpoint; +import lombok.extern.slf4j.Slf4j; /** * {@link KrakenRestRequester} implementation using {@link HttpsURLConnection}. */ +@Slf4j public class DefaultKrakenRestRequester implements KrakenRestRequester { private static final ObjectMapper OBJECT_MAPPER; @@ -51,7 +53,7 @@ public DefaultKrakenRestRequester(String key, String secret) { public T execute(PublicEndpoint endpoint) { try { HttpsURLConnection connection = createHttpsConnection(endpoint); - System.out.printf("Fetching %s%n", connection.getURL()); + log.info("Fetching {}", connection.getURL()); return parseResponse(connection.getInputStream(), endpoint); } catch (IOException e) { @@ -72,7 +74,7 @@ public T execute(PrivateEndpoint endpoint) { try { HttpsURLConnection connection = createHttpsConnection(endpoint); - System.out.printf("Fetching %s%n", connection.getURL()); + log.info("Fetching {}", connection.getURL()); connection.addRequestProperty("API-Key", credentials.getKey()); connection.addRequestProperty("API-Sign", credentials.sign(connection.getURL(), nonce, postData)); connection.setDoOutput(true); diff --git a/pom.xml b/pom.xml index 5ed4471..b6c42c0 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,8 @@ 2.16.1 1.18.30 + 2.0.12 + 2.23.0 3.1.1 @@ -81,6 +83,11 @@ ${lombok.version} provided + + org.slf4j + slf4j-api + ${slf4j.version} + @@ -102,6 +109,10 @@ org.projectlombok lombok + + org.slf4j + slf4j-api +