Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Recreate infinity grid #735

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/backtest-report/components/TradingViewChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const ordersToMarkets = (interval: string, orders: Array<Order> | void): Array<M
position: 'belowBar',
color: '#239D10',
shape: 'arrowUp',
text: ''+order.price
text: ''+order.price.toFixed(0),
//text: 'B',
});
break;
Expand All @@ -186,7 +186,7 @@ const ordersToMarkets = (interval: string, orders: Array<Order> | void): Array<M
position: 'aboveBar',
color: '#e91e63',
shape: 'arrowDown',
text: ''+order.price
text: ''+order.price.toFixed(0),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might truncate the precision for price like 1.0003355

//text: 'S',
});
break;
Expand Down
69 changes: 69 additions & 0 deletions config/infinity-grid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
sessions:
binance:
exchange: binance
envVarPrefix: binance

#max:
# exchange: max
# envVarPrefix: max

riskControls:
# This is the session-based risk controller, which let you configure different risk controller by session.
sessionBased:
# "max" is the session name that you want to configure the risk control
max:
# orderExecutor is one of the risk control
orderExecutor:
# symbol-routed order executor
bySymbol:
ETHUSDT:
# basic risk control order executor
basic:
minQuoteBalance: 10.0
maxBaseAssetBalance: 3.0
minBaseAssetBalance: 0.0
maxOrderAmount: 1000.0

# example command:
# godotenv -f .env.local -- go run ./cmd/bbgo backtest --sync-from 2020-11-01 --config config/grid.yaml --base-asset-baseline
backtest:
startTime: "2022-06-01"
endTime: "2022-06-17"
symbols:
- ETHUSDT
sessions: [binance]
accounts:
binance:
balances:
ETH: 0
USDT: 5000.0

exchangeStrategies:

#- on: binance
#grid:
#symbol: BTCUSDT
##quantity: 0.001
##amount: 50
#quantityScale:
#byPrice:
#exp:
#domain: [20_000, 70_000]
#range: [0.001, 0.0007]
#gridNumber: 33 # 33: spread = 1785
#profitSpread: 2000.0 # The profit price spread that you want to add to your sell order when your buy order is executed
#upperPrice: 70_000.0
#lowerPrice: 20_000.0
#long: true # The sell order is submitted in the same order amount as the filled corresponding buy order, rather than the same quantity.
- on: binance
infinity-grid:
symbol: ETHUSDT
interval: 1m
quantity: 0.05
initialOrderQuantity: 1
gridNumber: 10
countOfMoreOrders: 3 # +2
margin: 0.030
lowerPrice: 700
long: true
1 change: 1 addition & 0 deletions pkg/cmd/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
_ "github.com/c9s/bbgo/pkg/strategy/fmaker"
_ "github.com/c9s/bbgo/pkg/strategy/funding"
_ "github.com/c9s/bbgo/pkg/strategy/grid"
_ "github.com/c9s/bbgo/pkg/strategy/infinity-grid"
_ "github.com/c9s/bbgo/pkg/strategy/kline"
_ "github.com/c9s/bbgo/pkg/strategy/marketcap"
_ "github.com/c9s/bbgo/pkg/strategy/pivotshort"
Expand Down
4 changes: 4 additions & 0 deletions pkg/fixedpoint/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ func (a Value) MulExp(exp int) Value {
return Value(int64(float64(a) * math.Pow(10, float64(exp))))
}

func (a Value) MulPow(v Value, exp Value) Value {
return Value(int64(float64(a) * math.Pow(v.Float64(), exp.Float64())))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need also implement the same method for dnum fixedpoint.
Otherwise strategies compiled using dnum tag won't be able to pass the compilation

}

func (a Value) NumIntDigits() int {
digits := 0
target := int64(a)
Expand Down
7 changes: 4 additions & 3 deletions pkg/fixedpoint/dec_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package fixedpoint

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"math/big"
"testing"
"github.com/stretchr/testify/assert"
"encoding/json"
)

const Delta = 1e-9
Expand Down Expand Up @@ -61,6 +61,8 @@ func TestMulExp(t *testing.T) {
assert.Equal(t, digits, 3)
step := x.MulExp(-digits + 1)
assert.Equal(t, "1.66", step.String())
step = x.MulPow(NewFromInt(10), NewFromInt(int64(-digits+1)))
assert.Equal(t, "1.66", step.String())
}

func TestNew(t *testing.T) {
Expand Down Expand Up @@ -167,7 +169,6 @@ func TestJson(t *testing.T) {
assert.Equal(t, "0.00000000", p.FormatString(8))
assert.Equal(t, "0.00000000", string(e))


_ = json.Unmarshal([]byte("0.00153917575"), &p)
assert.Equal(t, "0.00153917", p.FormatString(8))

Expand Down
Loading