mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 15:55:14 +00:00
liqmaker: add market metrics updater
This commit is contained in:
parent
92a934b6f2
commit
31aea5753e
|
@ -2,71 +2,91 @@ package liquiditymaker
|
|||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
var generalLabels = []string{"strategy_type", "strategy_id", "exchange", "symbol"}
|
||||
|
||||
var spreadMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_spread",
|
||||
Help: "",
|
||||
}, generalLabels)
|
||||
|
||||
var tickerBidMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_ticker_bid",
|
||||
Help: "",
|
||||
}, generalLabels)
|
||||
|
||||
var tickerAskMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_ticker_ask",
|
||||
Help: "",
|
||||
}, generalLabels)
|
||||
|
||||
var openOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_open_order_bid_exposure_in_usd",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var openOrderAskExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_open_order_ask_exposure_in_usd",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var askLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_ask_liquidity_amount",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var bidLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_bid_liquidity_amount",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var askLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_ask_liquidity_price_high",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var askLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_ask_liquidity_price_low",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var bidLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_bid_liquidity_price_high",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var bidLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_bid_liquidity_price_low",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var midPriceMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_mid_price",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
var orderPlacementStatusMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_order_placement_status",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol", "side"})
|
||||
}, generalLabels)
|
||||
|
||||
var liquidityPriceRangeMetrics = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "liqmaker_liquidity_price_range",
|
||||
Help: "",
|
||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||
}, generalLabels)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(
|
||||
|
@ -86,5 +106,10 @@ func init() {
|
|||
bidLiquidityPriceLowMetrics,
|
||||
|
||||
orderPlacementStatusMetrics,
|
||||
|
||||
tickerBidMetrics,
|
||||
tickerAskMetrics,
|
||||
|
||||
spreadMetrics,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -140,7 +140,24 @@ func (s *Strategy) Initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) updateMarketMetrics(ctx context.Context) error {
|
||||
ticker, err := s.Session.Exchange.QueryTicker(ctx, s.Symbol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
currentSpread := ticker.Sell.Sub(ticker.Buy)
|
||||
|
||||
tickerBidMetrics.With(s.metricsLabels).Set(ticker.Buy.Float64())
|
||||
tickerAskMetrics.With(s.metricsLabels).Set(ticker.Sell.Float64())
|
||||
spreadMetrics.With(s.metricsLabels).Set(currentSpread.Float64())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) liquidityWorker(ctx context.Context, interval types.Interval) {
|
||||
metricsTicker := time.NewTicker(5 * time.Second)
|
||||
defer metricsTicker.Stop()
|
||||
|
||||
ticker := time.NewTicker(interval.Duration())
|
||||
defer ticker.Stop()
|
||||
|
||||
|
@ -150,6 +167,9 @@ func (s *Strategy) liquidityWorker(ctx context.Context, interval types.Interval)
|
|||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case <-metricsTicker.C:
|
||||
s.updateMarketMetrics(ctx)
|
||||
|
||||
case <-ticker.C:
|
||||
s.placeLiquidityOrders(ctx)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user