mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
metrics: add maker metrics for xdepthmaker
This commit is contained in:
parent
60c7dfea29
commit
5c6a00cc87
|
@ -1,6 +1,11 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import (
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
var OpenOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(
|
var OpenOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
|
@ -14,23 +19,70 @@ var OpenOrderAskExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []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"})
|
||||||
|
|
||||||
var MakerBestBidPriceMetrics = prometheus.NewGaugeVec(
|
var MakerBestBidPriceMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "bbgo_maker_maker_best_bid_price",
|
Name: "bbgo_maker_best_bid_price",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||||
|
|
||||||
var MakerBestAskPriceMetrics = prometheus.NewGaugeVec(
|
var MakerBestAskPriceMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "bbgo_maker_maker_best_ask_price",
|
Name: "bbgo_maker_best_ask_price",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []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))
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
OpenOrderAskExposureInUsdMetrics,
|
OpenOrderAskExposureInUsdMetrics,
|
||||||
OpenOrderBidExposureInUsdMetrics,
|
OpenOrderBidExposureInUsdMetrics,
|
||||||
MakerBestAskPriceMetrics,
|
MakerBestAskPriceMetrics,
|
||||||
MakerBestBidPriceMetrics,
|
MakerBestBidPriceMetrics,
|
||||||
|
OpenOrderAskOrderCountMetrics,
|
||||||
|
OpenOrderBidOrderCountMetrics,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/core"
|
"github.com/c9s/bbgo/pkg/core"
|
||||||
"github.com/c9s/bbgo/pkg/exchange/retry"
|
"github.com/c9s/bbgo/pkg/exchange/retry"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
"github.com/c9s/bbgo/pkg/metrics"
|
||||||
"github.com/c9s/bbgo/pkg/pricesolver"
|
"github.com/c9s/bbgo/pkg/pricesolver"
|
||||||
"github.com/c9s/bbgo/pkg/sigchan"
|
"github.com/c9s/bbgo/pkg/sigchan"
|
||||||
"github.com/c9s/bbgo/pkg/strategy/common"
|
"github.com/c9s/bbgo/pkg/strategy/common"
|
||||||
|
@ -1193,6 +1194,8 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {
|
||||||
|
|
||||||
s.logger.Infof("%d orders are generated, placing...", len(submitOrders))
|
s.logger.Infof("%d orders are generated, placing...", len(submitOrders))
|
||||||
|
|
||||||
|
metrics.UpdateOpenOrderMetrics(ID, s.InstanceID(), s.MakerExchange, s.Symbol, submitOrders)
|
||||||
|
|
||||||
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user