Username: Password:

Author Topic: [TUT] Script for easy-delayed-start of all pairs in Linux  (Read 1831 times)

Offline shacky

  • Trust: (0)
  • Rookie
  • *
  • Posts: 4
    • View Profile
[TUT] Script for easy-delayed-start of all pairs in Linux
« on: April 21, 2017, 07:13:58 AM »
Hi everyone,

Today I did a bash script to help me start all the pairs in Linux  (one in each screen) with a time delay of 5 seg for each pair. The script check if the screen exist to reduce the risk to start a duplicate pair.

The script will search for all config files in the gunbot folder and will try to start each one.

How to setup:

1) create a file in the gunbot folder with whatever name you want but the extension should be .sh, for example:
Code: [Select]
nano start_gunbot.sh2) Copy the code to the file
Code: [Select]
#!/bin/bash
########### EDIT PLEASE ###############
# exact folder where gunbot and config files are
botfolder="/root/bot/gunbotv2.0.4"
########## NO MORE EDIT ###############

############## DONT EDIT ##############
_dfiles="*-config.js"
red=`tput bold setaf 1`
green=`tput bold setaf 2`
blue=`tput bold setaf 4`
reset=`tput sgr0`
for f in $_dfiles
do
_name="${f##*/}"
_namef="${f%-*}"
echo "Checking if pair  $_namef is running..."
  if ! screen -list | grep -q "$_namef"; then
echo "${red}Pair not running.... ${green}Starting $_namef pair... ${reset}"
screen -dmS $_namef
screen -S $_namef -p 0 -X exec $botfolder/gunbot $_namef
echo "Waiting 5S"
sleep 1
echo -n "...1"
sleep 1
echo -n "...2"
sleep 1
echo -n "...3"
sleep 1
echo -n "...4"
sleep 1
echo "${blue}...5!${reset}"
echo "${green}Next PAIR${reset}"
  else
echo "${green}Pair $_namef RUNNING${reset}"
sleep 0.2
  fi

done
3)Make sure you edit the botfolder variable to the exact folder your bot is installed.
4) control + o to save and control + x to exit
5) make in executable:
Code: [Select]
chmod u+x start_gunbot.sh6) execute the script
Code: [Select]
./start_gunbot.sh
The script will search for all files with the name XXX_XXX-config.js and will execute the bot with that configuration in a screen called with the name of the pair.

Remember that:
- You should have only the config files you want to run in the gunbot folder, because the script will start ALL the pairs with config files in that directory. If you don't want to run a individual pair, move the config file.
- This only works with gunbot strategy, not 1000 strategy. It's easy to modify for that strategy.
- Dont call this script if you already running the bot. To run this script please stop all your robot sessions.
- Works with all Linux distributions.

If you want to see the output of each pair, you should execute:
Code: [Select]
screen -ls
and when you find the pair you want to see the output, only call the screen:
Code: [Select]
screen -r PAIR_NAME
To exit of the screen without closing it, press:
control a + d

I have another script to stop all trading, here is the code:

Code: [Select]
#!/bin/bash
############## DONT EDIT ##############
_dfiles="*-config.js"
red=`tput bold setaf 1`
green=`tput bold setaf 2`
blue=`tput bold setaf 4`
reset=`tput sgr0`
for f in $_dfiles
do
_name="${f##*/}"
_namef="${f%-*}"
echo "Checking if pair  $_namef is running..."
  if ! screen -list | grep -q "$_namef"; then
        echo "${blue}Pair not running.... ${reset}"
  else
        echo "${red}Pair $_namef RUNNING${reset}"
        screen -S $_namef -X quit
        echo "${blue}EXITING...${reset}"
        sleep 0.2
  fi

done

This code will close all the screen running with the name of the pairs listed in the gunbot folder.

If anyone want help, let me know,

If this helps you, give me a beer:

1Hoy4BgkHQg8wGzskwcVbxhcEcRscMFRnW

Thanks.

Offline jroddingham

  • Trust: (0)
  • Rookie
  • *
  • Posts: 16
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #1 on: April 21, 2017, 01:06:44 PM »
That sir, is some sexy bash. Mine is just a line of commands. Yours is smart. I'm gonna go drink some Brawndo now. It's got electrolytes.

Offline playmobitch

  • Trust: (0)
  • Rookie
  • *
  • Posts: 1
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #2 on: April 24, 2017, 08:52:29 PM »
hi

little improvement and compatibility with 3.x release :


change the grep command line to grep -qw (because pair like STR won't launch if pair STRAT is already running so the -w flag force a whole word match)

Code: [Select]
#!/bin/bash
########### EDIT PLEASE ###############
# exact folder where gunbot and config files are
botfolder="/home/user/gunbot"
########## NO MORE EDIT ###############

############## DONT EDIT ##############
_dfiles="*-config.js"
red=`tput bold setaf 1`
green=`tput bold setaf 2`
blue=`tput bold setaf 4`
reset=`tput sgr0`
for f in $_dfiles
do
_name="${f##*/}"
_namef="${f%-*}"
echo "Checking if pair  $_namef is running..."
  if ! screen -list | grep -qw "$_namef"; then
  echo "${red}Pair not running.... ${green}Starting $_namef pair... ${reset}"
  screen -dmS $_namef
  screen -S $_namef -p 0 -X exec node $botfolder/index $_namef poloniex
  echo "Waiting 5S"
  sleep 1
  echo -n "...1"
  sleep 1
  echo -n "...2"
  sleep 1
  echo -n "...3"
  sleep 1
  echo -n "...4"
  sleep 1
  echo "${blue}...5!${reset}"
  echo "${green}Next PAIR${reset}"
  else
  echo "${green}Pair $_namef RUNNING${reset}"
  sleep 0.2
  fi

done

Offline dobcrypto

  • Local Moderator
  • Trust: (+1)
  • Junior Member
  • ****
  • Posts: 278
  • Russian - native language
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #3 on: April 30, 2017, 01:30:24 AM »
Will it work if I have 2 folders of bot,
1 - I run mannualy and to 1 polo acc.
2 - I run with your start.sh to 2 polo acc?
Or I need to run only one of bot copy?
Telegram @dobcrypto
To get a 10% discount, tell the author a code "dobyGun"
My channel: http://www.youtube.com/dobcryptocurrency

Offline shacky

  • Trust: (0)
  • Rookie
  • *
  • Posts: 4
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #4 on: May 01, 2017, 07:48:47 AM »
This scripts work for you, if you have two polo accounts in two folders without problem. You should change only;

                screen -dmS $_namef to screen -dmS $_namef-2dary
if ! screen -list | grep -qw "$_namef"; then to if ! screen -list | grep -qw "$_namef-2dary"; then

I suggets to you, to have one script for each folder and everything will work.
« Last Edit: May 01, 2017, 08:20:18 AM by shacky »

Offline shacky

  • Trust: (0)
  • Rookie
  • *
  • Posts: 4
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #5 on: May 01, 2017, 07:50:14 AM »
hi

little improvement and compatibility with 3.x release :


change the grep command line to grep -qw (because pair like STR won't launch if pair STRAT is already running so the -w flag force a whole word match)

Code: [Select]
#!/bin/bash
########### EDIT PLEASE ###############
# exact folder where gunbot and config files are
botfolder="/home/user/gunbot"
########## NO MORE EDIT ###############

############## DONT EDIT ##############
_dfiles="*-config.js"
red=`tput bold setaf 1`
green=`tput bold setaf 2`
blue=`tput bold setaf 4`
reset=`tput sgr0`
for f in $_dfiles
do
_name="${f##*/}"
_namef="${f%-*}"
echo "Checking if pair  $_namef is running..."
  if ! screen -list | grep -qw "$_namef"; then
  echo "${red}Pair not running.... ${green}Starting $_namef pair... ${reset}"
  screen -dmS $_namef
  screen -S $_namef -p 0 -X exec node $botfolder/index $_namef poloniex
  echo "Waiting 5S"
  sleep 1
  echo -n "...1"
  sleep 1
  echo -n "...2"
  sleep 1
  echo -n "...3"
  sleep 1
  echo -n "...4"
  sleep 1
  echo "${blue}...5!${reset}"
  echo "${green}Next PAIR${reset}"
  else
  echo "${green}Pair $_namef RUNNING${reset}"
  sleep 0.2
  fi

done

Thanks for your suggestion! Will edit the main topic to add it.

Thanks.

Offline dobcrypto

  • Local Moderator
  • Trust: (+1)
  • Junior Member
  • ****
  • Posts: 278
  • Russian - native language
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #6 on: May 03, 2017, 04:49:03 PM »
hi

little improvement and compatibility with 3.x release :


change the grep command line to grep -qw (because pair like STR won't launch if pair STRAT is already running so the -w flag force a whole word match)

Code: [Select]
  screen -S $_namef -p 0 -X exec node $botfolder/index $_namef poloniex
Code: [Select]
screen -S $_namef -p 0 -X exec node $botfolder/stepgain $_namef poloniex
In my case.
Telegram @dobcrypto
To get a 10% discount, tell the author a code "dobyGun"
My channel: http://www.youtube.com/dobcryptocurrency

Offline LastUser

  • Trust: (0)
  • Rookie
  • *
  • Posts: 7
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #7 on: May 13, 2017, 12:25:35 AM »
thanks for you work, but script doesn't work for me.. while running start.sh script, some of pairs do start and some don't.
i get "no screen session found" for pairs who don't start, and when execute "screen -r BTC_XXX" i get only blank screen. no errors in logs, nothing at all.
maybe i'm doing something wrong?

Offline dobcrypto

  • Local Moderator
  • Trust: (+1)
  • Junior Member
  • ****
  • Posts: 278
  • Russian - native language
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #8 on: June 01, 2017, 10:03:12 PM »
How to run it for 3.3 version?
Telegram @dobcrypto
To get a 10% discount, tell the author a code "dobyGun"
My channel: http://www.youtube.com/dobcryptocurrency

Offline CoinKombinat

  • Trust: (0)
  • Rookie
  • *
  • Posts: 11
  • BTC - Birth of independent people of the future
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #9 on: June 10, 2017, 08:27:09 PM »
If anyone have problems to use these scripts, u need to make sure the content of ure  start shell is exactly the same! Pay attention for every line.

Had problems, that if i paste the lines from here and paste it in my empty file, he mess up the content.

and if u directly upload a windows created shell file on ure *nix VPS it always nice to make all *nix conform with the program dos2unix

And thx alot for ure nice script  ;)

Offline AlfonseX

  • Trust: (0)
  • Contributor
  • **
  • Posts: 109
  • Trop de chefs, pas assez d'indiens !
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #10 on: June 11, 2017, 11:58:40 AM »
Your script is cool, thanks to share it. Personally I use tmux rather than screen, by habit. So here's my launcher :

Code: [Select]
#!/bin/env bash
# start all *-config.js in a tmux new session_name

# adapt gun_command and delay to your needs
gun_command="./gunthy-linuxx64"
delay=30

session_name=$(basename $(pwd))

flag="0"
for file in *-config.js; do
    pair=$(echo $file | cut -d'-' -f2)
    market=$(echo $file | cut -d'-' -f1)
    if [[ "$flag" = "0" ]]; then
        tmux -2 new-session -d -s $session_name -n $pair "$gun_command $pair $market"
        flag="1"
    else
        tmux -2 new-window -d -n $pair "$gun_command $pair $market"
    fi
    printf "Launching %s %s " "$market" "$pair"
    for i in $(seq 1 $delay); do
        echo -n "."
        sleep 1
    done
    echo
done

echo Done
tmux ls

Because I use gunbot on the 3 markets (poloniex, bittrex and kraken), I created subfolders :

/home/me/gunbot/bittrex
/home/me/gunbot/kraken
/home/me/gunbot/poloniex

So in each I put files I need (gunthy-linuxx64, ALLPAIRS, config files) and my start.sh script. Launching it, in the appropriate folder (eg /home/me/gunbot/bittrex), create a tmux session well named "bittrex", "kraken" or "poloniex".
Be sure to adapt gun_command and delay to your needs. For example I set delay=30 for Poloniex and delay=10 for Bittrex.

Sessions are detached, to attach a session, do:
Code: [Select]
tmux a -t poloniex
If I want to stop ALL the pairs for a market:
Code: [Select]
tmux kill-session -t poloniex
You can give me drink at:
12aeQSpytxoehCEptQE8tUJVVSAS42LvXo
« Last Edit: June 14, 2017, 09:22:25 PM by AlfonseX »
If you think I helped you, give me a drink:
in btc: 12aeQSpytxoehCEptQE8tUJVVSAS42LvXo
in eth: 0x02a611f0c15bccdb6fa8e5e4b0692ff6d77852bd

Offline TMTBanker

  • Trust: (0)
  • Rookie
  • *
  • Posts: 20
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #11 on: June 13, 2017, 05:41:27 PM »
Your script is cool, thanks to share it. Personally I use tmux rather than screen, by habit. So here's my launcher :

Code: [Select]
#!/bin/env bash
# start all *-config.js in a tmux new session_name

# adapt gun_command and delay to your needs
gun_command="./gunthy-linuxx64"
delay=30

session_name=$(basename $(pwd))

flag="0"
for file in *-config.js; do
    pair=$(echo $file | cut -d'-' -f2)
    market=$(echo $file | cut -d'-' -f1)
    if [[ "$flag" = "0" ]]; then
        tmux -2 new-session_name -d -s $session_name -n $pair "$gun_command $pair $market"
        flag="1"
    else
        tmux -2 new-window -d -n $pair "$gun_command $pair $market"
    fi
    printf "Launching %s %s " "$market" "$pair"
    for i in $(seq 1 $delay); do
        echo -n "."
        sleep 1
    done
    echo
done

echo Done
tmux ls

Because I use gunbot on the 3 markets (poloniex, bittrex and kraken), I created subfolders :

/home/me/gunbot/bittrex
/home/me/gunbot/kraken
/home/me/gunbot/poloniex

So in each I put files I need (gunthy-linuxx64, ALLPAIRS, config files) and my start.sh script. Launching it, in the appropriate folder (eg /home/me/gunbot/bittrex), create a tmux session well named "bittrex", "kraken" or "poloniex".
Be sure to adapt gun_command and delay to your needs. For example I set delay=30 for Poloniex and delay=10 for Bittrex.

Sessions are detached, to attach a session, do:
Code: [Select]
tmux a -t poloniex
If I want to stop ALL the pairs for a market:
Code: [Select]
tmux kill-session -t poloniex
You can give me drink at:
12aeQSpytxoehCEptQE8tUJVVSAS42LvXo

Is a 30 second day long enough to avoid errors?

Offline AlfonseX

  • Trust: (0)
  • Contributor
  • **
  • Posts: 109
  • Trop de chefs, pas assez d'indiens !
    • View Profile
Re: [TUT] Script for easy-delayed-start of all pairs in Linux
« Reply #12 on: June 14, 2017, 09:28:35 PM »
Quote
Is a 30 second day long enough to avoid errors?

What error are you talking about?

Be carefull, I made a mistake, replace:
Code: [Select]
tmux -2 new-session_name -d -s $session_name -n $pair "$gun_command $pair $market"with:
Code: [Select]
tmux -2 new-session -d -s $session_name -n $pair "$gun_command $pair $market"
If you think I helped you, give me a drink:
in btc: 12aeQSpytxoehCEptQE8tUJVVSAS42LvXo
in eth: 0x02a611f0c15bccdb6fa8e5e4b0692ff6d77852bd