BBGO Grid Trading on OKEx

c9s
BBGO
Published in
3 min readDec 28, 2021

--

OKEx is one of the largest crypto exchanges that accounts for over $1.5 billion only from its futures trading platform.

BBGO is an open source crypto trading bot written in Go programming language, and it has a built-in grid trading strategy.

If you haven’t heard it, you can check out the GitHub project here.

This article will talk about how to run BBGO grid trading bot on OKEx.

First things first, you should have an OKEx account before you get started, you can register the OKEx account here with the referral code to support BBGO.

After you registered your account, click the user icon on the top right of the web page, you shall see the “API” link. Click it.

And then click the “Create V5 API Key” button to create your API Key:

You should see the API Key creation form like this:

Please give the key a name and choose on the “Trade” option. Then click on the “Create” button.

The API key will then be created, you should safely note or store the API key and API secret. We will use them later.

To run BBGO, you need two files:

  1. bbgo.yaml the core configuration file. it contains the strategy configuration, risk management and exchange session configuration.
  2. .env.local the dotenv file, it contains your API key, API secrets and other credentials.

To set up the OKEx session with BBGO, you need a dotenv file, usually named “.env” or “.env.local”, let’s create a file named .env.local, and put your API key and API secret into the file:

OKEX_API_KEY=1089cbbb-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
OKEX_API_SECRET=3Fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OKEX_API_PASSPHRASE=zzxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Now let’s create the bbgo.yaml file:

---
sessions:
okex:
exchange: okex
envVarPrefix: okex
exchangeStrategies:
- on: okex
grid:
symbol: BTCUSDT
quantity: 0.001
gridNumber: 200
profitSpread: 5000
upperPrice: 50_000
lowerPrice: 46_000

The above config content is in YAML format, which contains 2 sections, the first one is the session, you can see we defined the okex session.

And the second part is the exchange strategies, we defined one grid strategy on the okex exchange session.

We will explain the above parameters:

symbol means the market we want to trade.

quantity means how much quantity for each grid order.

gridNumber means how many grid orders do you want to place.

upperPrice means the highest price of this grid.

lowerPrice means the lowest price of this grid.

profitSpread means once your buy order is executed, what’s the profit spread of your sell order. for example, if you buy BTC at 46000 and your profit spread is 500, then it will place a BTC sell order at 46500 (46000 + 500).

The config files are ready, let’s download the bbgo binary from GitHub:

curl -L -O https://github.com/c9s/bbgo/releases/download/v1.21.0/bbgo-slim-v1.21.0-24-gf78a7d37-linux-amd64.tar.gz
tar xvf bbgo-slim-v1.21.0-24-gf78a7d37-linux-amd64.tar.gz
mv bbgo-slim-linux-amd64 bbgo

And then we can start running bbgo!

./bbgo run

And that’s it!

--

--

c9s
BBGO

Yo-an Lin, yet another programmer in 21 century