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()
|
gridClosedCallbacks []func()
|
||||||
gridErrorCallbacks []func(err error)
|
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 is used for locking the grid object field, avoid double grid opening
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
||||||
|
@ -240,6 +243,7 @@ func (s *Strategy) Defaults() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) Initialize() error {
|
func (s *Strategy) Initialize() error {
|
||||||
|
s.filledOrderIDMap = types.NewSyncOrderMap()
|
||||||
s.logger = log.WithFields(s.LogFields)
|
s.logger = log.WithFields(s.LogFields)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -505,8 +509,8 @@ func (s *Strategy) processFilledOrder(o types.Order) {
|
||||||
|
|
||||||
// we calculate profit only when the order is placed successfully
|
// we calculate profit only when the order is placed successfully
|
||||||
if profit != nil {
|
if profit != nil {
|
||||||
s.logger.Infof("GENERATED GRID PROFIT: %+v", profit)
|
|
||||||
s.GridProfitStats.AddProfit(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)
|
s.EmitGridProfit(s.GridProfitStats, profit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,6 +522,12 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
|
||||||
return
|
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.logger.Infof("GRID ORDER FILLED: %s", o.String())
|
||||||
s.updateFilledOrderMetrics(o)
|
s.updateFilledOrderMetrics(o)
|
||||||
s.processFilledOrder(o)
|
s.processFilledOrder(o)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user