mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
FEATURE: move metrics to defer funciton
This commit is contained in:
parent
68f54c032a
commit
d00a91441c
|
@ -14,6 +14,11 @@ import (
|
|||
)
|
||||
|
||||
func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.ExchangeSession) error {
|
||||
defer func() {
|
||||
s.updateGridNumOfOrdersMetricsWithLock()
|
||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||
}()
|
||||
|
||||
historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService)
|
||||
// if the exchange doesn't support ExchangeTradeHistoryService, do not run recover
|
||||
if !implemented {
|
||||
|
@ -64,8 +69,6 @@ func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.Ex
|
|||
debugGrid(s.logger, s.grid, s.orderExecutor.ActiveMakerOrders())
|
||||
// emit ready after recover
|
||||
s.EmitGridReady()
|
||||
s.updateGridNumOfOrdersMetricsWithLock()
|
||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -79,9 +82,6 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
|
|||
grid := s.newGrid()
|
||||
s.setGrid(grid)
|
||||
|
||||
// add open orders to active order book
|
||||
s.addOrdersToActiveOrderBook(openOrdersOnGrid)
|
||||
|
||||
expectedNumOfOrders := s.GridNum - 1
|
||||
numGridOpenOrders := int64(len(openOrdersOnGrid))
|
||||
s.debugLog("open orders nums: %d, expected nums: %d", numGridOpenOrders, expectedNumOfOrders)
|
||||
|
@ -121,9 +121,11 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
|
|||
return errors.Wrapf(err, "verify grid with error")
|
||||
}
|
||||
|
||||
s.debugOrders("emit filled orders", filledOrders)
|
||||
// 5. add open orders to active order book
|
||||
s.addOrdersToActiveOrderBook(openOrdersOnGrid)
|
||||
|
||||
// 5. emit the filled orders
|
||||
// 6. emit the filled orders
|
||||
s.debugOrders("emit filled orders", filledOrders)
|
||||
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
|
||||
for _, filledOrder := range filledOrders {
|
||||
activeOrderBook.EmitFilled(filledOrder)
|
||||
|
|
Loading…
Reference in New Issue
Block a user