From 2b25c94ce8b204acdf98bd9c447cf08525f04687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=B4=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=9A=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Fri, 17 Jun 2022 14:15:35 +0700 Subject: [PATCH 1/4] recreate infinity grid --- .../components/TradingViewChart.tsx | 4 +- config/infinity-grid.yaml | 69 +++ pkg/cmd/builtin.go | 1 + pkg/strategy/infinity-grid/strategy.go | 534 ++++++++++++++++++ 4 files changed, 606 insertions(+), 2 deletions(-) create mode 100644 config/infinity-grid.yaml create mode 100644 pkg/strategy/infinity-grid/strategy.go diff --git a/apps/backtest-report/components/TradingViewChart.tsx b/apps/backtest-report/components/TradingViewChart.tsx index 5a6937f4cd..f6143230f0 100644 --- a/apps/backtest-report/components/TradingViewChart.tsx +++ b/apps/backtest-report/components/TradingViewChart.tsx @@ -176,7 +176,7 @@ const ordersToMarkets = (interval: string, orders: Array | void): Array | void): Array 0 { + quantityF = s.InitialOrderQuantity + } else { + quantityF = s.Quantity.Div(fixedpoint.NewFromFloat(1.0 - 1/(1.0+s.Margin.Float64()))) + } + + // Buy half of value of asset + order := types.SubmitOrder{ + Symbol: s.Symbol, + Side: types.SideTypeBuy, + Type: types.OrderTypeLimit, + Market: s.Market, + Quantity: quantityF, + Price: currentPrice, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + log.Infof("submitting init order: %s", order.String()) + + createdOrders, err := orderExecutor.SubmitOrders(context.Background(), order) + if err != nil { + log.WithError(err).Errorf("can not place init order") + return + } + + s.activeOrders.Add(createdOrders...) + s.orderStore.Add(createdOrders...) + } + + // Sell Side + j := 1 + for i := int64(1); i <= s.GridNum/2; i++ { + price := fixedpoint.NewFromFloat(currentPrice.Float64() * math.Pow((1.0+s.Margin.Float64()), float64(j))) + j++ + if price.Compare(s.LowerPrice) < 0 { + i-- + continue + } + + quantity := s.Quantity + //quoteQuantity := price.Mul(quantity) + if baseBalance.Available.Compare(quantity) < 0 { + log.Errorf("base balance %s %s is not enough, stop generating sell orders", + baseBalance.Currency, + baseBalance.Available.String()) + break + } + if _, filled := s.state.FilledSellGrids[price]; filled { + log.Debugf("sell grid at price %v is already filled, skipping", price) + continue + } + order := types.SubmitOrder{ + Symbol: s.Symbol, + Side: types.SideTypeSell, + Type: types.OrderTypeLimit, + Market: s.Market, + Quantity: quantity, + Price: price, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + log.Infof("%d) submitting order: %s", i, order.String()) + orders = append(orders, order) + baseBalance.Available = baseBalance.Available.Sub(quantity) + + s.state.FilledSellGrids[price] = struct{}{} + s.currentUpperGrid++ + } + + // Buy Side + for i := int64(1); i <= s.GridNum/2; i++ { + price := fixedpoint.NewFromFloat(currentPrice.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(i))) + + if price < s.LowerPrice { + break + } + + quantity := s.Quantity + quoteQuantity := price.Mul(quantity) + if quoteBalance.Available.Compare(quoteQuantity) < 0 { + log.Errorf("quote balance %s %v is not enough for %v, stop generating buy orders", + quoteBalance.Currency, + quoteBalance.Available, + quoteQuantity) + break + } + if _, filled := s.state.FilledBuyGrids[price]; filled { + log.Debugf("buy grid at price %v is already filled, skipping", price) + continue + } + order := types.SubmitOrder{ + Symbol: s.Symbol, + Side: types.SideTypeBuy, + Type: types.OrderTypeLimit, + Market: s.Market, + Quantity: quantity, + Price: price, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + log.Infof("%d) submitting order: %s", i, order.String()) + orders = append(orders, order) + + quoteBalance.Available = quoteBalance.Available.Sub(quoteQuantity) + + s.state.FilledBuyGrids[price] = struct{}{} + s.currentLowerGrid++ + } + + createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orders...) + if err != nil { + log.WithError(err).Errorf("can not place orders") + return + } + + s.activeOrders.Add(createdOrders...) + s.orderStore.Add(createdOrders...) +} + +func (s *Strategy) submitFollowingOrder(order types.Order) { + var side = order.Side.Reverse() + var orders []types.SubmitOrder + var cancelOrders []types.Order + var price fixedpoint.Value + var quantity = order.Quantity + const earlyPlacedCount = 2 + + if order.Quantity == s.InitialOrderQuantity { + return + } + + switch side { + case types.SideTypeSell: + price = order.Price.Mul(fixedpoint.NewFromFloat(1.0).Add(s.Margin)) + s.currentUpperGrid++ + s.currentLowerGrid-- + if s.Long { + quantity = s.Quantity + } + + case types.SideTypeBuy: + price = order.Price.Mul(fixedpoint.NewFromFloat(1.0).Sub(s.Margin)) + if price < s.LowerPrice { + return + } + if s.Long { + var amount = order.Price * order.Quantity + quantity = amount / price + } + s.currentUpperGrid-- + s.currentLowerGrid++ + } + + submitOrder := types.SubmitOrder{ + Symbol: s.Symbol, + Side: side, + Type: types.OrderTypeLimit, + Market: s.Market, + Quantity: quantity, + Price: price, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + + if price >= s.LowerPrice { + log.Infof("→submitting following order: %s, currentUpperGrid: %d, currentLowerGrid: %d", submitOrder.String(), s.currentUpperGrid, s.currentLowerGrid) + orders = append(orders, submitOrder) + } + + if order.Side == types.SideTypeSell && s.currentUpperGrid <= earlyPlacedCount { + // Plase a more higher order + for i := 1; i <= s.CountOfMoreOrders; i++ { + price = fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0+s.Margin.Float64()), float64(i+earlyPlacedCount))) + submitOrder := types.SubmitOrder{ + Symbol: s.Symbol, + Side: order.Side, + Market: s.Market, + Type: types.OrderTypeLimit, + Quantity: s.Quantity, + Price: price, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + + orders = append(orders, submitOrder) + s.currentUpperGrid++ + log.Infof("submitting new higher order: %s, currentUpperGrid: %d", submitOrder.String(), s.currentUpperGrid) + } + // Cleanup overabundant order limits + lowerGridPrice := fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(s.GridNum))) + for _, cancelOrder := range s.activeOrders.Orders() { + if cancelOrder.Side == types.SideTypeSell { + continue + } + if cancelOrder.Price < lowerGridPrice { + cancelOrders = append(cancelOrders, cancelOrder) + } + } + log.Infof("cleanup %d the lowest orders", len(cancelOrders)) + s.currentLowerGrid -= len(cancelOrders) + s.OrderExecutor.CancelOrders(context.Background(), cancelOrders...) + } + + if order.Side == types.SideTypeBuy && s.currentLowerGrid <= earlyPlacedCount { + // Plase a more lower order + for i := 1; i <= s.CountOfMoreOrders; i++ { + price = fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(i+earlyPlacedCount))) + + if price < s.LowerPrice { + break + } + + submitOrder := types.SubmitOrder{ + Symbol: s.Symbol, + Side: order.Side, + Market: s.Market, + Type: types.OrderTypeLimit, + Quantity: s.Quantity, + Price: price, + TimeInForce: types.TimeInForceGTC, + GroupID: s.groupID, + } + + orders = append(orders, submitOrder) + s.currentLowerGrid++ + log.Infof("submitting new lower order: %s, currentLowerGrid: %d", submitOrder.String(), s.currentLowerGrid) + } + // Cleanup overabundant order limits + upperGridPrice := fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0+s.Margin.Float64()), float64(s.GridNum))) + for _, cancelOrder := range s.activeOrders.Orders() { + if cancelOrder.Side == types.SideTypeBuy { + continue + } + if cancelOrder.Price > upperGridPrice { + cancelOrders = append(cancelOrders, cancelOrder) + } + } + log.Infof("cleanup %d the highest orders", len(cancelOrders)) + s.currentUpperGrid -= len(cancelOrders) + s.OrderExecutor.CancelOrders(context.Background(), cancelOrders...) + } + + createdOrders, err := s.OrderExecutor.SubmitOrders(context.Background(), orders...) + if err != nil { + log.WithError(err).Errorf("can not place orders") + return + } + + s.activeOrders.Add(createdOrders...) +} + +func (s *Strategy) handleFilledOrder(order types.Order) { + if order.Symbol != s.Symbol { + return + } + + //s.Notifiability.Notify("order filled: %s", order.String()) + s.submitFollowingOrder(order) +} + +func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { + session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) +} + +func (s *Strategy) LoadState() error { + instanceID := s.InstanceID() + + var state State + if s.Persistence != nil { + if err := s.Persistence.Load(&state, ID, instanceID); err != nil { + if err != service.ErrPersistenceNotExists { + return errors.Wrapf(err, "state load error") + } + + s.state = &State{ + FilledBuyGrids: make(map[fixedpoint.Value]struct{}), + FilledSellGrids: make(map[fixedpoint.Value]struct{}), + Position: types.NewPositionFromMarket(s.Market), + } + } else { + s.state = &state + } + } + + // init profit stats + s.state.ProfitStats.Init(s.Market) + + // field guards + if s.state.FilledBuyGrids == nil { + s.state.FilledBuyGrids = make(map[fixedpoint.Value]struct{}) + } + if s.state.FilledSellGrids == nil { + s.state.FilledSellGrids = make(map[fixedpoint.Value]struct{}) + } + + return nil +} + +func (s *Strategy) SaveState() error { + if s.Persistence != nil { + log.Infof("backing up grid state...") + + instanceID := s.InstanceID() + s.state.Orders = s.activeOrders.Backup() + + if err := s.Persistence.Save(s.state, ID, instanceID); err != nil { + return err + } + } + return nil +} + +// InstanceID returns the instance identifier from the current grid configuration parameters +func (s *Strategy) InstanceID() string { + return fmt.Sprintf("%s-%s-%d-%d", ID, s.Symbol, s.GridNum, s.LowerPrice.Int()) +} + +func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { + if s.GridNum == 0 { + s.GridNum = 10 + } + + instanceID := s.InstanceID() + s.groupID = util.FNV32(instanceID) + log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID) + + if err := s.LoadState(); err != nil { + return err + } + + s.Notify("grid %s position", s.Symbol, s.state.Position) + + s.orderStore = bbgo.NewOrderStore(s.Symbol) + s.orderStore.BindStream(session.UserDataStream) + + s.activeOrders = bbgo.NewActiveOrderBook(s.Symbol) + s.activeOrders.OnFilled(s.handleFilledOrder) + s.activeOrders.BindStream(session.UserDataStream) + + s.tradeCollector = bbgo.NewTradeCollector(s.Symbol, s.state.Position, s.orderStore) + + s.tradeCollector.OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) { + s.Notifiability.Notify(trade) + // hack to reset today reset logic + s.state.ProfitStats.TodaySince = trade.Time.Unix() + s.state.ProfitStats.AddTrade(trade) + }) + + s.tradeCollector.OnPositionUpdate(func(position *types.Position) { + s.Notifiability.Notify(position) + }) + s.tradeCollector.BindStream(session.UserDataStream) + + s.currentLowerGrid = 0 + s.currentUpperGrid = 0 + + s.Graceful.OnShutdown(func(ctx context.Context, wg *sync.WaitGroup) { + defer wg.Done() + + if err := s.SaveState(); err != nil { + log.WithError(err).Errorf("can not save state: %+v", s.state) + } else { + s.Notify("%s: %s grid is saved", ID, s.Symbol) + } + + // now we can cancel the open orders + log.Infof("canceling %d active orders...", s.activeOrders.NumOfOrders()) + if err := session.Exchange.CancelOrders(ctx, s.activeOrders.Orders()...); err != nil { + log.WithError(err).Errorf("cancel order error") + } + + //log.Infoln(s.state.ProfitStats.PlainText()) + }) + session.MarketDataStream.OnConnect(func() {}) + session.UserDataStream.OnStart(func() { + if len(s.state.Orders) > 0 { + s.Notifiability.Notify("restoring %s %d grid orders...", s.Symbol, len(s.state.Orders)) + + createdOrders, err := orderExecutor.SubmitOrders(ctx, s.state.Orders...) + if err != nil { + log.WithError(err).Error("active orders restore error") + } + s.activeOrders.Add(createdOrders...) + s.orderStore.Add(createdOrders...) + } else { + s.placeInfiniteGridOrders(orderExecutor, session) + } + }) + + return nil +} From b9425e29e924a36e1008c223ba9a0c10b6cfe593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=B4=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=9A=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Sat, 18 Jun 2022 15:50:51 +0700 Subject: [PATCH 2/4] fix all fixedpoint issues --- pkg/fixedpoint/convert.go | 4 +++ pkg/fixedpoint/dec_test.go | 6 ++-- pkg/strategy/infinity-grid/strategy.go | 43 +++++++++++--------------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/pkg/fixedpoint/convert.go b/pkg/fixedpoint/convert.go index f70f25885d..6e21741380 100644 --- a/pkg/fixedpoint/convert.go +++ b/pkg/fixedpoint/convert.go @@ -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()))) +} + func (a Value) NumIntDigits() int { digits := 0 target := int64(a) diff --git a/pkg/fixedpoint/dec_test.go b/pkg/fixedpoint/dec_test.go index da23679adf..b482c7acc2 100644 --- a/pkg/fixedpoint/dec_test.go +++ b/pkg/fixedpoint/dec_test.go @@ -1,10 +1,11 @@ package fixedpoint import ( + "encoding/json" "math/big" "testing" + "github.com/stretchr/testify/assert" - "encoding/json" ) const Delta = 1e-9 @@ -61,6 +62,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) { @@ -167,7 +170,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)) diff --git a/pkg/strategy/infinity-grid/strategy.go b/pkg/strategy/infinity-grid/strategy.go index 6471330a6d..e246011fa5 100644 --- a/pkg/strategy/infinity-grid/strategy.go +++ b/pkg/strategy/infinity-grid/strategy.go @@ -128,7 +128,7 @@ func (s *Strategy) placeInfiniteGridOrders(orderExecutor bbgo.OrderExecutor, ses } quoteBalance, ok := balances[s.Market.QuoteCurrency] - if !ok || quoteBalance.Available <= 0 { // check available USD in balance + if !ok || quoteBalance.Available.Compare(fixedpoint.Zero) < 0 { // check available USD in balance log.Errorf("quote balance %s not found", s.Market.QuoteCurrency) return } @@ -140,18 +140,14 @@ func (s *Strategy) placeInfiniteGridOrders(orderExecutor bbgo.OrderExecutor, ses return } - if false { - if s.InitialOrderQuantity > 0 { - quantityF = s.InitialOrderQuantity - } else { - quantityF = s.Quantity.Div(fixedpoint.NewFromFloat(1.0 - 1/(1.0+s.Margin.Float64()))) - } - + quantityF = s.Quantity + if s.InitialOrderQuantity.Compare(fixedpoint.Zero) > 0 { + quantityF = s.InitialOrderQuantity // Buy half of value of asset order := types.SubmitOrder{ Symbol: s.Symbol, Side: types.SideTypeBuy, - Type: types.OrderTypeLimit, + Type: types.OrderTypeMarket, Market: s.Market, Quantity: quantityF, Price: currentPrice, @@ -214,7 +210,7 @@ func (s *Strategy) placeInfiniteGridOrders(orderExecutor bbgo.OrderExecutor, ses for i := int64(1); i <= s.GridNum/2; i++ { price := fixedpoint.NewFromFloat(currentPrice.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(i))) - if price < s.LowerPrice { + if price.Compare(s.LowerPrice) < 0 { break } @@ -268,7 +264,7 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { var quantity = order.Quantity const earlyPlacedCount = 2 - if order.Quantity == s.InitialOrderQuantity { + if order.Quantity.Eq(s.InitialOrderQuantity) { return } @@ -283,12 +279,12 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { case types.SideTypeBuy: price = order.Price.Mul(fixedpoint.NewFromFloat(1.0).Sub(s.Margin)) - if price < s.LowerPrice { + if price.Compare(s.LowerPrice) < 0 { return } if s.Long { - var amount = order.Price * order.Quantity - quantity = amount / price + var amount = order.Price.Mul(order.Quantity) + quantity = amount.Div(price) } s.currentUpperGrid-- s.currentLowerGrid++ @@ -305,7 +301,7 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { GroupID: s.groupID, } - if price >= s.LowerPrice { + if price.Compare(s.LowerPrice) >= 0 { log.Infof("→submitting following order: %s, currentUpperGrid: %d, currentLowerGrid: %d", submitOrder.String(), s.currentUpperGrid, s.currentLowerGrid) orders = append(orders, submitOrder) } @@ -313,7 +309,7 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { if order.Side == types.SideTypeSell && s.currentUpperGrid <= earlyPlacedCount { // Plase a more higher order for i := 1; i <= s.CountOfMoreOrders; i++ { - price = fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0+s.Margin.Float64()), float64(i+earlyPlacedCount))) + price = order.Price.MulPow(fixedpoint.NewFromFloat(1.0).Add(s.Margin), fixedpoint.NewFromInt(int64(i+earlyPlacedCount))) submitOrder := types.SubmitOrder{ Symbol: s.Symbol, Side: order.Side, @@ -330,12 +326,12 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { log.Infof("submitting new higher order: %s, currentUpperGrid: %d", submitOrder.String(), s.currentUpperGrid) } // Cleanup overabundant order limits - lowerGridPrice := fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(s.GridNum))) + lowerGridPrice := order.Price.MulPow(fixedpoint.NewFromFloat(1.0).Sub(s.Margin), fixedpoint.NewFromInt(int64(s.GridNum))) for _, cancelOrder := range s.activeOrders.Orders() { if cancelOrder.Side == types.SideTypeSell { continue } - if cancelOrder.Price < lowerGridPrice { + if cancelOrder.Price.Compare(lowerGridPrice) < 0 { cancelOrders = append(cancelOrders, cancelOrder) } } @@ -347,9 +343,9 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { if order.Side == types.SideTypeBuy && s.currentLowerGrid <= earlyPlacedCount { // Plase a more lower order for i := 1; i <= s.CountOfMoreOrders; i++ { - price = fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0-s.Margin.Float64()), float64(i+earlyPlacedCount))) + price = order.Price.MulPow(fixedpoint.NewFromFloat(1.0).Sub(s.Margin), fixedpoint.NewFromInt(int64(i+earlyPlacedCount))) - if price < s.LowerPrice { + if price.Compare(s.LowerPrice) < 0 { break } @@ -369,12 +365,12 @@ func (s *Strategy) submitFollowingOrder(order types.Order) { log.Infof("submitting new lower order: %s, currentLowerGrid: %d", submitOrder.String(), s.currentLowerGrid) } // Cleanup overabundant order limits - upperGridPrice := fixedpoint.NewFromFloat(order.Price.Float64() * math.Pow((1.0+s.Margin.Float64()), float64(s.GridNum))) + upperGridPrice := order.Price.MulPow(fixedpoint.NewFromFloat(1.0).Add(s.Margin), fixedpoint.NewFromInt(int64(s.GridNum))) for _, cancelOrder := range s.activeOrders.Orders() { if cancelOrder.Side == types.SideTypeBuy { continue } - if cancelOrder.Price > upperGridPrice { + if cancelOrder.Price.Compare(upperGridPrice) > 0 { cancelOrders = append(cancelOrders, cancelOrder) } } @@ -484,9 +480,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.tradeCollector.OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) { s.Notifiability.Notify(trade) - // hack to reset today reset logic - s.state.ProfitStats.TodaySince = trade.Time.Unix() - s.state.ProfitStats.AddTrade(trade) }) s.tradeCollector.OnPositionUpdate(func(position *types.Position) { From dd01460bcb873a120b20a902d1125a2db45b6db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=B4=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=9A=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Sat, 18 Jun 2022 16:04:31 +0700 Subject: [PATCH 3/4] refactor initial order quantity, but it's not work --- config/infinity-grid.yaml | 4 ++-- pkg/strategy/infinity-grid/strategy.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/config/infinity-grid.yaml b/config/infinity-grid.yaml index 3cae415397..7a73b8cf6a 100644 --- a/config/infinity-grid.yaml +++ b/config/infinity-grid.yaml @@ -36,7 +36,7 @@ backtest: accounts: binance: balances: - ETH: 1 + ETH: 0 USDT: 5000.0 exchangeStrategies: @@ -61,7 +61,7 @@ exchangeStrategies: symbol: ETHUSDT interval: 1m quantity: 0.05 - #initialOrderQuantity: 0.05 + initialOrderQuantity: 1 gridNumber: 10 countOfMoreOrders: 3 # +2 margin: 0.030 diff --git a/pkg/strategy/infinity-grid/strategy.go b/pkg/strategy/infinity-grid/strategy.go index e246011fa5..ac4ee781fb 100644 --- a/pkg/strategy/infinity-grid/strategy.go +++ b/pkg/strategy/infinity-grid/strategy.go @@ -155,15 +155,17 @@ func (s *Strategy) placeInfiniteGridOrders(orderExecutor bbgo.OrderExecutor, ses GroupID: s.groupID, } log.Infof("submitting init order: %s", order.String()) + orders = append(orders, order) - createdOrders, err := orderExecutor.SubmitOrders(context.Background(), order) - if err != nil { - log.WithError(err).Errorf("can not place init order") - return - } + baseBalance.Available = baseBalance.Available.Add(quantityF) + //createdOrders, err := orderExecutor.SubmitOrders(context.Background(), order) + //if err != nil { + //log.WithError(err).Errorf("can not place init order") + //return + //} - s.activeOrders.Add(createdOrders...) - s.orderStore.Add(createdOrders...) + //s.activeOrders.Add(createdOrders...) + //s.orderStore.Add(createdOrders...) } // Sell Side From 523e7df5f23227fbf64dfefa07db6d8a8e1549c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=B4=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=9A=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Sat, 18 Jun 2022 16:16:05 +0700 Subject: [PATCH 4/4] fix merge conflict, revert original pkg import order --- pkg/fixedpoint/dec_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/fixedpoint/dec_test.go b/pkg/fixedpoint/dec_test.go index b482c7acc2..8fd5105277 100644 --- a/pkg/fixedpoint/dec_test.go +++ b/pkg/fixedpoint/dec_test.go @@ -2,10 +2,9 @@ package fixedpoint import ( "encoding/json" + "github.com/stretchr/testify/assert" "math/big" "testing" - - "github.com/stretchr/testify/assert" ) const Delta = 1e-9