bbgo_origin/pkg/metrics/maker.go

89 lines
2.7 KiB
Go
Raw Normal View History

2024-11-15 15:55:38 +00:00
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
2024-11-15 15:55:38 +00:00
var OpenOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_open_order_bid_exposure_in_usd",
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var OpenOrderAskExposureInUsdMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_open_order_ask_exposure_in_usd",
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var OpenOrderBidOrderCountMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_open_order_bid_count",
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var OpenOrderAskOrderCountMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_open_order_ask_count",
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
2024-11-15 15:55:38 +00:00
var MakerBestBidPriceMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_best_bid_price",
2024-11-15 15:55:38 +00:00
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var MakerBestAskPriceMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bbgo_maker_best_ask_price",
2024-11-15 15:55:38 +00:00
Help: "",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
func UpdateOpenOrderMetrics(strategyType, strategyId, exchangeName, symbol string, submitOrders []types.SubmitOrder) {
bidOrderCount := 0
askOrderCount := 0
bidExposureQuoteAmount := fixedpoint.Zero
askExposureQuoteAmount := fixedpoint.Zero
for _, submitOrder := range submitOrders {
quoteAmount := submitOrder.Quantity.Mul(submitOrder.Price)
switch submitOrder.Side {
case types.SideTypeSell:
askExposureQuoteAmount = askExposureQuoteAmount.Add(quoteAmount)
askOrderCount++
case types.SideTypeBuy:
bidExposureQuoteAmount = bidExposureQuoteAmount.Add(quoteAmount)
bidOrderCount++
}
}
labels := prometheus.Labels{
"strategy_type": strategyType,
"strategy_id": strategyId,
"exchange": exchangeName,
"symbol": symbol,
}
OpenOrderBidExposureInUsdMetrics.With(labels).Set(bidExposureQuoteAmount.Float64())
OpenOrderAskExposureInUsdMetrics.With(labels).Set(askExposureQuoteAmount.Float64())
OpenOrderBidOrderCountMetrics.With(labels).Set(float64(bidOrderCount))
OpenOrderAskOrderCountMetrics.With(labels).Set(float64(askOrderCount))
}
2024-11-15 15:55:38 +00:00
func init() {
prometheus.MustRegister(
OpenOrderAskExposureInUsdMetrics,
OpenOrderBidExposureInUsdMetrics,
MakerBestAskPriceMetrics,
MakerBestBidPriceMetrics,
OpenOrderAskOrderCountMetrics,
OpenOrderBidOrderCountMetrics,
2024-11-15 15:55:38 +00:00
)
}