mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #1824 from c9s/c9s/xdepthmaker-maker-metrics
FEATURE: [xdepthmaker] add maker metrics
This commit is contained in:
commit
b8f8e09a51
88
pkg/metrics/maker.go
Normal file
88
pkg/metrics/maker.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
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"})
|
||||
|
||||
var MakerBestBidPriceMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "bbgo_maker_best_bid_price",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
|
||||
var MakerBestAskPriceMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "bbgo_maker_best_ask_price",
|
||||
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))
|
||||
}
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(
|
||||
OpenOrderAskExposureInUsdMetrics,
|
||||
OpenOrderBidExposureInUsdMetrics,
|
||||
MakerBestAskPriceMetrics,
|
||||
MakerBestBidPriceMetrics,
|
||||
OpenOrderAskOrderCountMetrics,
|
||||
OpenOrderBidOrderCountMetrics,
|
||||
)
|
||||
}
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/core"
|
||||
"github.com/c9s/bbgo/pkg/exchange/retry"
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/metrics"
|
||||
"github.com/c9s/bbgo/pkg/pricesolver"
|
||||
"github.com/c9s/bbgo/pkg/sigchan"
|
||||
"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))
|
||||
|
||||
metrics.UpdateOpenOrderMetrics(ID, s.InstanceID(), s.MakerExchange, s.Symbol, submitOrders)
|
||||
|
||||
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
||||
if err != nil {
|
||||
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
||||
|
|
Loading…
Reference in New Issue
Block a user