diff --git a/README.md b/README.md
index 8a4f90f..3353067 100644
--- a/README.md
+++ b/README.md
@@ -4,10 +4,13 @@ Free Proxy for Gunbot on Poloniex
# Join the telegram group
If you have questions after reading the readme
https://t.me/joinchat/FWYlMkKK-mkrSuj836ehug
-
+
+# Another guide
+Diesel's Guide
+
# How to run
-Download the latest released jar file or compile your own using the source code
-https://github.com/taniman/gunbotproxycommunity/releases
+Download the latest released jar file or compile your own using the source code
+https://github.com/taniman/gunbotproxycommunity/releases
Put the jar file in a directory
Put application.properties in the same directory and fill in your apiKeys and secrets
@@ -19,9 +22,15 @@ Open a terminal or command prompt and type
java -jar GunbotProxyCommunity-x.x.x.jar (replace x.x.x with your actual version number)
On OSX or some linux versions you might need to sudo su and then run the java -jar command.
-If you did everything correctly the application will start without giving you any error messages.
+If you did everything correctly the application will start without giving you any error messages.
+
+### On windows
Open a web browser and go to
-http://localhost:8081/checkSetup/
+http://localhost:8081/checkSetup/
+
+### On a Linux VPS
+curl http://localhost:8081/checkSetupLinux/
+
All rows except hostfile should say 'Looking good!'
If this is not the case, than you have an error in your application.properties
So everything is up and running.
@@ -39,8 +48,16 @@ Open a web browser again and again go to :
http://localhost:8081/checkSetup/
All rows should say 'Looking good!'
If this is not the case, than you have an error in your application.properties
+
+# Running in the background
+Use the provided pm2 json file.
+If you have pm2 installed just use this command.
+pm2 start pm2-GunbotProxyCommunity.json
+pm2 save
+This will make sure that pm2 will automatically start the proxy when pm2 reloads.
-
+To see the proxy log you could do.
+pm2 log 'id' <-- this is the id pm2 gave your proxy
# Warning
Please use the proxy on a VPS or machine that you do not use normally.
diff --git a/gproxy b/gproxy
new file mode 100644
index 0000000..5f5d8f5
--- /dev/null
+++ b/gproxy
@@ -0,0 +1,93 @@
+#!/bin/sh
+# /etc/init.d/gproxy
+### BEGIN INIT INFO
+# Provides: gproxy
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start gproxy at boot time
+# Description: Gunbot Community Proxy {start|stop|status|restart} init.d script.
+### END INIT INFO
+
+# EDIT THESE VARIABLES IF NEEDED
+GPROXY_PATH=/opt/gunbot
+GPROXY_JAR=GunbotProxy.jar
+
+# You can use this script to start and stop the Gunbot Community Proxy
+# If you would like the proxy to start and stop automatically when rebooting
+# place this file in the '/etc/init.d' folder and execute the command
+# update-rc.d gproxy defaults
+
+SERVICE_NAME=GunbotProxy
+PID_PATH_NAME="/tmp/GunbotProxy-pid"
+
+
+status() {
+ if [ -f $PID_PATH_NAME ]; then
+ PID=$(cat $PID_PATH_NAME);
+ printf "$SERVICE_NAME PID:$PID "
+ else
+ printf "$SERVICE_NAME "
+ fi
+ if ps ax | grep -v grep | grep $GPROXY_JAR > /dev/null; then
+ echo " (Active)"
+ else
+ echo " (Inactive)"
+ [ -f $PID_PATH_NAME ] && {
+ printf "\n"
+ tail /var/log/gproxy.log | grep INFO:
+ echo "Problem Detected:"
+ echo "It appears as though the proxy started but did not remain active."
+ printf "\n"
+ }
+ fi
+}
+
+start() {
+ if ! ps ax | grep -v grep | grep $GPROXY_JAR > /dev/null ; then
+ rm -f $PID_PATH_NAME
+ echo "Starting $SERVICE_NAME ..."
+ cd $GPROXY_PATH
+ [ -f /var/log/gproxy.log ] && rm /var/log/gproxy.log
+ nohup java -Xmx256m -jar $GPROXY_JAR /tmp 2>> /var/log/gproxy.log >> /dev/null &
+ echo $! > $PID_PATH_NAME
+ (tail -f /var/log/gproxy.log & P=$! ; sleep 10; kill -9 $P) | grep INFO:
+ else
+ status
+ fi
+}
+
+stop() {
+ if [ -f $PID_PATH_NAME ]; then
+ PID=$(cat $PID_PATH_NAME);
+ echo "$SERVICE_NAME stopping ..."
+ kill $PID;
+ rm -f $PID_PATH_NAME
+ sleep 10
+ status
+ else
+ echo "$SERVICE_NAME is not running ..."
+ fi
+}
+
+
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ *)
+ echo "Usage: gproxy {start|stop|status|restart}"
+ exit 1
+ ;;
+esac
diff --git a/src/main/java/nl/komtek/gpi/controllers/GunbotProxyController.java b/src/main/java/nl/komtek/gpi/controllers/GunbotProxyController.java
index fa81685..53f6cc9 100644
--- a/src/main/java/nl/komtek/gpi/controllers/GunbotProxyController.java
+++ b/src/main/java/nl/komtek/gpi/controllers/GunbotProxyController.java
@@ -2,6 +2,7 @@ package nl.komtek.gpi.controllers;
import com.cf.data.map.poloniex.PoloniexDataMapper;
import com.cf.data.model.poloniex.PoloniexChartData;
+import com.cf.data.model.poloniex.PoloniexCompleteBalance;
import com.cf.data.model.poloniex.PoloniexTradeHistory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -62,7 +63,7 @@ public class GunbotProxyController {
return "trading api intercepted";
}
- @RequestMapping(value = "/public/**", params = "command=return24hVolume")
+ @RequestMapping(value = "/public/**", params = "command=returnOrderBook")
@ResponseBody
public String publicRequestOrderBook(@RequestParam String currencyPair) {
return gunbotProxyService.getOrderBook(currencyPair);
@@ -124,7 +125,10 @@ public class GunbotProxyController {
String key = request.getHeader("key");
market = gunbotProxyService.getMarket(key);
}
- return gunbotProxyService.getCompleteBalances(market);
+ String result = gunbotProxyService.getCompleteBalances(market);
+ result = hideDust(result);
+
+ return result;
}
@RequestMapping(value = "/tradingApi/**", params = "command=returnOpenOrders")
@@ -284,4 +288,34 @@ public class GunbotProxyController {
}
return jsonArray;
}
+
+ private String hideDust(String result) {
+ boolean hidedust = Boolean.parseBoolean(util.getConfigurationProperty("hideDust"));
+ if (!hidedust) {
+ return result;
+ }
+ JsonParser jsonParser = new JsonParser();
+ JsonElement jElement = jsonParser.parse(result);
+ JsonObject jObject = jElement.getAsJsonObject();
+ JsonObject filteredObject = new JsonObject();
+ for (Map.Entry entry : jObject.entrySet()) {
+ JsonElement element = (JsonElement) entry.getValue();
+ BigDecimal available = BigDecimal.valueOf(element.getAsJsonObject().get("available").getAsDouble());
+ BigDecimal onOrders = BigDecimal.valueOf(element.getAsJsonObject().get("onOrders").getAsDouble());
+ BigDecimal btcValue = BigDecimal.valueOf(element.getAsJsonObject().get("btcValue").getAsDouble());
+
+ if (available.doubleValue() == 0) {
+ continue;
+ }
+
+ double approximatePrice = btcValue.doubleValue() / available.add(onOrders).doubleValue();
+ double availableValue = available.doubleValue() * approximatePrice;
+ if (availableValue < 0.00015) {
+ available = BigDecimal.ZERO;
+ }
+ PoloniexCompleteBalance balance = new PoloniexCompleteBalance(available, onOrders, btcValue);
+ filteredObject.add(entry.getKey().toString(), jsonParser.parse(balance.toString()));
+ }
+ return filteredObject.toString();
+ }
}
diff --git a/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java b/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java
index 7e25486..1c56fe2 100644
--- a/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java
+++ b/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java
@@ -305,6 +305,12 @@ public class GunbotProxyService {
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
@CacheEvict(value = "completeBalances", allEntries = true)})
public synchronized String buyOrderWithProtection(String key, String currencyPair, BigDecimal buyPrice, BigDecimal amount) {
+ boolean testMode = Boolean.parseBoolean(util.getConfigurationProperty("testMode"));
+ if (testMode) {
+ logger.info("Test mode: We bought {}", currencyPair);
+ return "";
+ }
+
PoloniexTradingAPIClient tmpTradingAPIClient;
if (isUsingMultipleMarkets()) {
tmpTradingAPIClient = getMultiMarketTradingClient(key);
@@ -324,6 +330,11 @@ public class GunbotProxyService {
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
@CacheEvict(value = "completeBalances", allEntries = true)})
public synchronized String sellOrder(String key, String currencyPair, BigDecimal sellPrice, BigDecimal amount) {
+ boolean testMode = Boolean.parseBoolean(util.getConfigurationProperty("testMode"));
+ if (testMode) {
+ logger.info("Test mode: We sold {}", currencyPair);
+ return "";
+ }
PoloniexTradingAPIClient tmpTradingAPIClient;
if (isUsingMultipleMarkets()) {
tmpTradingAPIClient = getMultiMarketTradingClient(key);