diff --git a/README.md b/README.md index b99e832db..acffa672d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ A trading bot framework written in Go. The name bbgo comes from the BB8 bot in t - Docker image ready. - Kubernetes support. - Helm chart ready. +- High precision float point (up to 16 digits, run with `-tags dnum`). ## Screenshots @@ -62,14 +63,13 @@ Get your exchange API key and secret after you register the accounts (you can ch - OKEx: - Kucoin: -Since the exchange implementation and support are done by a small team, if you like the work they've done for you, It -would be great if you can use their referral code as your support to them. :-D +This project is maintained and supported by a small group of team. If you would like to support this project, please register on the exchanges using the provided links with referral codes above. ## Installation ### Install from binary -The following script will help you set up a config file, dotenv file: +The following script will help you set up a config file and a dotenv file: ```sh # grid trading strategy for binance exchange @@ -77,8 +77,24 @@ bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-gri # grid trading strategy for max exchange bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-grid.sh) max + +# bollinger grid trading strategy for binance exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-bollgrid.sh) binance + +# bollinger grid trading strategy for max exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-bollgrid.sh) max ``` +If you already have configuration somewhere, a download-only script might be suitable for you: +```sh +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/download.sh) +``` + +Or refer to the [Release Page](https://github.com/c9s/bbgo/releases) and download manually. + +Since v2, we've added new float point implementation from dnum to support decimals with higher precision. +To download & setup, please refer to [Dnum Installation](doc/topics/dnum-binary.md) + ### One-click Linode StackScript: - BBGO Grid Trading on Binance diff --git a/doc/README.md b/doc/README.md index 4d73b89a9..bac675a10 100644 --- a/doc/README.md +++ b/doc/README.md @@ -6,6 +6,7 @@ * [Build From Source](build-from-source.md) - How to build bbgo * [Back-testing](topics/back-testing.md) - How to back-test strategies * [TWAP](topics/twap.md) - TWAP order execution to buy/sell large quantity of order +* [Dnum Installation](topics/dnum-binary.md) - installation of high-precision version of bbgo ### Configuration * [Setting up Slack Notification](configuration/slack.md) diff --git a/doc/topics/dnum-binary.md b/doc/topics/dnum-binary.md new file mode 100644 index 000000000..c6454e794 --- /dev/null +++ b/doc/topics/dnum-binary.md @@ -0,0 +1,26 @@ +## Dnum: High Precision Numeric Implementation +---------------------------------------------- +The `dnum` version of `fixedpoint` supports up to 16 digits of decimal precision. It's two times slower than the legacy version, which only supports up to 8 digits of decimal precision. We recommend that strategy developers do algorithmic calculations in `float64`, then convert them back to `fixedpoint` to interact with exchanges to keep the balance between speed and the accuracy of accounting result. + +To Install dnum version of bbgo, we've create several scripts for quick setup: + +```sh +# grid trading strategy for binance exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-grid-dnum.sh) binance + +# grid trading strategy for max exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-grid-dnum.sh) max + +# bollinger grid trading strategy for binance exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-bollgrid-dnum.sh) binance + +# bollinger grid trading strategy for max exchange +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-bollgrid-dnum.sh) max +``` + +If you already have the configuration somewhere, you may want to use the download-only script: +```sh +bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/download-dnum.sh) +``` + +The precompiled dnum binaries are also available in the [Release Page](https://github.com/c9s/bbgo/releases). diff --git a/scripts/download-dnum.sh b/scripts/download-dnum.sh new file mode 100644 index 000000000..a8aeef011 --- /dev/null +++ b/scripts/download-dnum.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') +osf=$(uname | tr '[:upper:]' '[:lower:]') +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac +dist_file=bbgo-dnum-$version-$osf-$arch.tar.gz + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +function warn() +{ + echo -e "${YELLOW}$@${NC}" +} + +function error() +{ + echo -e "${RED}$@${NC}" +} + +function info() +{ + echo -e "${GREEN}$@${NC}" +} + +info "downloading..." +curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file +tar xzf $dist_file +mv bbgo-dnum-$osf-$arch bbgo +chmod +x bbgo +info "downloaded successfully" diff --git a/scripts/download.sh b/scripts/download.sh index 767fcf3e0..9d5268e2d 100755 --- a/scripts/download.sh +++ b/scripts/download.sh @@ -1,8 +1,16 @@ #!/bin/bash set -e +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac osf=$(uname | tr '[:upper:]' '[:lower:]') -version=v1.15.2 -dist_file=bbgo-$version-$osf-amd64.tar.gz +dist_file=bbgo-$version-$osf-$arch.tar.gz RED='\033[0;31m' GREEN='\033[0;32m' @@ -27,6 +35,6 @@ function info() info "downloading..." curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file tar xzf $dist_file -mv bbgo-$osf bbgo +mv bbgo-$osf-$arch bbgo chmod +x bbgo info "downloaded successfully" diff --git a/scripts/setup-bollgrid-dnum.sh b/scripts/setup-bollgrid-dnum.sh new file mode 100644 index 000000000..b5e6f273b --- /dev/null +++ b/scripts/setup-bollgrid-dnum.sh @@ -0,0 +1,109 @@ +#!/bin/bash +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +function warn() +{ + echo -e "${YELLOW}$@${NC}" +} + +function error() +{ + echo -e "${RED}$@${NC}" +} + +function info() +{ + echo -e "${GREEN}$@${NC}" +} +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') +osf=$(uname | tr '[:upper:]' '[:lower:]') +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac +dist_file=bbgo-dnum-$version-$osf-$arch.tar.gz + +info "downloading..." +curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file +tar xzf $dist_file +mv bbgo-dnum-$osf-$arch bbgo +chmod +x bbgo +info "downloaded successfully" + +function gen_dotenv() +{ + read -p "Enter your MAX API key: " api_key + read -p "Enter your MAX API secret: " api_secret + echo "Generating your .env.local file..." +cat < .env.local +MAX_API_KEY=$api_key +MAX_API_SECRET=$api_secret +END + +} + +if [[ -e ".env.local" ]] ; then + echo "Found existing .env.local, you will overwrite the existing .env.local file!" + read -p "Are you sure? (Y/n) " a + if [[ $a != "n" ]] ; then + gen_dotenv + fi +else + gen_dotenv +fi + +if [[ -e "bbgo.yaml" ]] ; then + echo "Found existing bbgo.yaml, you will overwrite the existing bbgo.yaml file!" + read -p "Are you sure? (Y/n) " a + if [[ $a == "n" ]] ; then + exit + fi +fi + +cat < bbgo.yaml +--- +exchangeStrategies: +- on: max + bollgrid: + symbol: BTCUSDT + interval: 1h + gridNumber: 20 + quantity: 0.001 + profitSpread: 100.0 + +END + +info "config file is generated successfully" +echo "================================================================" +echo "now you can edit your strategy config file bbgo.yaml to run bbgo" + +if [[ $osf == "darwin" ]] ; then + echo "we found you're using MacOS, you can type:" + echo "" + echo " open -a TextEdit bbgo.yaml" + echo "" +else + echo "you look like a pro user, you can edit the config by:" + echo "" + echo " vim bbgo.yaml" + echo "" +fi + +echo "To run bbgo just type: " +echo "" +echo " ./bbgo run" +echo "" +echo "To stop bbgo, just hit CTRL-C" + +if [[ $osf == "darwin" ]] ; then + open -a TextEdit bbgo.yaml +fi diff --git a/scripts/setup-bollgrid.sh b/scripts/setup-bollgrid.sh index 8592a054c..baf061666 100755 --- a/scripts/setup-bollgrid.sh +++ b/scripts/setup-bollgrid.sh @@ -20,10 +20,16 @@ function info() { echo -e "${GREEN}$@${NC}" } - +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') osf=$(uname | tr '[:upper:]' '[:lower:]') -arch=amd64 -version=v1.21.4 +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac dist_file=bbgo-$version-$osf-$arch.tar.gz info "downloading..." diff --git a/scripts/setup-dnum.sh b/scripts/setup-dnum.sh new file mode 100644 index 000000000..965705ac5 --- /dev/null +++ b/scripts/setup-dnum.sh @@ -0,0 +1,114 @@ +#!/bin/bash +set -e +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') +osf=$(uname | tr '[:upper:]' '[:lower:]') +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac +dist_file=bbgo-dnum-$version-$osf-$arch.tar.gz + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +function warn() +{ + echo -e "${YELLOW}$@${NC}" +} + +function error() +{ + echo -e "${RED}$@${NC}" +} + +function info() +{ + echo -e "${GREEN}$@${NC}" +} + +info "downloading..." +curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file +tar xzf $dist_file +mv bbgo-dnum-$osf-$arch bbgo +chmod +x bbgo +info "downloaded successfully" + +if [[ -e "bbgo.yaml" ]] ; then + echo "Found existing bbgo.yaml, you will overwrite the existing bbgo.yaml file!" + read -p "Are you sure? (Y/n) " a + if [[ $a == "n" ]] ; then + exit + fi +fi + +cat < bbgo.yaml +--- +riskControls: + sessionBased: + max: + orderExecutor: + bySymbol: + BTCUSDT: + # basic risk control order executor + basic: + minQuoteBalance: 100.0 + maxBaseAssetBalance: 3.0 + minBaseAssetBalance: 0.0 + maxOrderAmount: 1000.0 + +exchangeStrategies: +- on: max + grid: + symbol: BTCUSDT + quantity: 0.002 + gridNumber: 100 + profitSpread: 50.0 + upperPrice: 14000.0 + lowerPrice: 11000.0 +END + +echo "Config file is generated" + +if [[ -e ".env.local" ]] ; then + echo "Found existing .env.local, you will overwrite the existing .env.local file!" + read -p "Are you sure? (Y/n) " a + if [[ $a == "n" ]] ; then + exit + fi +fi + +read -p "Enter your MAX API key: " api_key + +read -p "Enter your MAX API secret: " api_secret + +echo "Generating your .env.local file..." +cat < .env.local +export MAX_API_KEY=$api_key +export MAX_API_SECRET=$api_secret +END + +echo "Now you can edit your strategy config file bbgo.yaml to run bbgo" + +if [[ $osf == "darwin" ]] ; then + echo "We found you're using MacOS, you can type:" + echo "" + echo " open -a TextEdit bbgo.yaml" + echo "" +fi + +echo "To run bbgo just type: " +echo "" +echo " source .env.local && ./bbgo run --config bbgo.yaml" +echo "" +echo "To stop bbgo, just hit CTRL-C" + +if [[ $osf == "darwin" ]] ; then + open -a TextEdit bbgo.yaml +fi + diff --git a/scripts/setup-grid-dnum.sh b/scripts/setup-grid-dnum.sh new file mode 100644 index 000000000..6e93bbc18 --- /dev/null +++ b/scripts/setup-grid-dnum.sh @@ -0,0 +1,121 @@ +#!/bin/bash +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +function warn() +{ + echo -e "${YELLOW}$@${NC}" +} + +function error() +{ + echo -e "${RED}$@${NC}" +} + +function info() +{ + echo -e "${GREEN}$@${NC}" +} +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') +osf=$(uname | tr '[:upper:]' '[:lower:]') +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac +dist_file=bbgo-dnum-$version-$osf-$arch.tar.gz +exchange=max + +if [[ -n $1 ]] ; then + exchange=$1 +fi + +exchange_upper=$(echo -n $exchange | tr 'a-z' 'A-Z') + + +info "downloading..." +curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file +tar xzf $dist_file +mv bbgo-dnum-$osf-$arch bbgo +chmod +x bbgo +info "downloaded successfully" + +function gen_dotenv() +{ + read -p "Enter your $exchange_upper API key: " api_key + read -p "Enter your $exchange_upper API secret: " api_secret + info "generating your .env.local file..." +cat < .env.local +${exchange_upper}_API_KEY=$api_key +${exchange_upper}_API_SECRET=$api_secret +END + + info "dotenv is configured successfully" +} + +if [[ -e ".env.local" ]] ; then + warn "found an existing .env.local, you will overwrite the existing .env.local file!" + read -p "are you sure? (Y/n) " a + if [[ $a != "n" ]] ; then + gen_dotenv + fi +else + gen_dotenv +fi + + +if [[ -e "bbgo.yaml" ]] ; then + warn "found existing bbgo.yaml, you will overwrite the existing bbgo.yaml file!" + read -p "are you sure? (Y/n) " a + if [[ $a == "n" ]] ; then + exit + fi +fi + +cat < bbgo.yaml +--- +exchangeStrategies: +- on: ${exchange} + grid: + symbol: BTCUSDT + quantity: 0.001 + gridNumber: 100 + profitSpread: 100.0 + upperPrice: 50_000.0 + lowerPrice: 10_000.0 + long: true + +END + +info "config file is generated successfully" +echo "================================================================" +echo "now you can edit your strategy config file bbgo.yaml to run bbgo" + +if [[ $osf == "darwin" ]] ; then + echo "we found you're using MacOS, you can type:" + echo "" + echo " open -a TextEdit bbgo.yaml" + echo "" +else + echo "you look like a pro user, you can edit the config by:" + echo "" + echo " vim bbgo.yaml" + echo "" +fi + +echo "To run bbgo just type: " +echo "" +echo " ./bbgo run" +echo "" +echo "To stop bbgo, just hit CTRL-C" + +if [[ $osf == "darwin" ]] ; then + open -a TextEdit bbgo.yaml +fi diff --git a/scripts/setup-grid.sh b/scripts/setup-grid.sh index dce71fc65..664c4bd5e 100755 --- a/scripts/setup-grid.sh +++ b/scripts/setup-grid.sh @@ -21,9 +21,16 @@ function info() echo -e "${GREEN}$@${NC}" } +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') osf=$(uname | tr '[:upper:]' '[:lower:]') -arch=amd64 -version=v1.21.4 +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac dist_file=bbgo-$version-$osf-$arch.tar.gz exchange=max diff --git a/scripts/setup.sh b/scripts/setup.sh index a6577e0d5..461a475e1 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,8 +1,16 @@ #!/bin/bash set -e +version=$(curl -fs https://api.github.com/repos/c9s/bbgo/releases/latest | awk -F '"' '/tag_name/{print $4}') osf=$(uname | tr '[:upper:]' '[:lower:]') -version=v1.21.4 -dist_file=bbgo-$version-$osf-amd64.tar.gz +arch="" +case $(uname -m) in + x86_64 | ia64) arch="amd64";; + arm64 | aarch64 | arm) arch="arm64";; + *) + echo "unsupported architecture: $(uname -m)" + exit 1;; +esac +dist_file=bbgo-$version-$osf-$arch.tar.gz RED='\033[0;31m' GREEN='\033[0;32m' @@ -27,7 +35,7 @@ function info() info "downloading..." curl -O -L https://github.com/c9s/bbgo/releases/download/$version/$dist_file tar xzf $dist_file -mv bbgo-$osf bbgo +mv bbgo-$osf-$arch bbgo chmod +x bbgo info "downloaded successfully"