Skip to content

Quick start

Jerry edited this page May 2, 2024 · 13 revisions

You can use both - PIP and Docker deployment schemas, as you choice.

Prepare

For test purpose create API key pair:

You can test strategy on Binance, OKX, Bitfinex and Bybit exchanges, where realized "paper trade mode"

Create Telegram bot

  • Register Telegram bot
  • Get token
  • Find channel_id. Just start IDBot and get channel_id
  • After create environment specify this data into /home/ubuntu/.MartinBinance/config/ms_cfg.toml for 'Demo - Binance', 0

Install from pip

pip install martin-binance

After first install run:

exchanges-wrapper-init

then

martin-binance-init

The structure of the working directory will be created and the necessary files will be copied. On init output you can find location.

Start server

  • Specify api_key and api_secret in /home/ubuntu/.MartinBinance/config/exch_srv_cfg.toml
  • Run in terminal window
exchanges-wrapper-srv

Start client

  • Run in other terminal window
/home/ubuntu/.MartinBinance/cli_0_BTCUSDT.py

Strategy is started.

For upgrade to latest versions use:

pip install -U martin-binance

Docker

  • Install and run exchanges-wrapper server.
  • Pull last version of martin-binance image
docker pull ghcr.io/dogstailfarmer/martin-binance:latest

First run

The structure of the working directory will be created and the necessary files will be copied:

For Ubuntu run commands in terminal:

  mkdir -p tmp_mb/templates &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/__init__.py" > tmp_mb/init.py &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/ms_cfg.toml" > tmp_mb/templates/ms_cfg.toml &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/trial_params.json" > tmp_mb/templates/trial_params.json &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/funds_rate.db" > tmp_mb/templates/funds_rate.db &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_0_BTCUSDT.py" > tmp_mb/templates/cli_0_BTCUSDT.py &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_1_BTCUSDT.py" > tmp_mb/templates/cli_1_BTCUSDT.py &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_2_TESTBTCTESTUSDT.py" > tmp_mb/templates/cli_2_TESTBTCTESTUSDT.py &&\
  docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_3_BTCUSDT.py" > tmp_mb/templates/cli_3_BTCUSDT.py &&\
  python3 tmp_mb/init.py;\
  rm -R -f tmp_mb

For Windows run commands in terminal:

mkdir tmp_mb\templates
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/__init__.py" > tmp_mb\init.py
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/ms_cfg.toml" > tmp_mb\templates\ms_cfg.toml
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/trial_params.json" > tmp_mb\templates\trial_params.json
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/funds_rate.db" > tmp_mb\templates\funds_rate.db
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_0_BTCUSDT.py" > tmp_mb\templates\cli_0_BTCUSDT.py
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_1_BTCUSDT.py" > tmp_mb\templates\cli_1_BTCUSDT.py
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_2_TESTBTCTESTUSDT.py" > tmp_mb\templates\cli_2_TESTBTCTESTUSDT.py
docker run --rm --entrypoint /bin/sh martin-binance -c "cat ./martin_binance/templates/cli_3_BTCUSDT.py" > tmp_mb\templates\cli_3_BTCUSDT.py
python tmp_mb\init.py
rmdir /s /q tmp_mb

Start client

docker run -itP \
 --mount type=bind,source=/home/ubuntu/.MartinBinance,target=/home/appuser/.MartinBinance \
 --network=host \
 --restart=always \
 --name=0-BTCUSDT \
 martin-binance \
 /home/appuser/.MartinBinance/cli_0_BTCUSDT.py 1

The last '1' it is parameter for silent restart with restore operational status.

.MartinBinance/cli_0_BTCUSDT.py where trading parameters must be setting.

For auto update running containers recommended use Watchtower

Setting trade pair

You must set pair name in three places the same (yes, it is crooked, but so far):

  • base setting at top of the cli_X_AAABBB.py, ex.SYMBOL = 'AAABBB'
  • the name of cli_X_AAABBB.py must match
  • the X it is index of element from exchange list in config/ms_cfg.toml

For 'Demo - Binance' and BTC/USDT trade pair it will be cli_0_BTCUSDT.py

For stop strategy use Ctrl-C and/or Telegram control function

Add new exchange account

Adding an account is in two parts
  • For server, it is /home/ubuntu/.MartinBinance/config/exch_srv_cfg.toml, where you place API key and account name
  • For client, it's /home/ubuntu/.MartinBinance/config/ms_cfg.toml, where you add account name into exchange list and setup Telegram parameters

The account name must be identically for server and client configs.