Skip to content

Commit

Permalink
xdepthmaker: update metrics when maxLayer == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 15, 2024
1 parent 81a9d4c commit 11394ae
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/strategy/xdepthmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,20 +1110,20 @@ func (s *Strategy) partiallyCancelOrders(ctx context.Context, maxLayer int) erro
func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {
if maxLayer == 0 {
if err := s.MakerOrderExecutor.GracefulCancel(ctx); err != nil {
log.WithError(err).Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol)
s.logger.WithError(err).Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol)
s.MakerOrderExecutor.ActiveMakerOrders().Print()
return
}
} else {
if err := s.partiallyCancelOrders(ctx, maxLayer); err != nil {
log.WithError(err).Warnf("%s partial order cancel failed", s.Symbol)
s.logger.WithError(err).Warnf("%s partial order cancel failed", s.Symbol)
return
}
}

numOfMakerOrders := s.MakerOrderExecutor.ActiveMakerOrders().NumOfOrders()
if numOfMakerOrders > 0 {
log.Warnf("maker orders are not all canceled")
s.logger.Warnf("maker orders are not all canceled")
return
}

Expand All @@ -1143,20 +1143,20 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {

bestBidPrice := bestBid.Price
bestAskPrice := bestAsk.Price
log.Infof("%s book ticker: best ask / best bid = %v / %v", s.HedgeSymbol, bestAskPrice, bestBidPrice)
s.logger.Infof("%s book ticker: best ask / best bid = %v / %v", s.HedgeSymbol, bestAskPrice, bestBidPrice)

s.lastSourcePrice.Set(bestBidPrice.Add(bestAskPrice).Div(Two))

bookLastUpdateTime := s.sourceBook.LastUpdateTime()

if _, err := s.bidPriceHeartBeat.Update(bestBid); err != nil {
log.WithError(err).Warnf("quote update error, %s price not updating, order book last update: %s ago",
s.logger.WithError(err).Warnf("quote update error, %s price not updating, order book last update: %s ago",
s.Symbol,
time.Since(bookLastUpdateTime))
}

if _, err := s.askPriceHeartBeat.Update(bestAsk); err != nil {
log.WithError(err).Warnf("quote update error, %s price not updating, order book last update: %s ago",
s.logger.WithError(err).Warnf("quote update error, %s price not updating, order book last update: %s ago",
s.Symbol,
time.Since(bookLastUpdateTime))
}
Expand All @@ -1167,7 +1167,7 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {
return
}

log.Infof("balances: %+v", balances.NotZero())
s.logger.Infof("balances: %+v", balances.NotZero())

quoteBalance, ok := balances[s.makerMarket.QuoteCurrency]
if !ok {
Expand All @@ -1194,7 +1194,9 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {

s.logger.Infof("%d orders are generated, placing...", len(submitOrders))

metrics.UpdateMakerOpenOrderMetrics(ID, s.InstanceID(), s.MakerExchange, s.Symbol, submitOrders)
if maxLayer == 0 {
metrics.UpdateMakerOpenOrderMetrics(ID, s.InstanceID(), s.MakerExchange, s.Symbol, submitOrders)
}

_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
if err != nil {
Expand Down

0 comments on commit 11394ae

Please sign in to comment.