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"
|
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(
|
var openOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_open_order_bid_exposure_in_usd",
|
Name: "liqmaker_open_order_bid_exposure_in_usd",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var openOrderAskExposureInUsdMetrics = prometheus.NewGaugeVec(
|
var openOrderAskExposureInUsdMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_open_order_ask_exposure_in_usd",
|
Name: "liqmaker_open_order_ask_exposure_in_usd",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var askLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
var askLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_ask_liquidity_amount",
|
Name: "liqmaker_ask_liquidity_amount",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var bidLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
var bidLiquidityAmountMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_bid_liquidity_amount",
|
Name: "liqmaker_bid_liquidity_amount",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var askLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
var askLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_ask_liquidity_price_high",
|
Name: "liqmaker_ask_liquidity_price_high",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var askLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
var askLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_ask_liquidity_price_low",
|
Name: "liqmaker_ask_liquidity_price_low",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var bidLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
var bidLiquidityPriceHighMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_bid_liquidity_price_high",
|
Name: "liqmaker_bid_liquidity_price_high",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var bidLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
var bidLiquidityPriceLowMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_bid_liquidity_price_low",
|
Name: "liqmaker_bid_liquidity_price_low",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var midPriceMetrics = prometheus.NewGaugeVec(
|
var midPriceMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_mid_price",
|
Name: "liqmaker_mid_price",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
var orderPlacementStatusMetrics = prometheus.NewGaugeVec(
|
var orderPlacementStatusMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_order_placement_status",
|
Name: "liqmaker_order_placement_status",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol", "side"})
|
}, generalLabels)
|
||||||
|
|
||||||
var liquidityPriceRangeMetrics = prometheus.NewGaugeVec(
|
var liquidityPriceRangeMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "liqmaker_liquidity_price_range",
|
Name: "liqmaker_liquidity_price_range",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, generalLabels)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
|
@ -86,5 +106,10 @@ func init() {
|
||||||
bidLiquidityPriceLowMetrics,
|
bidLiquidityPriceLowMetrics,
|
||||||
|
|
||||||
orderPlacementStatusMetrics,
|
orderPlacementStatusMetrics,
|
||||||
|
|
||||||
|
tickerBidMetrics,
|
||||||
|
tickerAskMetrics,
|
||||||
|
|
||||||
|
spreadMetrics,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,24 @@ func (s *Strategy) Initialize() error {
|
||||||
return nil
|
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) {
|
func (s *Strategy) liquidityWorker(ctx context.Context, interval types.Interval) {
|
||||||
|
metricsTicker := time.NewTicker(5 * time.Second)
|
||||||
|
defer metricsTicker.Stop()
|
||||||
|
|
||||||
ticker := time.NewTicker(interval.Duration())
|
ticker := time.NewTicker(interval.Duration())
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
@ -150,6 +167,9 @@ func (s *Strategy) liquidityWorker(ctx context.Context, interval types.Interval)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case <-metricsTicker.C:
|
||||||
|
s.updateMarketMetrics(ctx)
|
||||||
|
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
s.placeLiquidityOrders(ctx)
|
s.placeLiquidityOrders(ctx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user