Add support for gunbot 3.3.3 and implement some missing polo endpoints
This commit is contained in:
commit
857b16d7fa
29
README.md
29
README.md
|
@ -4,10 +4,13 @@ Free Proxy for Gunbot on Poloniex
|
||||||
# Join the telegram group
|
# Join the telegram group
|
||||||
If you have questions after reading the readme
|
If you have questions after reading the readme
|
||||||
https://t.me/joinchat/FWYlMkKK-mkrSuj836ehug
|
https://t.me/joinchat/FWYlMkKK-mkrSuj836ehug
|
||||||
<br />
|
|
||||||
|
# Another guide
|
||||||
|
<a href="https://gunthy.org/index.php?topic=570.msg3080#msg3080">Diesel's Guide</a>
|
||||||
|
|
||||||
# How to run
|
# How to run
|
||||||
Download the latest released jar file or compile your own using the source code
|
Download the latest released jar file or compile your own using the source code <br />
|
||||||
https://github.com/taniman/gunbotproxycommunity/releases
|
https://github.com/taniman/gunbotproxycommunity/releases <br />
|
||||||
<br />
|
<br />
|
||||||
Put the jar file in a directory <br />
|
Put the jar file in a directory <br />
|
||||||
Put application.properties in the same directory and fill in your apiKeys and secrets <br />
|
Put application.properties in the same directory and fill in your apiKeys and secrets <br />
|
||||||
|
@ -19,9 +22,15 @@ Open a terminal or command prompt and type <br />
|
||||||
java -jar GunbotProxyCommunity-x.x.x.jar (replace x.x.x with your actual version number)<br />
|
java -jar GunbotProxyCommunity-x.x.x.jar (replace x.x.x with your actual version number)<br />
|
||||||
On OSX or some linux versions you might need to sudo su and then run the java -jar command.<br />
|
On OSX or some linux versions you might need to sudo su and then run the java -jar command.<br />
|
||||||
<br />
|
<br />
|
||||||
If you did everything correctly the application will start without giving you any error messages.<br />
|
If you did everything correctly the application will start without giving you any error messages.
|
||||||
|
|
||||||
|
### On windows
|
||||||
Open a web browser and go to <br />
|
Open a web browser and go to <br />
|
||||||
http://localhost:8081/checkSetup/ <br />
|
http://localhost:8081/checkSetup/
|
||||||
|
|
||||||
|
### On a Linux VPS
|
||||||
|
curl http://localhost:8081/checkSetupLinux/ <br />
|
||||||
|
<br />
|
||||||
All rows except hostfile should say 'Looking good!'<br />
|
All rows except hostfile should say 'Looking good!'<br />
|
||||||
If this is not the case, than you have an error in your application.properties <br />
|
If this is not the case, than you have an error in your application.properties <br />
|
||||||
So everything is up and running. <br />
|
So everything is up and running. <br />
|
||||||
|
@ -39,8 +48,16 @@ Open a web browser again and again go to : <br />
|
||||||
http://localhost:8081/checkSetup/ <br />
|
http://localhost:8081/checkSetup/ <br />
|
||||||
All rows should say 'Looking good!' <br />
|
All rows should say 'Looking good!' <br />
|
||||||
If this is not the case, than you have an error in your application.properties <br />
|
If this is not the case, than you have an error in your application.properties <br />
|
||||||
|
|
||||||
|
# Running in the background
|
||||||
|
Use the provided pm2 json file.<br />
|
||||||
|
If you have pm2 installed just use this command.<br />
|
||||||
|
pm2 start pm2-GunbotProxyCommunity.json <br />
|
||||||
|
pm2 save <br />
|
||||||
|
This will make sure that pm2 will automatically start the proxy when pm2 reloads. <br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
To see the proxy log you could do. <br />
|
||||||
|
pm2 log 'id' <-- this is the id pm2 gave your proxy
|
||||||
|
|
||||||
# Warning
|
# Warning
|
||||||
Please use the proxy on a VPS or machine that you do not use normally. <br />
|
Please use the proxy on a VPS or machine that you do not use normally. <br />
|
||||||
|
|
|
@ -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
|
|
@ -2,6 +2,7 @@ package nl.komtek.gpi.controllers;
|
||||||
|
|
||||||
import com.cf.data.map.poloniex.PoloniexDataMapper;
|
import com.cf.data.map.poloniex.PoloniexDataMapper;
|
||||||
import com.cf.data.model.poloniex.PoloniexChartData;
|
import com.cf.data.model.poloniex.PoloniexChartData;
|
||||||
|
import com.cf.data.model.poloniex.PoloniexCompleteBalance;
|
||||||
import com.cf.data.model.poloniex.PoloniexTradeHistory;
|
import com.cf.data.model.poloniex.PoloniexTradeHistory;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
@ -62,7 +63,7 @@ public class GunbotProxyController {
|
||||||
return "trading api intercepted";
|
return "trading api intercepted";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/public/**", params = "command=return24hVolume")
|
@RequestMapping(value = "/public/**", params = "command=returnOrderBook")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String publicRequestOrderBook(@RequestParam String currencyPair) {
|
public String publicRequestOrderBook(@RequestParam String currencyPair) {
|
||||||
return gunbotProxyService.getOrderBook(currencyPair);
|
return gunbotProxyService.getOrderBook(currencyPair);
|
||||||
|
@ -124,7 +125,10 @@ public class GunbotProxyController {
|
||||||
String key = request.getHeader("key");
|
String key = request.getHeader("key");
|
||||||
market = gunbotProxyService.getMarket(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")
|
@RequestMapping(value = "/tradingApi/**", params = "command=returnOpenOrders")
|
||||||
|
@ -284,4 +288,34 @@ public class GunbotProxyController {
|
||||||
}
|
}
|
||||||
return jsonArray;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,6 +305,12 @@ public class GunbotProxyService {
|
||||||
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
|
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
|
||||||
@CacheEvict(value = "completeBalances", allEntries = true)})
|
@CacheEvict(value = "completeBalances", allEntries = true)})
|
||||||
public synchronized String buyOrderWithProtection(String key, String currencyPair, BigDecimal buyPrice, BigDecimal amount) {
|
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;
|
PoloniexTradingAPIClient tmpTradingAPIClient;
|
||||||
if (isUsingMultipleMarkets()) {
|
if (isUsingMultipleMarkets()) {
|
||||||
tmpTradingAPIClient = getMultiMarketTradingClient(key);
|
tmpTradingAPIClient = getMultiMarketTradingClient(key);
|
||||||
|
@ -324,6 +330,11 @@ public class GunbotProxyService {
|
||||||
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
|
@Caching(evict = {@CacheEvict(value = "openOrders", allEntries = true),
|
||||||
@CacheEvict(value = "completeBalances", allEntries = true)})
|
@CacheEvict(value = "completeBalances", allEntries = true)})
|
||||||
public synchronized String sellOrder(String key, String currencyPair, BigDecimal sellPrice, BigDecimal amount) {
|
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;
|
PoloniexTradingAPIClient tmpTradingAPIClient;
|
||||||
if (isUsingMultipleMarkets()) {
|
if (isUsingMultipleMarkets()) {
|
||||||
tmpTradingAPIClient = getMultiMarketTradingClient(key);
|
tmpTradingAPIClient = getMultiMarketTradingClient(key);
|
||||||
|
|
Loading…
Reference in New Issue