Skip to content

Terminal Tmux (useful tips)

Jerry edited this page Feb 2, 2024 · 4 revisions

You need separate terminal window for each task, separate for server and for each trading pair. If you plan to run a strategy on VPS then you need terminal program which:

  • multi windows/panes
  • continue running after end of ssh session
  • auto save running state
  • restore state after system restart

The Tmux meets all these requirements.

Tmux install

Install and setup all in list:

Example for tmux configuration file .tmux.conf

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
set -g @continuum-save-interval '15'
set -g @continuum-boot 'on'
set -g status-right 'Status: #{continuum_status}'
set -g assume-paste-time 1
set -g base-index 0
set -g bell-action none
set -g history-file ~/.tmux_history
set -g mouse on
set -g prefix C-b
run '~/.tmux/plugins/tpm/tpm'

Attention: The name of session ('Trade') and pane ('srv', '0-BTC/USDT') must be same as in example and correspond pair which start in this pane. For example cli_1_BTCUSDT.py must be started in pane with name '1-BTC/USDT'

  • Start new session:
tmux new-session -s Trade
  • Rename pane 0: Ctrl+B + , srv Enter
  • Create new pane: Ctrl+B c
  • Rename pane 1: Ctrl+B + , 0-BTC/USDT Enter
  • Change dir to the ~/.MartinBinance
  • Reboot system
  • Attach to the restored session:
tmux attach

You must see the same window as before reboot:

image

For each client pane appropriate dir ~./MartinBinance must be selected.

  • Find /service/relaunch.service, edit your path and install it under systemctl.
  • Run in the pane 0:srv server script:
exchanges-wrapper-srv
  • Run in the pane 1:0-BTC/USDT trade strategy script:
./cli_0_BTCUSDT.py

Final test, reboot system. After reboot connect to the tmux session:

tmux attach

If everything has been done correctly you should see the restored strategy.