Skip to content

Commit

Permalink
feature: add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zenixls2 committed Jun 17, 2022
1 parent 55fa4cc commit ba1342c
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 35 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
env:
MYSQL_DATABASE: bbgo
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
MYSQL_PASSWORD: "root" # pragma: allowlist secret

steps:

Expand Down Expand Up @@ -48,6 +48,15 @@ jobs:
with:
go-version: 1.18

- name: Run pre-commit
run: |
pip install pre-commit
go get -v -u github.com/go-critic/go-critic/cmd/gocritic
pre-commit install-hooks
pre-commit run markdownlint --files=README.md --verbose
pre-commit run go-fmt --all-files --verbose
pre-commit run go-critic --all-files --verbose
- name: Install Migration Tool
run: go install github.com/c9s/rockhopper/cmd/rockhopper@v1.2.1

Expand Down
5 changes: 5 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
default: true
extends: null
MD033: false
MD010: false
MD013: false
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
repos:
# Secret Detection
- repo: https://github.com/Yelp/detect-secrets
rev: v1.2.0
hooks:
- id: detect-secrets
args: ['--exclude-secrets', '3899a918953e01bfe218116cdfeccbed579e26275c4a89abcbc70d2cb9e9bbb8']
exclude: pacakge.lock.json
# Markdown
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.31.1
hooks:
- id: markdownlint
# Go
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
args: ['-l']
- id: go-critic
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ A trading bot framework written in Go. The name bbgo comes from the BB8 bot in t
## Current Status

[![Go](https://github.com/c9s/bbgo/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/c9s/bbgo/actions/workflows/go.yml)
[![GoDoc](https://godoc.org/github.com/c9s/bbgo?status.svg)](https://pkg.go.dev/github.com/c9s/bbgo)
[![Go Report Card](https://goreportcard.com/badge/github.com/c9s/bbgo)](https://goreportcard.com/report/github.com/c9s/bbgo)
[![DockerHub](https://img.shields.io/docker/pulls/yoanlin/bbgo.svg)](https://hub.docker.com/r/yoanlin/bbgo)
[![Coverage Status](http://codecov.io/github/c9s/bbgo/coverage.svg?branch=main)](http://codecov.io/github/c9s/bbgo?branch=main)
<img alt="open collective badge" src="https://opencollective.com/bbgo/tiers/badge.svg">
Expand Down Expand Up @@ -42,7 +44,38 @@ You can use BBGO's underlying common exchange API, currently it supports 4+ majo
- Built-in parameter optimization tool.
- Built-in Grid strategy and many other built-in strategies.
- Multi-exchange session support: you can connect to more than 2 exchanges with different accounts or subaccounts.
- Standard indicators, e.g., SMA, EMA, BOLL, VMA, MACD...
- Indicators with interface similar to `pandas.Series`([series](https://github.com/c9s/bbgo/blob/main/doc/development/series.md))([usage](https://github.com/c9s/bbgo/blob/main/doc/development/indicator.md)):
- [Accumulation/Distribution Indicator](./pkg/indicator/ad.go)
- [Arnaud Legoux Moving Average](./pkg/indicator/alma.go)
- [Average True Range](./pkg/indicator/atr.go)
- [Bollinger Bands](./pkg/indicator/boll.go)
- [Commodity Channel Index](./pkg/indicator/cci.go)
- [Cumulative Moving Average](./pkg/indicator/cma.go)
- [Double Exponential Moving Average](./pkg/indicator/dema.go)
- [Directional Movement Index](./pkg/indicator/dmi.go)
- [Brownian Motion's Drift Factor](./pkg/indicator/drift.go)
- [Ease of Movement](./pkg/indicator/emv.go)
- [Exponentially Weighted Moving Average](./pkg/indicator/ewma.go)
- [Hull Moving Average](./pkg/indicator/hull.go)
- [Trend Line (Tool)](./pkg/indicator/line.go)
- [Moving Average Convergence Divergence Indicator](./pkg/indicator/macd.go)
- [On-Balance Volume](./pkg/indicator/obv.go)
- [Pivot](./pkg/indicator/pivot.go)
- [Running Moving Average](./pkg/indicator/rma.go)
- [Relative Strength Index](./pkg/indicator/rsi.go)
- [Simple Moving Average](./pkg/indicator/sma.go)
- [Ehler's Super Smoother Filter](./pkg/indicator/ssf.go)
- [Stochastic Oscillator](./pkg/indicator/stoch.go)
- [SuperTrend](./pkg/indicator/supertrend.go)
- [Triple Exponential Moving Average](./pkg/indicator/tema.go)
- [Tillson T3 Moving Average](./pkg/indicator/till.go)
- [Triangular Moving Average](./pkg/indicator/tma.go)
- [Variable Index Dynamic Average](./pkg/indicator/vidya.go)
- [Volatility Indicator](./pkg/indicator/volatility.go)
- [Volume Weighted Average Price](./pkg/indicator/vwap.go)
- [Zero Lag Exponential Moving Average](./pkg/indicator/zlema.go)
- And more...
- HeikinAshi OHLC / Normal OHLC (check [this config](https://github.com/c9s/bbgo/blob/main/config/skeleton.yaml#L5))
- React-powered Web Dashboard.
- Docker image ready.
- Kubernetes support.
Expand All @@ -51,7 +84,7 @@ You can use BBGO's underlying common exchange API, currently it supports 4+ majo

## Screenshots

![bbgo dashboard](assets/screenshots/dashboard.jpeg)
![bbgo dashboard](assets/screenshots/dashboard.jpeg)

![bbgo backtest report](assets/screenshots/backtest-report.jpg)

Expand All @@ -63,8 +96,8 @@ You can use BBGO's underlying common exchange API, currently it supports 4+ majo
- Kucoin Spot Exchange
- MAX Spot Exchange (located in Taiwan)


## Documentation and General Topics

- Check the [documentation index](doc/README.md)

## BBGO Tokenomics
Expand Down Expand Up @@ -105,6 +138,7 @@ bash <(curl -s https://raw.githubusercontent.com/c9s/bbgo/main/scripts/setup-bol
```

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)
```
Expand All @@ -114,7 +148,7 @@ Or refer to the [Release Page](https://github.com/c9s/bbgo/releases) and downloa
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:
### One-click Linode StackScript

- BBGO Grid Trading on Binance <https://cloud.linode.com/stackscripts/950715>
- BBGO USDT/TWD Grid Trading on MAX <https://cloud.linode.com/stackscripts/793380>
Expand Down Expand Up @@ -165,14 +199,12 @@ Prepare your dotenv file `.env.local` and BBGO yaml config file `bbgo.yaml`.

To check the available environment variables, please see [Environment Variables](./doc/configuration/envvars.md)


The minimal bbgo.yaml could be generated by:

```sh
curl -o bbgo.yaml https://raw.githubusercontent.com/c9s/bbgo/main/config/minimal.yaml
```


To run strategy:

```sh
Expand All @@ -185,14 +217,12 @@ To start bbgo with the frontend dashboard:
bbgo run --enable-webserver
```


If you want to switch to other dotenv file, you can add an `--dotenv` option or `--config`:

```sh
bbgo sync --dotenv .env.dev --config config/grid.yaml --session binance
```


To query transfer history:

```sh
Expand All @@ -207,13 +237,13 @@ bbgo pnl --exchange binance --asset BTC --since "2019-01-01"
```
--->


## Advanced Configuration

### Testnet (Paper Trading)

Currently only supports binance testnet.
To run bbgo in testnet, apply new API keys from [Binance Test Network](https://testnet.binance.vision), and set the following env before you start bbgo:

```bash
export PAPER_TRADE=1
export DISABLE_MARKET_CACHE=1 # the symbols supported in testnet is far less than the mainnet
Expand Down
9 changes: 5 additions & 4 deletions pkg/bbgo/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,11 @@ func (environ *Environment) setupInteraction(persistence service.PersistenceServ
}

interact.AddCustomInteraction(&interact.AuthInteract{
Strict: authStrict,
Mode: authMode,
Token: authToken, // can be empty string here
OneTimePasswordKey: key, // can be nil here
Strict: authStrict,
Mode: authMode,
Token: authToken, // can be empty string here
// pragma: allowlist nextline secret
OneTimePasswordKey: key, // can be nil here
})
return nil
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/bbgo/strategycontroller_callbacks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/datasource/coinmarketcap/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func New() *RestClient {
}

func (c *RestClient) Auth(apiKey string) {
// pragma: allowlist nextline secret
c.apiKey = apiKey
}

Expand Down
1 change: 1 addition & 0 deletions pkg/datasource/glassnode/glassnodeapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewRestClient() *RestClient {
}

func (c *RestClient) Auth(apiKey string) {
// pragma: allowlist nextline secret
c.apiKey = apiKey
}

Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/binance/binanceapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewClient(baseURL string) *RestClient {

func (c *RestClient) Auth(key, secret string) {
c.Key = key
// pragma: allowlist nextline secret
c.Secret = secret
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/exchange/binance/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func New(key, secret string) *Exchange {
}

return &Exchange{
key: key,
key: key,
// pragma: allowlist nextline secret
secret: secret,
client: client,
futuresClient: futuresClient,
Expand Down
5 changes: 3 additions & 2 deletions pkg/exchange/ftx/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func NewExchange(key, secret string, subAccount string) *Exchange {
client: client,
restEndpoint: u,
key: key,
secret: secret,
subAccount: subAccount,
// pragma: allowlist nextline secret
secret: secret,
subAccount: subAccount,
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/ftx/ftxapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewClient() *RestClient {

func (c *RestClient) Auth(key, secret, subAccount string) {
c.Key = key
// pragma: allowlist nextline secret
c.Secret = secret
c.subAccount = subAccount
}
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/ftx/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func newRestRequest(c *http.Client, baseURL *url.URL) *restRequest {

func (r *restRequest) Auth(key, secret string) *restRequest {
r.key = key
// pragma: allowlist nextline secret
r.secret = secret
return r
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/exchange/ftx/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type klineSubscription struct {

func NewStream(key, secret string, subAccount string, e *Exchange) *Stream {
s := &Stream{
exchange: e,
key: key,
exchange: e,
key: key,
// pragma: allowlist nextline secret
secret: secret,
subAccount: subAccount,
StandardStream: &types.StandardStream{},
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/ftx/websocket_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func Test_insertAt(t *testing.T) {
func Test_newLoginRequest(t *testing.T) {
// From API doc: https://docs.ftx.com/?javascript#authentication-2
r := newLoginRequest("", "Y2QTHI23f23f23jfjas23f23To0RfUwX3H42fvN-", time.Unix(0, 1557246346499*int64(time.Millisecond)), "")
// pragma: allowlist nextline secret
expectedSignature := "d10b5a67a1a941ae9463a60b285ae845cdeac1b11edc7da9977bef0228b96de9"
assert.Equal(t, expectedSignature, r.Login.Signature)
jsonStr, err := json.Marshal(r)
Expand Down
3 changes: 2 additions & 1 deletion pkg/exchange/kucoin/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func New(key, secret, passphrase string) *Exchange {
}

return &Exchange{
key: key,
key: key,
// pragma: allowlist nextline secret
secret: secret,
passphrase: passphrase,
client: client,
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/kucoin/kucoinapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewClient() *RestClient {

func (c *RestClient) Auth(key, secret, passphrase string) {
c.Key = key
// pragma: allowlist nextline secret
c.Secret = secret
c.Passphrase = passphrase
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/exchange/max/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func New(key, secret string) *Exchange {
client := maxapi.NewRestClient(baseURL)
client.Auth(key, secret)
return &Exchange{
client: client,
key: key,
client: client,
key: key,
// pragma: allowlist nextline secret
secret: secret,
v3order: &v3.OrderService{Client: client},
v3margin: &v3.MarginService{Client: client},
Expand Down
2 changes: 2 additions & 0 deletions pkg/exchange/max/maxapi/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func NewRestClient(baseURL string) *RestClient {

// Auth sets api key and secret for usage is requests that requires authentication.
func (c *RestClient) Auth(key string, secret string) *RestClient {
// pragma: allowlist nextline secret
c.APIKey = key
// pragma: allowlist nextline secret
c.APISecret = secret
return c
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/exchange/max/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func NewStream(key, secret string) *Stream {
stream := &Stream{
StandardStream: types.NewStandardStream(),
key: key,
secret: secret,
// pragma: allowlist nextline secret
secret: secret,
}
stream.SetEndpointCreator(stream.getEndpoint)
stream.SetParser(max.ParseMessage)
Expand Down Expand Up @@ -116,7 +117,9 @@ func (s *Stream) handleConnect() {

nonce := time.Now().UnixNano() / int64(time.Millisecond)
auth := &max.AuthMessage{
Action: "auth",
// pragma: allowlist nextline secret
Action: "auth",
// pragma: allowlist nextline secret
APIKey: s.key,
Nonce: nonce,
Signature: signPayload(fmt.Sprintf("%d", nonce), s.secret),
Expand Down
3 changes: 2 additions & 1 deletion pkg/exchange/okex/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func New(key, secret, passphrase string) *Exchange {
}

return &Exchange{
key: key,
key: key,
// pragma: allowlist nextline secret
secret: secret,
passphrase: passphrase,
client: client,
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/okex/okexapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func NewClient() *RestClient {

func (c *RestClient) Auth(key, secret, passphrase string) {
c.Key = key
// pragma: allowlist nextline secret
c.Secret = secret
c.Passphrase = passphrase
}
Expand Down
Loading

0 comments on commit ba1342c

Please sign in to comment.