Skip to content

Commit

Permalink
optimize balance metrics updater
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 17, 2025
1 parent 7ce6f3e commit 072f1cd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,18 +984,28 @@ func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap
"symbol": session.IsolatedMarginSymbol,
}

metricsTotalBalancesCurry := metricsTotalBalances.MustCurryWith(labels)
metricsBalanceNetMetricsCurry := metricsBalanceNetMetrics.MustCurryWith(labels)
metricsBalanceAvailableMetricsCurry := metricsBalanceAvailableMetrics.MustCurryWith(labels)
metricsBalanceLockedMetricsCurry := metricsBalanceLockedMetrics.MustCurryWith(labels)
metricsBalanceDebtMetricsCurry := metricsBalanceDebtMetrics.MustCurryWith(labels)
metricsBalanceBorrowedMetricsCurry := metricsBalanceBorrowedMetrics.MustCurryWith(labels)
metricsBalanceInterestMetricsCurry := metricsBalanceInterestMetrics.MustCurryWith(labels)

for currency, balance := range balances {
labels["currency"] = currency
curLabels := prometheus.Labels{
"currency": currency,
}

metricsTotalBalances.With(labels).Set(balance.Total().Float64())
metricsBalanceNetMetrics.With(labels).Set(balance.Net().Float64())
metricsBalanceAvailableMetrics.With(labels).Set(balance.Available.Float64())
metricsBalanceLockedMetrics.With(labels).Set(balance.Locked.Float64())
metricsTotalBalancesCurry.With(curLabels).Set(balance.Total().Float64())
metricsBalanceNetMetricsCurry.With(curLabels).Set(balance.Net().Float64())
metricsBalanceAvailableMetricsCurry.With(curLabels).Set(balance.Available.Float64())
metricsBalanceLockedMetricsCurry.With(curLabels).Set(balance.Locked.Float64())

// margin metrics
metricsBalanceDebtMetrics.With(labels).Set(balance.Debt().Float64())
metricsBalanceBorrowedMetrics.With(labels).Set(balance.Borrowed.Float64())
metricsBalanceInterestMetrics.With(labels).Set(balance.Interest.Float64())
metricsBalanceDebtMetricsCurry.With(curLabels).Set(balance.Debt().Float64())
metricsBalanceBorrowedMetricsCurry.With(curLabels).Set(balance.Borrowed.Float64())
metricsBalanceInterestMetricsCurry.With(curLabels).Set(balance.Interest.Float64())

metricsLastUpdateTimeMetrics.With(prometheus.Labels{
"session": session.Name,
Expand All @@ -1007,7 +1017,6 @@ func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap
"currency": currency,
}).SetToCurrentTime()
}

}

func (session *ExchangeSession) metricsOrderUpdater(order types.Order) {
Expand Down

0 comments on commit 072f1cd

Please sign in to comment.