From 95abea9cd01333beb52efe580545c96a20529544 Mon Sep 17 00:00:00 2001 From: Rino van Wijngaarden Date: Sun, 4 Aug 2024 23:47:42 +0200 Subject: [PATCH] Updated to use a more recent JDK (tested with Java 21) Updated all dependencies and moved example to the test package. Also: Fixed broken Bitvavo logo link in readme --- .gitignore | 90 +++++++++++++++++++ README.md | 9 +- pom.xml | 58 ++++++------ .../bitvavo/api/WebsocketClientEndpoint.java | 23 ++--- .../java/com/bitvavo/api/BitvavoTest.java} | 66 +++++++------- 5 files changed, 169 insertions(+), 77 deletions(-) create mode 100644 .gitignore rename src/{main/java/com/bitvavo/api/example/example.java => test/java/com/bitvavo/api/BitvavoTest.java} (92%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8857c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,90 @@ +############################## +## Java +############################## +.mtj.tmp/ +*.class +*.jar +*.war +*.ear +*.nar +hs_err_pid* +replay_pid* + +############################## +## Maven +############################## +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +pom.xml.bak +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +############################## +## Gradle +############################## +bin/ +build/ +.gradle +.gradletasknamecache +gradle-app.setting +!gradle-wrapper.jar + +############################## +## IntelliJ +############################## +out/ +.idea/ +.idea_modules/ +*.iml +*.ipr +*.iws + +############################## +## Eclipse +############################## +.settings/ +bin/ +tmp/ +.metadata +.classpath +.project +*.tmp +*.bak +*.swp +*~.nib +local.properties +.loadpath +.factorypath + +############################## +## NetBeans +############################## +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml + +############################## +## Visual Studio Code +############################## +.vscode/ +.code-workspace + +############################## +## OS X +############################## +.DS_Store + +############################## +## Miscellaneous +############################## +*.log \ No newline at end of file diff --git a/README.md b/README.md index 0a8d4b1..74e04d6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@


- +

# Java Bitvavo Api @@ -56,15 +56,12 @@ Place dependency in your project to start using the SDK: com.bitvavo.api api - 1.0 + 1.1 ``` -Or you can use the example as starting point for your own project. Create a new project with the above dependency and place the example.java file in the src/main/java folder. Install through `mvn clean install` and run the example: +See the BitvavoTest class as a starting point for your own project. -` -mvn exec:java "-Dexec.mainClass=com.bitvavo.api.example.example" -` ## Rate Limiting diff --git a/pom.xml b/pom.xml index a62dfc0..bab5b0b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,87 +6,93 @@ com.bitvavo.api api - 1.0 - + 1.1 api http://www.bitvavo.com UTF-8 - 1.7 - 1.7 + 21 + 21 - - - junit - junit - 4.13.1 - test - org.json json - 20180130 + 20240303 commons-io commons-io - 2.7 + 2.16.1 commons-codec commons-codec - 1.11 + 1.17.0 org.eclipse.jetty.websocket - javax-websocket-client-impl - 9.4.14.v20181114 + websocket-jakarta-client + 11.0.22 + + + + org.apache.logging.log4j + log4j-slf4j2-impl + 2.23.1 - + + + org.junit.jupiter + junit-jupiter-engine + 5.10.3 + test + + + maven-clean-plugin - 3.1.0 + 3.3.2 maven-resources-plugin - 3.0.2 + 3.3.1 maven-compiler-plugin - 3.8.0 + 3.13.0 maven-surefire-plugin - 2.22.1 + 3.3.1 maven-jar-plugin - 3.0.2 + 3.4.2 maven-install-plugin - 2.5.2 + 3.1.2 maven-deploy-plugin - 2.8.2 + 3.1.2 maven-site-plugin - 3.7.1 + 3.12.1 maven-project-info-reports-plugin - 3.0.0 + 3.6.2 diff --git a/src/main/java/com/bitvavo/api/WebsocketClientEndpoint.java b/src/main/java/com/bitvavo/api/WebsocketClientEndpoint.java index c78b0ad..e024bc2 100644 --- a/src/main/java/com/bitvavo/api/WebsocketClientEndpoint.java +++ b/src/main/java/com/bitvavo/api/WebsocketClientEndpoint.java @@ -1,17 +1,18 @@ package com.bitvavo.api; +import jakarta.websocket.ClientEndpoint; import org.json.*; import java.net.URI; -import javax.websocket.ClientEndpoint; -import javax.websocket.CloseReason; -import javax.websocket.ContainerProvider; -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.OnError; -import javax.websocket.Session; -import javax.websocket.WebSocketContainer; -import javax.websocket.PongMessage; +import jakarta.websocket.ClientEndpoint; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.OnClose; +import jakarta.websocket.OnMessage; +import jakarta.websocket.OnOpen; +import jakarta.websocket.OnError; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; +import jakarta.websocket.PongMessage; import java.util.concurrent.TimeUnit; import java.util.*; import java.io.*; @@ -76,7 +77,7 @@ public void retryConnecting(URI endpointURI) { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); container.connectToServer(this, endpointURI); } - catch (javax.websocket.DeploymentException e) { + catch (jakarta.websocket.DeploymentException e) { try { TimeUnit.MILLISECONDS.sleep(this.reconnectTimer); this.reconnectTimer = this.reconnectTimer * 2; diff --git a/src/main/java/com/bitvavo/api/example/example.java b/src/test/java/com/bitvavo/api/BitvavoTest.java similarity index 92% rename from src/main/java/com/bitvavo/api/example/example.java rename to src/test/java/com/bitvavo/api/BitvavoTest.java index b8e32a3..d46ad7a 100644 --- a/src/main/java/com/bitvavo/api/example/example.java +++ b/src/test/java/com/bitvavo/api/BitvavoTest.java @@ -1,11 +1,11 @@ -package com.bitvavo.api.example; +package com.bitvavo.api; -import com.bitvavo.api.*; import org.json.*; -import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /* - * This is an example utilising all functions of the node Bitvavo API wrapper. + * This is an example (test) utilising all functions of the Java Bitvavo API wrapper. * The APIKEY and APISECRET should be replaced by your own key and secret. * For public functions the APIKEY and SECRET can be removed. * Documentation: https://docs.bitvavo.com @@ -13,25 +13,30 @@ * README: https://github.com/bitvavo/java-bitvavo-api */ -class example{ - public static void main(String args[]){ - Bitvavo bitvavo = new Bitvavo(new JSONObject("{" + - "APIKEY: '', " + - "APISECRET: '', " + - "RESTURL: 'https://api.bitvavo.com/v2'," + - "WSURL: 'wss://ws.bitvavo.com/v2/'," + - "ACCESSWINDOW: 10000, " + - "DEBUGGING: false }")); - - testREST(bitvavo); - testWebsocket(bitvavo); +class BitvavoTest { + private static Bitvavo bitvavo; + + @BeforeAll + static void prepare() { + + bitvavo = new Bitvavo(new JSONObject(""" + {\ + APIKEY: '', \ + APISECRET: '', \ + RESTURL: 'https://api.bitvavo.com/v2',\ + WSURL: 'wss://ws.bitvavo.com/v2/',\ + ACCESSWINDOW: 10000, \ + DEBUGGING: false\ + }""")); } - public static void testREST(Bitvavo bitvavo) { + @Test + void testREST() { JSONArray response; int remaining = bitvavo.getRemainingLimit(); System.out.println("remaining limit is " + remaining); + System.out.println("time " + bitvavo.time()); // response = bitvavo.markets(new JSONObject()); // for(int i = 0; i < response.length(); i ++) { @@ -73,13 +78,13 @@ public static void testREST(Bitvavo bitvavo) { // System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "limit", new JSONObject("{ amount: 0.1, price: 4000 }")).toString(2)); // System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "stopLoss", new JSONObject("{ amount: 0.1, triggerType: price, triggerReference: lastTrade, triggerAmount: 5000 }")).toString(2)); - + // System.out.println(bitvavo.getOrder("BTC-EUR", "afa9da1c-edb9-4245-9271-3549147845a1").toString(2)); // System.out.println(bitvavo.updateOrder("BTC-EUR", "afa9da1c-edb9-4245-9271-3549147845a1", new JSONObject("{ amount: 0.2 }")).toString(2)); // System.out.println(bitvavo.cancelOrder("BTC-EUR", "afa9da1c-edb9-4245-9271-3549147845a1").toString(2)); - + // response = bitvavo.getOrders("BTC-EUR", new JSONObject()); // for(int i = 0; i < response.length(); i ++) { // System.out.println(response.getJSONObject(i).toString(2)); @@ -89,12 +94,12 @@ public static void testREST(Bitvavo bitvavo) { // for(int i = 0; i < response.length(); i ++) { // System.out.println(response.getJSONObject(i).toString(2)); // } - + // response = bitvavo.ordersOpen(new JSONObject("{ market: BTC-EUR }")); // for(int i = 0; i < response.length(); i ++) { // System.out.println(response.getJSONObject(i).toString(2)); // } - + // response = bitvavo.trades("BTC-EUR", new JSONObject()); // for(int i = 0; i < response.length(); i ++) { // System.out.println(response.getJSONObject(i).toString(2)); @@ -122,20 +127,13 @@ public static void testREST(Bitvavo bitvavo) { // } } - public static void testWebsocket(Bitvavo bitvavo) { + @Test + void testWebsocket() { Bitvavo.Websocket ws = bitvavo.newWebsocket(); - ws.setErrorCallback(new WebsocketClientEndpoint.MessageHandler() { - public void handleMessage(JSONObject response) { - System.out.println("Found ERROR, own callback." + response); - } - }); + ws.setErrorCallback(response -> System.out.println("Found ERROR, own callback." + response)); - ws.time(new WebsocketClientEndpoint.MessageHandler() { - public void handleMessage(JSONObject responseObject) { - System.out.println(responseObject.getJSONObject("response").toString(2)); - } - }); + ws.time(responseObject -> System.out.println(responseObject.getJSONObject("response").toString(2))); // ws.markets(new JSONObject(), new WebsocketClientEndpoint.MessageHandler() { // public void handleMessage(JSONObject responseObject) { @@ -358,6 +356,6 @@ public void handleMessage(JSONObject responseObject) { // }); // The following function can be used to close the socket, callbacks will no longer be called. - // ws.close() + //ws.close(); } -} +} \ No newline at end of file