mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
xmaker: integrate bid/ask margin metrics
This commit is contained in:
parent
b3c8739983
commit
3d4ccd1344
|
@ -26,6 +26,18 @@ var makerBestAskPriceMetrics = prometheus.NewGaugeVec(
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||||
|
|
||||||
|
var bidMarginMetrics = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "xmaker_bid_margin",
|
||||||
|
Help: "the current bid margin (dynamic)",
|
||||||
|
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||||
|
|
||||||
|
var askMarginMetrics = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "xmaker_ask_margin",
|
||||||
|
Help: "the current ask margin (dynamic)",
|
||||||
|
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||||
|
|
||||||
var configNumOfLayersMetrics = prometheus.NewGaugeVec(
|
var configNumOfLayersMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "xmaker_config_num_of_layers",
|
Name: "xmaker_config_num_of_layers",
|
||||||
|
@ -56,6 +68,8 @@ func init() {
|
||||||
openOrderAskExposureInUsdMetrics,
|
openOrderAskExposureInUsdMetrics,
|
||||||
makerBestBidPriceMetrics,
|
makerBestBidPriceMetrics,
|
||||||
makerBestAskPriceMetrics,
|
makerBestAskPriceMetrics,
|
||||||
|
bidMarginMetrics,
|
||||||
|
askMarginMetrics,
|
||||||
configNumOfLayersMetrics,
|
configNumOfLayersMetrics,
|
||||||
configMaxExposureMetrics,
|
configMaxExposureMetrics,
|
||||||
configBidMarginMetrics,
|
configBidMarginMetrics,
|
||||||
|
|
|
@ -401,9 +401,12 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
|
|
||||||
bidExposureInUsd := fixedpoint.Zero
|
bidExposureInUsd := fixedpoint.Zero
|
||||||
askExposureInUsd := fixedpoint.Zero
|
askExposureInUsd := fixedpoint.Zero
|
||||||
|
|
||||||
bidPrice := bestBidPrice
|
bidPrice := bestBidPrice
|
||||||
askPrice := bestAskPrice
|
askPrice := bestAskPrice
|
||||||
|
|
||||||
|
bidMarginMetrics.With(labels).Set(bidMargin.Float64())
|
||||||
|
askMarginMetrics.With(labels).Set(askMargin.Float64())
|
||||||
|
|
||||||
for i := 0; i < s.NumLayers; i++ {
|
for i := 0; i < s.NumLayers; i++ {
|
||||||
// for maker bid orders
|
// for maker bid orders
|
||||||
if !disableMakerBid {
|
if !disableMakerBid {
|
||||||
|
@ -430,13 +433,13 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(bidMargin))
|
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(bidMargin))
|
||||||
if i > 0 && pips.Sign() > 0 {
|
if i == 0 {
|
||||||
|
makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64())
|
||||||
|
} else if i > 0 && pips.Sign() > 0 {
|
||||||
bidPrice = bidPrice.Sub(pips.Mul(fixedpoint.NewFromInt(int64(i)).
|
bidPrice = bidPrice.Sub(pips.Mul(fixedpoint.NewFromInt(int64(i)).
|
||||||
Mul(s.makerMarket.TickSize)))
|
Mul(s.makerMarket.TickSize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64())
|
|
||||||
|
|
||||||
if makerQuota.QuoteAsset.Lock(bidQuantity.Mul(bidPrice)) && hedgeQuota.BaseAsset.Lock(bidQuantity) {
|
if makerQuota.QuoteAsset.Lock(bidQuantity.Mul(bidPrice)) && hedgeQuota.BaseAsset.Lock(bidQuantity) {
|
||||||
// if we bought, then we need to sell the base from the hedge session
|
// if we bought, then we need to sell the base from the hedge session
|
||||||
submitOrders = append(submitOrders, types.SubmitOrder{
|
submitOrders = append(submitOrders, types.SubmitOrder{
|
||||||
|
@ -487,12 +490,12 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
askPrice = askPrice.Mul(fixedpoint.One.Add(askMargin))
|
askPrice = askPrice.Mul(fixedpoint.One.Add(askMargin))
|
||||||
if i > 0 && pips.Sign() > 0 {
|
if i == 0 {
|
||||||
|
makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64())
|
||||||
|
} else if i > 0 && pips.Sign() > 0 {
|
||||||
askPrice = askPrice.Add(pips.Mul(fixedpoint.NewFromInt(int64(i)).Mul(s.makerMarket.TickSize)))
|
askPrice = askPrice.Add(pips.Mul(fixedpoint.NewFromInt(int64(i)).Mul(s.makerMarket.TickSize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64())
|
|
||||||
|
|
||||||
if makerQuota.BaseAsset.Lock(askQuantity) && hedgeQuota.QuoteAsset.Lock(askQuantity.Mul(askPrice)) {
|
if makerQuota.BaseAsset.Lock(askQuantity) && hedgeQuota.QuoteAsset.Lock(askQuantity.Mul(askPrice)) {
|
||||||
|
|
||||||
// if we bought, then we need to sell the base from the hedge session
|
// if we bought, then we need to sell the base from the hedge session
|
||||||
|
|
Loading…
Reference in New Issue
Block a user