Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: active orders observability TODOs #469

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ingest/usecase/ingest_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ func (p *ingestUseCase) parsePoolData(ctx context.Context, poolData []*types.Poo
// and to avoid potential deadlock.
go func() {
if err := p.orderBookUseCase.ProcessPool(ctx, poolResult.pool); err != nil {
// TODO: (alert) if failed to process orderbook pool, add an alert
// Prometheus metric counter and alert

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing the alert mechanism.

The TODO comment suggests adding an alert if processing the orderbook pool fails. Implementing this will enhance monitoring.

Do you want me to generate the alert mechanism code or open a GitHub issue to track this task?

p.logger.Error("failed to process orderbook pool", zap.Error(err), zap.Uint64("pool_id", poolID))
}
}()
Expand Down
21 changes: 16 additions & 5 deletions orderbook/usecase/orderbook_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ func (o *orderbookUseCaseImpl) GetActiveOrders(ctx context.Context, address stri
for _, orderbook := range orderbooks {
orders, count, err := o.orderBookClient.GetActiveOrders(context.TODO(), orderbook.ContractAddress, address)
if err != nil {
o.logger.Info("failed to fetch active orders", zap.Any("contract", orderbook.ContractAddress), zap.Any("contract", address), zap.Any("err", err))
o.logger.Error("failed to fetch active orders", zap.Any("contract", orderbook.ContractAddress), zap.Any("contract", address), zap.Any("err", err))

// TODO: (alert) if failed to fetch active orders, add an alert
// Prometheus metric counter and alert

continue
}

Expand Down Expand Up @@ -159,7 +163,7 @@ func (o *orderbookUseCaseImpl) GetActiveOrders(ctx context.Context, address stri
if !ok {
o.logger.Info("tick not found", zap.Any("contract", orderbook.ContractAddress), zap.Any("ticks", order.TickId), zap.Any("ok", ok))

// TODO: if tick not found, add an alert
// TODO: (alert) if tick not found, add an alert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing the alert mechanism.

The TODO comment suggests adding an alert if a tick is not found. Implementing this will enhance monitoring.

Do you want me to generate the alert mechanism code or open a GitHub issue to track this task?

// Prometheus metric counter and alert
}

Expand All @@ -178,7 +182,11 @@ func (o *orderbookUseCaseImpl) GetActiveOrders(ctx context.Context, address stri
orderbook.ContractAddress,
)
if err != nil {
o.logger.Info("failed to create limit order", zap.Any("order", order), zap.Any("err", err))
o.logger.Error("failed to create limit order", zap.Any("order", order), zap.Any("err", err))

// TODO: (alert) if failed to create limit order, add an alert
// Prometheus metric counter and alert

continue
}

Expand Down Expand Up @@ -221,7 +229,10 @@ func (o *orderbookUseCaseImpl) createLimitOrder(
percentClaimed := placedQuantityDec.Sub(quantityDec).Quo(placedQuantityDec)

// Calculate normalization factor for price
normalizationFactor := osmomath.NewDec(10).Power(uint64(quoteAsset.Decimals - baseAsset.Decimals))
normalizationFactor, err := o.tokensUsecease.GetSpotPriceScalingFactorByDenom(baseAsset.Symbol, quoteAsset.Symbol)
if err != nil {
return orderbookdomain.LimitOrder{}, fmt.Errorf("error getting spot price scaling factor: %w", err)
}

// Determine tick values and unrealized cancels based on order direction
var tickEtas, tickUnrealizedCancelled int64
Expand Down Expand Up @@ -288,7 +299,7 @@ func (o *orderbookUseCaseImpl) createLimitOrder(
}

// Calculate normalized price
normalizedPrice := price.Dec().Quo(normalizationFactor)
normalizedPrice := price.Dec().Mul(normalizationFactor)

// Convert placed_at to a nano second timestamp
placedAt, err := strconv.ParseInt(order.PlacedAt, 10, 64)
Expand Down
Loading