diff --git a/.gitignore b/.gitignore index 0dcebd3..6bf1f54 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,17 @@ conf/* .project target/ pom.xml.versionsBackup -.DS_Store \ No newline at end of file +.DS_Store + +### Gradle ### +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..2cb9a61 --- /dev/null +++ b/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'java' +apply plugin: 'maven' + +group = 'com.bitso' +version = '3.0.4-SNAPSHOT' + +description = """bitso-java""" + +sourceCompatibility = 1.5 +targetCompatibility = 1.5 +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + + + +repositories { + + maven { url "http://repo.maven.apache.org/maven2" } +} +dependencies { + compile group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.3.6' + compile group: 'org.json', name: 'json', version:'20140107' + compile group: 'org.mockito', name: 'mockito-all', version:'1.9.5' + compile group: 'io.netty', name: 'netty-all', version:'4.1.8.Final' + testCompile group: 'junit', name: 'junit', version:'4.12' +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7a3265e Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f16d266 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..934477b --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'bitso-java' diff --git a/src/main/java/com/bitso/Bitso.java b/src/main/java/com/bitso/Bitso.java index 6f16803..f625ec3 100644 --- a/src/main/java/com/bitso/Bitso.java +++ b/src/main/java/com/bitso/Bitso.java @@ -599,12 +599,15 @@ private String buildBitsoAuthHeader(String requestPath, String httpMethod, Strin String signature = String.format("%0" + (arrayOfByte.length << 1) + "x", new Object[] { bigInteger }); return String.format("Bitso %s:%s:%s", apiKey, nonce, signature); - } catch (NoSuchAlgorithmException | InvalidKeyException e) { + } catch (NoSuchAlgorithmException e){ e.printStackTrace(); throw new BitsoAPIException(e); } catch (IllegalArgumentException e) { e.printStackTrace(); throw new BitsoAPIException(e); + } catch (InvalidKeyException e) { + e.printStackTrace(); + throw new BitsoAPIException(e); } } diff --git a/src/main/java/com/bitso/BitsoBalance.java b/src/main/java/com/bitso/BitsoBalance.java index 769aede..a9c98e0 100644 --- a/src/main/java/com/bitso/BitsoBalance.java +++ b/src/main/java/com/bitso/BitsoBalance.java @@ -12,7 +12,7 @@ public class BitsoBalance { private HashMap mBalances; public BitsoBalance(JSONObject o) { - mBalances = new HashMap<>(); + mBalances = new HashMap(); JSONArray jsonBalances = o.getJSONArray("balances"); int totalElements = jsonBalances.length(); for (int i = 0; i < totalElements; i++) { diff --git a/src/main/java/com/bitso/BitsoFee.java b/src/main/java/com/bitso/BitsoFee.java index 34517c7..fb22afa 100644 --- a/src/main/java/com/bitso/BitsoFee.java +++ b/src/main/java/com/bitso/BitsoFee.java @@ -20,7 +20,7 @@ public BitsoFee(JSONObject o) { } private void processTradeFees(JSONObject o) { - mTradeFees = new HashMap<>(); + mTradeFees = new HashMap(); JSONArray jsonFees = o.getJSONArray("fees"); int totalElements = jsonFees.length(); for (int i = 0; i < totalElements; i++) { @@ -33,7 +33,7 @@ private void processTradeFees(JSONObject o) { } private void processWithdrawalFees(JSONObject o) { - mWithdrawalFees = new HashMap<>(); + mWithdrawalFees = new HashMap(); JSONObject withdrawalFees = o.getJSONObject("withdrawal_fees"); Iterator it = withdrawalFees.keys(); while (it.hasNext()) { diff --git a/src/main/java/com/bitso/BitsoFunding.java b/src/main/java/com/bitso/BitsoFunding.java index c4874e7..abb602b 100644 --- a/src/main/java/com/bitso/BitsoFunding.java +++ b/src/main/java/com/bitso/BitsoFunding.java @@ -90,7 +90,7 @@ private HashMap retrieveOperationDetails(JSONObject o) { return null; } - HashMap details = new HashMap<>(); + HashMap details = new HashMap(); String currentKey; String currentValue; diff --git a/src/main/java/com/bitso/BitsoOperation.java b/src/main/java/com/bitso/BitsoOperation.java index 1b2bb3f..3a8ba85 100644 --- a/src/main/java/com/bitso/BitsoOperation.java +++ b/src/main/java/com/bitso/BitsoOperation.java @@ -40,7 +40,7 @@ private HashMap retrieveOperationDetails(JSONObject o) { return null; } - HashMap details = new HashMap<>(); + HashMap details = new HashMap(); String currentKey; String currentValue; diff --git a/src/main/java/com/bitso/BitsoOrder.java b/src/main/java/com/bitso/BitsoOrder.java index ec36633..b4a01aa 100644 --- a/src/main/java/com/bitso/BitsoOrder.java +++ b/src/main/java/com/bitso/BitsoOrder.java @@ -64,19 +64,13 @@ private BitsoOrder.SIDE retrieveSide(String side) { } private BitsoOrder.STATUS retrieveStatus(String status) { - switch (status) { - case "open": - return BitsoOrder.STATUS.OPEN; - case "partially filled": - return BitsoOrder.STATUS.PARTIALLY_FILLED; - case "completed": - return BitsoOrder.STATUS.COMPLETED; - case "cancelled": - return BitsoOrder.STATUS.CANCELLED; - default: - String exceptionMessage = status + "is not a supported order status"; - throw new BitsoExceptionNotExpectedValue(exceptionMessage); - } + if (status.equals("open")) return BitsoOrder.STATUS.OPEN; + if (status.equals("partially filled")) return BitsoOrder.STATUS.PARTIALLY_FILLED; + if (status.equals("completed")) return BitsoOrder.STATUS.COMPLETED; + if (status.equals("cancelled")) return BitsoOrder.STATUS.CANCELLED; + + String exceptionMessage = status + "is not a supported order status"; + throw new BitsoExceptionNotExpectedValue(exceptionMessage); } private BitsoOrder.TYPE retrieveType(String type) { diff --git a/src/main/java/com/bitso/BitsoTransfer.java b/src/main/java/com/bitso/BitsoTransfer.java index 4241f93..9cf5095 100644 --- a/src/main/java/com/bitso/BitsoTransfer.java +++ b/src/main/java/com/bitso/BitsoTransfer.java @@ -52,7 +52,7 @@ public BitsoTransfer(JSONObject json) { Object fields = o.get("fields"); if (fields.getClass() == JSONObject.class) { JSONObject f = o.getJSONObject("fields"); - this.fields = new HashMap<>(); + this.fields = new HashMap(); Iterator keys = f.keys(); String currentKey; while(keys.hasNext()){ diff --git a/src/main/java/com/bitso/BitsoWithdrawal.java b/src/main/java/com/bitso/BitsoWithdrawal.java index 62d0191..93f49fd 100644 --- a/src/main/java/com/bitso/BitsoWithdrawal.java +++ b/src/main/java/com/bitso/BitsoWithdrawal.java @@ -85,7 +85,7 @@ public void setDetails(HashMap details) { @SuppressWarnings("unchecked") private HashMap retrieveOperationDetails(JSONObject o) { - HashMap details = new HashMap<>(); + HashMap details = new HashMap(); String currentKey; String currentValue = null; diff --git a/src/main/java/com/bitso/websockets/BitsoChannels.java b/src/main/java/com/bitso/websockets/BitsoChannels.java index 350916c..3b501c6 100644 --- a/src/main/java/com/bitso/websockets/BitsoChannels.java +++ b/src/main/java/com/bitso/websockets/BitsoChannels.java @@ -1,7 +1,7 @@ package com.bitso.websockets; public enum BitsoChannels { - TRADES("trades"), DIFF_ORDERS("diff-orders"), ORDERS("orders"); + TRADES("trades"), DIFF_ORDERS("diff-orders"), ORDERS("orders"), KA("ka"); private final String id; @@ -13,4 +13,13 @@ public String toString() { return this.id; } + public static BitsoChannels getBitsoChannel(String data) { + BitsoChannels channel = null; + if (data.equals("trades")) channel = BitsoChannels.TRADES; + if (data.equals("diff-orders")) channel = DIFF_ORDERS; + if (data.equals("orders")) channel = ORDERS; + if (data.equals("ka")) channel = KA; + return channel; + } + } diff --git a/src/main/java/com/bitso/websockets/BitsoStreamUpdate.java b/src/main/java/com/bitso/websockets/BitsoStreamUpdate.java index ab2b255..e90558b 100644 --- a/src/main/java/com/bitso/websockets/BitsoStreamUpdate.java +++ b/src/main/java/com/bitso/websockets/BitsoStreamUpdate.java @@ -18,21 +18,7 @@ public String getBitsoBook() { } public BitsoStreamUpdate(JSONObject jsonObject){ - bitsoChannel = getStream(Helpers.getString(jsonObject, "type")); + bitsoChannel = BitsoChannels.getBitsoChannel(Helpers.getString(jsonObject, "type")); bitsoBook = Helpers.getString(jsonObject, "book"); } - - protected BitsoChannels getStream(String stream) { - switch (stream) { - case "diff-orders": - return BitsoChannels.DIFF_ORDERS; - case "orders": - return BitsoChannels.ORDERS; - case "trades": - return BitsoChannels.TRADES; - default: - String exceptionMessage = stream + "is not a supported stream"; - throw new BitsoExceptionNotExpectedValue(exceptionMessage); - } - } } diff --git a/src/test/java/com/bitso/BitsoServerTest.java b/src/test/java/com/bitso/BitsoServerTest.java index 36e8cc8..15d5410 100644 --- a/src/test/java/com/bitso/BitsoServerTest.java +++ b/src/test/java/com/bitso/BitsoServerTest.java @@ -21,7 +21,7 @@ public void setUp() throws Exception { @After public void tearDown() { try { - Thread.sleep(5_000); + Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/test/java/com/bitso/BitsoTest.java b/src/test/java/com/bitso/BitsoTest.java index 3904cda..2151bdc 100644 --- a/src/test/java/com/bitso/BitsoTest.java +++ b/src/test/java/com/bitso/BitsoTest.java @@ -78,7 +78,7 @@ public void testTrades() throws JSONException, BitsoNullException, IOException, BitsoTransactions bitsoTransaction = mBitso.getTrades(bookInfo.getBook()); assertEquals(nullCheck(bitsoTransaction, BitsoTransactions.class), true); - Thread.sleep(5_000); + Thread.sleep(5000); /* * // TODO: // This should return null due it's a negative value on limit try{ BitsoTransactions @@ -86,26 +86,26 @@ public void testTrades() throws JSONException, BitsoNullException, IOException, * (BitsoAPIException bitsoAPIException) { assertEquals(bitsoAPIException != null, true); } */ - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due limit value is 0 BitsoTransactions bitsoTransactionCeroLimit = mBitso.getTrades(bookInfo.getBook(), "limit=0"); assertEquals(bitsoTransactionCeroLimit != null, true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTransactions bitsoTransactionLowLimit = mBitso.getTrades(bookInfo.getBook(), "limit=1"); totalElements = bitsoTransactionLowLimit.getTransactionsList().length; assertEquals((totalElements >= 0 && totalElements <= 1), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTransactions bitsoTransactionMaxLimit = mBitso.getTrades(bookInfo.getBook(), "limit=100"); totalElements = bitsoTransactionMaxLimit.getTransactionsList().length; assertEquals((totalElements >= 0 && totalElements <= 100), true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due the limit value exceeds 100 @@ -113,7 +113,7 @@ public void testTrades() throws JSONException, BitsoNullException, IOException, "limit=1000"); assertEquals(bitsoTransactionExcedingMaxLimit != null, true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTransactions bitsoTransactionSortAsc = mBitso.getTrades(bookInfo.getBook(), "sort=asc"); innerTransactions = bitsoTransaction.getTransactionsList(); @@ -131,7 +131,7 @@ public void testTrades() throws JSONException, BitsoNullException, IOException, assertEquals(true, orderAsc); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return a correct DESC order and is not doing it @@ -151,7 +151,7 @@ public void testTrades() throws JSONException, BitsoNullException, IOException, assertEquals(true, orderDesc); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTransactions bitsoTransactionSortLimit = mBitso.getTrades(bookInfo.getBook(), "sort=asc", "limit=15"); @@ -213,7 +213,7 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoOperation, BitsoOperation.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] tradesLedger = mBitso.getLedger("trades"); assertEquals(tradesLedger != null, true); @@ -224,7 +224,7 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(bitsoOperation.getOperationDescription(), "trade"); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] feesLedger = mBitso.getLedger("fees"); assertEquals(feesLedger != null, true); @@ -235,7 +235,7 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(bitsoOperation.getOperationDescription(), "fee"); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] fundingsLedger = mBitso.getLedger("fundings"); assertEquals(fundingsLedger != null, true); @@ -246,7 +246,7 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(bitsoOperation.getOperationDescription(), "funding"); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] withdrawalsLedger = mBitso.getLedger("withdrawals"); assertEquals(withdrawalsLedger != null, true); @@ -257,21 +257,21 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(bitsoOperation.getOperationDescription(), "withdrawal"); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due it's a negative value on limit BitsoOperation[] negativeLimitLedger = mBitso.getLedger("", "limit=-10"); assertEquals((negativeLimitLedger != null || negativeLimitLedger == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due limit value is 0 BitsoOperation[] ceroLimitLedger = mBitso.getLedger("", "limit=0"); assertEquals((ceroLimitLedger != null || ceroLimitLedger == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] lowLimitLedger = mBitso.getLedger("", "limit=1"); assertEquals(lowLimitLedger != null, true); @@ -281,7 +281,7 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoOperation, BitsoOperation.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] maxLimitLedger = mBitso.getLedger("", "limit=100"); assertEquals(maxLimitLedger != null, true); @@ -291,28 +291,28 @@ public void testLedger() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoOperation, BitsoOperation.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due the limit value exceeds 100 BitsoOperation[] excedingLimitLedger = mBitso.getLedger("", "limit=1000"); assertEquals((excedingLimitLedger != null || excedingLimitLedger == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] sortAscLedger = mBitso.getLedger("", "sort=asc"); assertEquals(sortAscLedger != null, true); totalElements = sortAscLedger.length; assertEquals((totalElements >= 0 && totalElements <= 25), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] sortDescLedger = mBitso.getLedger("", "sort=desc"); assertEquals(sortDescLedger != null, true); totalElements = sortDescLedger.length; assertEquals((totalElements >= 0 && totalElements <= 25), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoOperation[] multipleQueryParameterLedger = mBitso.getLedger("", "sort=desc", "limit=15"); assertEquals(multipleQueryParameterLedger != null, true); @@ -337,7 +337,7 @@ public void testWithdrawals() throws JSONException, BitsoNullException, IOExcept assertEquals(true, nullCheck(bitsoWithdrawal, BitsoWithdrawal.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall > 0) { BitsoWithdrawal bitsoWithdrawal = withdrawals[0]; @@ -353,7 +353,7 @@ public void testWithdrawals() throws JSONException, BitsoNullException, IOExcept } } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall >= 3) { BitsoWithdrawal bitsoWithdrawalFirst = withdrawals[0]; @@ -370,26 +370,26 @@ public void testWithdrawals() throws JSONException, BitsoNullException, IOExcept } } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoWithdrawal[] withdrawalsBothParameters = mBitso.getWithdrawals(new String[] { "" }, ""); assertEquals(withdrawalsBothParameters == null, true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due it's a negative value on limit BitsoWithdrawal[] negativeLimitwithdrawals = mBitso.getWithdrawals(null, "limit=-10"); assertEquals((negativeLimitwithdrawals != null || negativeLimitwithdrawals == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due limit value is 0 BitsoWithdrawal[] ceroLimitwithdrawals = mBitso.getWithdrawals(null, "limit=0"); assertEquals((ceroLimitwithdrawals != null || ceroLimitwithdrawals == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoWithdrawal[] lowestLimitwithdrawals = mBitso.getWithdrawals(null, "limit=1"); assertEquals(lowestLimitwithdrawals != null, true); @@ -399,7 +399,7 @@ public void testWithdrawals() throws JSONException, BitsoNullException, IOExcept assertEquals(true, nullCheck(bitsoWithdrawal, BitsoWithdrawal.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoWithdrawal[] maxLimitwithdrawals = mBitso.getWithdrawals(null, "limit=100"); assertEquals(maxLimitwithdrawals != null, true); @@ -409,7 +409,7 @@ public void testWithdrawals() throws JSONException, BitsoNullException, IOExcept assertEquals(true, nullCheck(bitsoWithdrawal, BitsoWithdrawal.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null limit exceed max @@ -434,7 +434,7 @@ public void tesFundings() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoFunding, BitsoFunding.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall > 0) { BitsoFunding bitsoFunding = fundings[0]; @@ -448,7 +448,7 @@ public void tesFundings() throws JSONException, BitsoNullException, IOException, } } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall >= 3) { BitsoFunding bitsoFundingFirst = fundings[0]; @@ -464,26 +464,26 @@ public void tesFundings() throws JSONException, BitsoNullException, IOException, } } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoFunding[] fundingsBothParameters = mBitso.getFundings(new String[] { "" }, ""); assertEquals(fundingsBothParameters == null, true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due it's a negative value on limit BitsoFunding[] negativeLimit = mBitso.getFundings(null, "limit=-10"); assertEquals((negativeLimit != null || negativeLimit == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due limit value is 0 BitsoFunding[] ceroLimit = mBitso.getFundings(null, "limit=0"); assertEquals((ceroLimit != null || ceroLimit == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoFunding[] lowestLimit = mBitso.getFundings(null, "limit=1"); assertEquals(lowestLimit != null, true); @@ -493,7 +493,7 @@ public void tesFundings() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoFunding, BitsoFunding.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoFunding[] maxLimit = mBitso.getFundings(null, "limit=100"); assertEquals(maxLimit != null, true); @@ -503,7 +503,7 @@ public void tesFundings() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoFunding, BitsoFunding.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null limit exceed max @@ -528,7 +528,7 @@ public void testUserTrades() throws JSONException, BitsoNullException, IOExcepti assertEquals(true, nullCheck(current, BitsoTrade.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall > 0) { BitsoTrade bitso = fundings[0]; @@ -542,7 +542,7 @@ public void testUserTrades() throws JSONException, BitsoNullException, IOExcepti } } - Thread.sleep(5_000); + Thread.sleep(5000); if (totalElementsFirstCall >= 3) { BitsoTrade bitsoFirst = fundings[0]; @@ -558,26 +558,26 @@ public void testUserTrades() throws JSONException, BitsoNullException, IOExcepti } } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTrade[] bothParameters = mBitso.getUserTrades(new String[] { "" }, ""); assertEquals(bothParameters == null, true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due it's a negative value on limit BitsoTrade[] negativeLimit = mBitso.getUserTrades(null, "limit=-10"); assertEquals((negativeLimit != null || negativeLimit == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null due limit value is 0 BitsoTrade[] ceroLimit = mBitso.getUserTrades(null, "limit=0"); assertEquals((ceroLimit != null || ceroLimit == null), true); - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTrade[] lowestLimit = mBitso.getUserTrades(null, "limit=1"); assertEquals(lowestLimit != null, true); @@ -587,7 +587,7 @@ public void testUserTrades() throws JSONException, BitsoNullException, IOExcepti assertEquals(true, nullCheck(current, BitsoTrade.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); BitsoTrade[] maxLimit = mBitso.getUserTrades(null, "limit=100"); assertEquals(maxLimit != null, true); @@ -597,7 +597,7 @@ public void testUserTrades() throws JSONException, BitsoNullException, IOExcepti assertEquals(true, nullCheck(current, BitsoTrade.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); // TODO: // This should return null limit exceed max @@ -620,7 +620,7 @@ public void testOrderTrades() throws JSONException, BitsoNullException, IOExcept assertEquals(true, nullCheck(current, BitsoTrade.class)); } - Thread.sleep(5_000); + Thread.sleep(5000); for (BitsoTrade trade : trades) { String order = trade.getOid(); @@ -629,14 +629,14 @@ public void testOrderTrades() throws JSONException, BitsoNullException, IOExcept for (BitsoTrade orderTrade : orderTrades) { assertEquals(nullCheck(orderTrade, BitsoTrade.class), true); } - Thread.sleep(5_000); + Thread.sleep(5000); } } @Test public void testTrading() throws JSONException, BitsoNullException, IOException, BitsoAPIException, BitsoPayloadException, InterruptedException { - List orders = new ArrayList<>(); + List orders = new ArrayList(); String canceledOrders[] = null; String sellOrderId = null; String buyOrderId = null; @@ -673,7 +673,7 @@ public void testTrading() throws JSONException, BitsoNullException, IOException, "Test: Set limit SELL order on mxn_btc order book was not executed due not enough funds in BTC"); } - Thread.sleep(1_000); + Thread.sleep(1000); int totalOpenOrders = orders.size(); assertEquals(totalOpenOrders, 2); @@ -694,7 +694,7 @@ public void testTrading() throws JSONException, BitsoNullException, IOException, } } - Thread.sleep(1_000); + Thread.sleep(1000); BitsoOrder[] multiple = mBitso.lookupOrders(buyOrderId, sellOrderId); assertEquals(multiple != null, true); @@ -703,7 +703,7 @@ public void testTrading() throws JSONException, BitsoNullException, IOException, assertEquals(true, nullCheck(bitsoOrder, BitsoOrder.class)); } - Thread.sleep(1_000); + Thread.sleep(1000); for (int i = 0; i < totalOpenOrders; i++) { String orderId = orders.get(i); @@ -730,21 +730,21 @@ public void testFundingDestination() throws JSONException, BitsoNullException, I assertEquals(true, (btcFundingDestination.containsKey("account_identifier_name") && btcFundingDestination.containsKey("account_identifier"))); - Thread.sleep(5_000); + Thread.sleep(5000); Map ethFundingDestination = mBitso.fundingDestination("fund_currency=eth"); assertEquals(true, (ethFundingDestination != null)); assertEquals(true, (ethFundingDestination.containsKey("account_identifier_name") && ethFundingDestination.containsKey("account_identifier"))); - Thread.sleep(5_000); + Thread.sleep(5000); Map mxnFundingDestination = mBitso.fundingDestination("fund_currency=mxn"); assertEquals(true, (mxnFundingDestination != null)); assertEquals(true, (mxnFundingDestination.containsKey("account_identifier_name") && mxnFundingDestination.containsKey("account_identifier"))); - Thread.sleep(5_000); + Thread.sleep(5000); } @Test diff --git a/src/test/java/com/bitso/BitsoWebSocketTest.java b/src/test/java/com/bitso/BitsoWebSocketTest.java index 0f81875..15f408a 100644 --- a/src/test/java/com/bitso/BitsoWebSocketTest.java +++ b/src/test/java/com/bitso/BitsoWebSocketTest.java @@ -21,12 +21,13 @@ import com.bitso.websockets.BitsoChannels; public class BitsoWebSocketTest { - private final BitsoChannels[] bitsoChannels = { BitsoChannels.TRADES, BitsoChannels.DIFF_ORDERS, BitsoChannels.ORDERS }; + private final BitsoChannels[] bitsoChannels = { BitsoChannels.TRADES, BitsoChannels.DIFF_ORDERS, + BitsoChannels.ORDERS }; private BitsoWebSocket bitsoWebSocket; private BitsoWebSocketObserver bitsoWebSocketObserver; - + @Before - public void setUp() throws Exception{ + public void setUp() throws Exception { bitsoWebSocket = new BitsoWebSocket(); bitsoWebSocketObserver = new BitsoWebSocketObserver(); bitsoWebSocket.addObserver(bitsoWebSocketObserver); @@ -63,23 +64,27 @@ public void testWebSocket() throws SSLException, URISyntaxException, Interrupted for (int i = 3; i < totalMessagesReceived; i++) { JSONObject jsonObject = new JSONObject(receivedMessages.get(i)); String type = Helpers.getString(jsonObject, "type"); - switch (type) { - case "trades": + BitsoChannels channel = BitsoChannels.getBitsoChannel(type); + + assertEquals(true, (channel != null)); + + switch (channel) { + case TRADES: BitsoStreamTrades trades = new BitsoStreamTrades(jsonObject); assertEquals((trades != null), true); assertEquals(trades.attributesNotNull(), true); break; - case "diff-orders": + case DIFF_ORDERS: BitsoStreamDiffOrders diff = new BitsoStreamDiffOrders(jsonObject); assertEquals((diff != null), true); assertEquals(diff.attributesNotNull(), true); break; - case "orders": + case ORDERS: BitsoStreamOrders orders = new BitsoStreamOrders(jsonObject); assertEquals(orders != null, true); assertEquals(orders.attributesNotNull(), true); break; - case "ka": + case KA: break; default: String exceptionMessage = type + "is not a supported stream type";