Skip to content

Instantly share code, notes, and snippets.

@c9s
Last active May 14, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9s/9fca325bb14034ba033272700084323c to your computer and use it in GitHub Desktop.
Save c9s/9fca325bb14034ba033272700084323c to your computer and use it in GitHub Desktop.
Go and BBGO Installation Guide

Install Go

Go to https://golang.org/dl/ and download the Go installer.

The installed Go is located in /usr/local/go, be sure to add the binary path to your PATH environment variable:

export GOPATH=~/go
export PATH=/usr/local/go/bin:$PATH
export PATH=~/go/bin:$PATH

Please add the above code in your ~/.zshrc or ~/.bashrc

After adding the PATH, please open a new terminal or reload the shell file by:

# if you're using zsh
source ~/.zshrc

# if you're using bash
source ~/.bashrc

Now, let's check if we have install go successfully:

go version

You shall see the output like this:

go version go1.16.3 darwin/arm64

Then, check the location of go:

which go

And the command should output the following path:

/usr/local/go/bin/go

Install BBGO

After you install the Go SDK, you can now get and install the bbgo binary by running the following command:

go get github.com/c9s/bbgo/cmd/bbgo

After installing the package, the bbgo binary should be located at $GOPATH/bin/bbgo, Let's check if it's installed successfully:

See where bbgo is located:

which bbgo

And check the version command:

bbgo version

Now you're ready to run bbgo on your machine!

Setting up your trading environment

To run bbgo you need two files:

  1. .env.local - an environment variable file that stores your exchange API keys, slack token, telegram bot token... etc
  2. bbgo.yaml - a bbgo settings file that defines the strategies you want to execute.

Add your dotenv file

First thing first, let's add our dotenv file .env.local.

If you're in Taiwan and want to use MAX exchange, please visit this page https://max.maicoin.com/api_tokens to create your API token, be sure to enable all read permissions.

Now add the following lines to your .env.local:

MAX_API_KEY=_____YOUR_MAX_API_KEY_____
MAX_API_SECRET=_____YOUR_MAX_API_SECRET_____

If you're using Binance exchange, please visit this page https://www.binance.com/en/my/settings/api-management to

BINANCE_API_KEY=_____YOUR_BINANCE_API_KEY_____
BINANCE_API_SECRET=_____YOUR_BINANCE_API_SECRET_____

Add your bbgo.yaml

A miniaml bbgo.yaml is like this, you just give it an empty YAML file, and it will use all the default settings for you.

---

If you want to add some new strategies, simply add a exchangeStrategies section, for example:

---
exchangeStrategies:

- on: max
  grid:
    symbol: BTCUSDT
    quantity: 0.001
    gridNumber: 30
    profitSpread: 100.0
    upperPrice: 50_000.0
    lowerPrice: 60_000.0
    # long means you want to save your profit in BTC instead of USDT
    long: true

Running bbgo

To run your strategies, simply type the following command:

bbgo run

by default, bbgo loads the dotenv file from the current directory, so be sure to have the two files (./.env.local and ./bbgo.yaml) in the directory that you execute bbgo.

To add more stratgies, simply append the a new list item in the config file, for example:

---
exchangeStrategies:

- on: max
  grid:
    symbol: BTCUSDT
    quantity: 0.001
    gridNumber: 30
    profitSpread: 100.0
    upperPrice: 50_000.0
    lowerPrice: 60_000.0
    long: true
    
- on: max
  grid:
    symbol: LTCUSDT
    quantity: 1.0
    gridNumber: 100
    profitSpread: 10.0
    upperPrice: 300.0
    lowerPrice: 400.0
    long: true    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment