mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 01:05:15 +00:00
grid2: use initial grid order id to query closed order history
This commit is contained in:
parent
6444fd5e03
commit
8af7d6f457
|
@ -24,6 +24,7 @@ type GridProfitStats struct {
|
||||||
Market types.Market `json:"market,omitempty"`
|
Market types.Market `json:"market,omitempty"`
|
||||||
ProfitEntries []*GridProfit `json:"profitEntries,omitempty"`
|
ProfitEntries []*GridProfit `json:"profitEntries,omitempty"`
|
||||||
Since *time.Time `json:"since,omitempty"`
|
Since *time.Time `json:"since,omitempty"`
|
||||||
|
InitialOrderID uint64 `json:"initialOrderID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGridProfitStats(market types.Market) *GridProfitStats {
|
func newGridProfitStats(market types.Market) *GridProfitStats {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package grid2
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -819,10 +820,23 @@ func (s *Strategy) openGrid(ctx context.Context, session *bbgo.ExchangeSession)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var orderIds []uint64
|
||||||
|
|
||||||
for _, order := range createdOrders {
|
for _, order := range createdOrders {
|
||||||
|
orderIds = append(orderIds, order.OrderID)
|
||||||
|
|
||||||
s.logger.Info(order.String())
|
s.logger.Info(order.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(orderIds, func(i, j int) bool {
|
||||||
|
return orderIds[i] < orderIds[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(orderIds) > 0 {
|
||||||
|
s.GridProfitStats.InitialOrderID = orderIds[0]
|
||||||
|
bbgo.Sync(ctx, s)
|
||||||
|
}
|
||||||
|
|
||||||
s.logger.Infof("ALL GRID ORDERS SUBMITTED")
|
s.logger.Infof("ALL GRID ORDERS SUBMITTED")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -997,9 +1011,13 @@ func (s *Strategy) recoverGrid(ctx context.Context, historyService types.Exchang
|
||||||
_ = lastOrderTime
|
_ = lastOrderTime
|
||||||
|
|
||||||
// for MAX exchange we need the order ID to query the closed order history
|
// for MAX exchange we need the order ID to query the closed order history
|
||||||
|
if s.GridProfitStats != nil && s.GridProfitStats.InitialOrderID > 0 {
|
||||||
|
lastOrderID = s.GridProfitStats.InitialOrderID
|
||||||
|
} else {
|
||||||
if oid, ok := findEarliestOrderID(openOrders); ok {
|
if oid, ok := findEarliestOrderID(openOrders); ok {
|
||||||
lastOrderID = oid
|
lastOrderID = oid
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
|
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
|
||||||
|
|
||||||
|
@ -1332,14 +1350,14 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
||||||
session.MarketDataStream.OnKLineClosed(s.newTakeProfitHandler(ctx, session))
|
session.MarketDataStream.OnKLineClosed(s.newTakeProfitHandler(ctx, session))
|
||||||
}
|
}
|
||||||
|
|
||||||
session.UserDataStream.OnStart(func() {
|
// if TriggerPrice is zero, that means we need to open the grid when start up
|
||||||
if s.TriggerPrice.IsZero() {
|
if s.TriggerPrice.IsZero() {
|
||||||
|
session.UserDataStream.OnStart(func() {
|
||||||
if err := s.openGrid(ctx, session); err != nil {
|
if err := s.openGrid(ctx, session); err != nil {
|
||||||
s.logger.WithError(err).Errorf("failed to setup grid orders")
|
s.logger.WithError(err).Errorf("failed to setup grid orders")
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user