Gunthy
		GUNBOT: The automatic profit generator => Technical Support & Development => Topic started by: gionni on May 06, 2017, 12:20:25 AM
		
			
			- 
				I made up a little something for those who like to manage the bot manually.
 Do take a look at this post by user shacky here if you want to start all your pairs at once instead:
 https://gunthy.org/index.php?topic=129.0
 
 Note that I'm using exactly the same command here to launch the bot and I respected the same screen naming. I haven't tested but I believe this script is compatible with shacky's script and you can use gunctl script to stop a single pair also launched with shacky's script.
 
 - configure the botfolder in the script
 - make the script executable: chmod u+x gunctl.sh
 
 USAGE:
 Start: ./gunctl.sh start [strategy] [pair] [exchange or leave blank for poloniex]
 Stop:./gunctl.sh stop [pair]
 List (running pairs, strategy and exchange):./gunctl.sh list [pair]
 View the running bot:screen -r PAIR_NAME
 #!/bin/bash
 ########### EDIT PLEASE ###############
 # exact folder where gunbot and config files are
 botfolder="/your/path/to/gunbot/"
 ########## NO MORE EDIT ###############
 
 
 ############## DONT EDIT ##############
 
 red=`tput setaf 1`
 green=`tput setaf 2`
 blue=`tput setaf 4`
 reset=`tput sgr0`
 cmd=$1
 strat=$2
 pair=$3
 exchange=$4
 
 
 echo "*********** GUNCTL - v0.0.2 - $( date ) ***************"
 
 if [[ -n "$cmd" ]]; then
 if [[ "$cmd" == "list" ]]; then
 lookup='ps aux'
 printf "%-10s %-10s %-10s\n" "Strategy" "Pair" "Exchange"
 printf "%-10s %-10s %-10s\n" "----------" "----------" "----------"
 $lookup | grep -v grep | grep -v gunctl | grep "node [stepgain|BB|1000trades]" |  awk '{printf "%-10s %-10s %-10s\n",$12,$13,$14}' | sort -nk2
 exit 0
 fi
 if [[ "$cmd" == "stop" ]]; then
 pair=$2
 if [[ -n "$pair" ]]; then
 if ! screen -list | grep -q "$2"; then
 echo "${red}Pair not running or not started with gunctl... ${reset}"
 exit 0
 else
 echo "${green}Stopping Pair $2${reset}"
 screen -S $2 -X quit
 echo "${blue}Pair $2 stopped.${reset}"
 sleep 0.2
 exit 0
 fi
 else
 echo "Pair is missing"
 exit 0
 fi
 
 fi
 else
 echo "Command missing"
 echo "Usage: gunctl [start [strat] [pair] [exchange],stop [pair],list]"
 exit 0
 fi
 if [[ -n "$strat" ]]; then
 echo "Strategy: $2"
 else
 echo "Strategy is missing"
 exit 0
 fi
 if [[ -n "$pair" ]]; then
 echo "Pair: $3"
 else
 echo "Pair is missing"
 exit 0
 fi
 if [[ -n "$exchange" ]]; then
 echo "Exchange: $4"
 else
 exchange="poloniex"
 echo "Exchange: Poloniex"
 fi
 cd $botfolder
 echo ""
 if ! ls | grep -qw "$3"; then
 echo "Config missing for $3"
 exit 0
 fi
 echo "Checking if pair $3 is running..."
 if ! ps aux | grep -v grep | grep -v gunctl | grep "$3"; then
 echo "${red}Pair not running...${reset}"
 echo "${green}Starting $3 pair. ${reset}"
 
 screen -dmS $3
 screen -S $3 -p 0 -X exec node $2 $3 $4
 else
 echo "${green}Pair $3 is already running${reset}"
 sleep 0.2
 fi
 
 
- 
				Nice work, thanks gionni for sharing this ! 
 
 I'm especially interested with this part (you'll understand why if you read my latest post (https://gunthy.org/index.php?topic=238.0))
 
 Stop: screen -S $2 -X quit
 
 Do you know in deep how screen stops a process associated with the window you quit ?
- 
				I believe that it kills all the processes running from the window and then quit the screen session
			
- 
				I believe that it kills all the processes running from the window and then quit the screen session
 
 Thanks for your answer :)
 Well not exactly the kind of "smart" exit I am looking for ... but I guess there is no other way...
- 
				I believe that it kills all the processes running from the window and then quit the screen session
 
 Thanks for your answer :)
 Well not exactly the kind of "smart" exit I am looking for ... but I guess there is no other way...
 
 
 What were you looking for?
- 
				I believe that it kills all the processes running from the window and then quit the screen session
 
 Thanks for your answer :)
 Well not exactly the kind of "smart" exit I am looking for ... but I guess there is no other way...
 
 
 What were you looking for?
 
 
 A way to tell the process to close himself, thus making shure we don't kill it while it is buying or selling, which could lead to corrupted/inaccurate save.json file
 
 I even suggested an easy way to code this here: https://gunthy.org/index.php?topic=257.0 (https://gunthy.org/index.php?topic=257.0)