mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
FIX: [grid2] avoid handling one orderID twice
This commit is contained in:
parent
78d65d74d2
commit
fd2032b825
|
@ -186,6 +186,9 @@ type Strategy struct {
|
|||
gridClosedCallbacks []func()
|
||||
gridErrorCallbacks []func(err error)
|
||||
|
||||
// filledOrderIDMap is used to prevent processing the same order ID twice.
|
||||
filledOrderIDMap *types.SyncOrderMap
|
||||
|
||||
// mu is used for locking the grid object field, avoid double grid opening
|
||||
mu sync.Mutex
|
||||
|
||||
|
@ -240,6 +243,7 @@ func (s *Strategy) Defaults() error {
|
|||
}
|
||||
|
||||
func (s *Strategy) Initialize() error {
|
||||
s.filledOrderIDMap = types.NewSyncOrderMap()
|
||||
s.logger = log.WithFields(s.LogFields)
|
||||
return nil
|
||||
}
|
||||
|
@ -505,8 +509,8 @@ func (s *Strategy) processFilledOrder(o types.Order) {
|
|||
|
||||
// we calculate profit only when the order is placed successfully
|
||||
if profit != nil {
|
||||
s.logger.Infof("GENERATED GRID PROFIT: %+v", profit)
|
||||
s.GridProfitStats.AddProfit(profit)
|
||||
s.logger.Infof("GENERATED GRID PROFIT: %+v; TOTAL GRID PROFIT BECOMES: %f", profit, s.GridProfitStats.TotalQuoteProfit.Float64())
|
||||
s.EmitGridProfit(s.GridProfitStats, profit)
|
||||
}
|
||||
}
|
||||
|
@ -518,6 +522,12 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
|
|||
return
|
||||
}
|
||||
|
||||
if s.filledOrderIDMap.Exists(o.OrderID) {
|
||||
s.logger.Warn("duplicated id (%d) of filled order detected", o.OrderID)
|
||||
return
|
||||
}
|
||||
s.filledOrderIDMap.Add(o)
|
||||
|
||||
s.logger.Infof("GRID ORDER FILLED: %s", o.String())
|
||||
s.updateFilledOrderMetrics(o)
|
||||
s.processFilledOrder(o)
|
||||
|
@ -2130,4 +2140,4 @@ func queryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symb
|
|||
|
||||
err = generalBackoff(ctx, op)
|
||||
return openOrders, err
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user