mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #1207 from c9s/bhwu/grid2/delete-order-price-metrics
This commit is contained in:
commit
6741f8b22c
|
@ -10,7 +10,6 @@ var (
|
||||||
metricsGridNumOfOrdersWithCorrectPrice *prometheus.GaugeVec
|
metricsGridNumOfOrdersWithCorrectPrice *prometheus.GaugeVec
|
||||||
metricsGridNumOfMissingOrders *prometheus.GaugeVec
|
metricsGridNumOfMissingOrders *prometheus.GaugeVec
|
||||||
metricsGridNumOfMissingOrdersWithCorrectPrice *prometheus.GaugeVec
|
metricsGridNumOfMissingOrdersWithCorrectPrice *prometheus.GaugeVec
|
||||||
metricsGridOrderPrices *prometheus.GaugeVec
|
|
||||||
metricsGridProfit *prometheus.GaugeVec
|
metricsGridProfit *prometheus.GaugeVec
|
||||||
|
|
||||||
metricsGridUpperPrice *prometheus.GaugeVec
|
metricsGridUpperPrice *prometheus.GaugeVec
|
||||||
|
@ -102,19 +101,6 @@ func initMetrics(extendedLabels []string) {
|
||||||
}, extendedLabels...),
|
}, extendedLabels...),
|
||||||
)
|
)
|
||||||
|
|
||||||
metricsGridOrderPrices = prometheus.NewGaugeVec(
|
|
||||||
prometheus.GaugeOpts{
|
|
||||||
Name: "bbgo_grid2_order_prices",
|
|
||||||
Help: "order prices",
|
|
||||||
},
|
|
||||||
append([]string{
|
|
||||||
"exchange", // exchange name
|
|
||||||
"symbol", // symbol of the market
|
|
||||||
"ith",
|
|
||||||
"side",
|
|
||||||
}, extendedLabels...),
|
|
||||||
)
|
|
||||||
|
|
||||||
metricsGridProfit = prometheus.NewGaugeVec(
|
metricsGridProfit = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "bbgo_grid2_profit",
|
Name: "bbgo_grid2_profit",
|
||||||
|
@ -202,7 +188,6 @@ func registerMetrics() {
|
||||||
metricsGridNumOfMissingOrders,
|
metricsGridNumOfMissingOrders,
|
||||||
metricsGridNumOfMissingOrdersWithCorrectPrice,
|
metricsGridNumOfMissingOrdersWithCorrectPrice,
|
||||||
metricsGridProfit,
|
metricsGridProfit,
|
||||||
metricsGridOrderPrices,
|
|
||||||
metricsGridLowerPrice,
|
metricsGridLowerPrice,
|
||||||
metricsGridUpperPrice,
|
metricsGridUpperPrice,
|
||||||
metricsGridQuoteInvestment,
|
metricsGridQuoteInvestment,
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.ExchangeSession) error {
|
func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.ExchangeSession) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService)
|
historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService)
|
||||||
|
|
|
@ -894,7 +894,6 @@ func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.Exch
|
||||||
bbgo.Sync(ctx, s)
|
bbgo.Sync(ctx, s)
|
||||||
|
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1170,7 +1169,6 @@ func (s *Strategy) openGrid(ctx context.Context, session *bbgo.ExchangeSession)
|
||||||
s.logger.Infof("ALL GRID ORDERS SUBMITTED")
|
s.logger.Infof("ALL GRID ORDERS SUBMITTED")
|
||||||
|
|
||||||
s.updateGridNumOfOrdersMetrics(grid)
|
s.updateGridNumOfOrdersMetrics(grid)
|
||||||
s.updateOpenOrderPricesMetrics(createdOrders)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1219,41 +1217,6 @@ func (s *Strategy) updateGridNumOfOrdersMetrics(grid *Grid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) updateOpenOrderPricesMetrics(orders []types.Order) {
|
|
||||||
orders = sortOrdersByPriceAscending(orders)
|
|
||||||
num := len(orders)
|
|
||||||
s.deleteOpenOrderPricesMetrics()
|
|
||||||
for idx, order := range orders {
|
|
||||||
labels := s.newPrometheusLabels()
|
|
||||||
labels["side"] = order.Side.String()
|
|
||||||
labels["ith"] = strconv.Itoa(num - idx)
|
|
||||||
metricsGridOrderPrices.With(labels).Set(order.Price.Float64())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Strategy) deleteOpenOrderPricesMetrics() {
|
|
||||||
for i := 1; i <= int(s.GridNum); i++ {
|
|
||||||
ithStr := strconv.Itoa(i)
|
|
||||||
labels := s.newPrometheusLabels()
|
|
||||||
labels["side"] = "BUY"
|
|
||||||
labels["ith"] = ithStr
|
|
||||||
metricsGridOrderPrices.Delete(labels)
|
|
||||||
labels = s.newPrometheusLabels()
|
|
||||||
labels["side"] = "SELL"
|
|
||||||
labels["ith"] = ithStr
|
|
||||||
metricsGridOrderPrices.Delete(labels)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortOrdersByPriceAscending(orders []types.Order) []types.Order {
|
|
||||||
sort.Slice(orders, func(i, j int) bool {
|
|
||||||
a := orders[i]
|
|
||||||
b := orders[j]
|
|
||||||
return a.Price.Compare(b.Price) < 0
|
|
||||||
})
|
|
||||||
return orders
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Strategy) debugGridOrders(submitOrders []types.SubmitOrder, lastPrice fixedpoint.Value) {
|
func (s *Strategy) debugGridOrders(submitOrders []types.SubmitOrder, lastPrice fixedpoint.Value) {
|
||||||
if !s.Debug {
|
if !s.Debug {
|
||||||
return
|
return
|
||||||
|
@ -1538,7 +1501,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
||||||
s.setGrid(grid)
|
s.setGrid(grid)
|
||||||
s.EmitGridReady()
|
s.EmitGridReady()
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
s.logger.Infof("GRID RECOVER: found missing prices: %v", missingPrices)
|
s.logger.Infof("GRID RECOVER: found missing prices: %v", missingPrices)
|
||||||
|
@ -1585,7 +1547,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
||||||
s.setGrid(grid)
|
s.setGrid(grid)
|
||||||
s.EmitGridReady()
|
s.EmitGridReady()
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1612,7 +1573,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
||||||
s.setGrid(grid)
|
s.setGrid(grid)
|
||||||
s.EmitGridReady()
|
s.EmitGridReady()
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
|
|
||||||
for i := range filledOrders {
|
for i := range filledOrders {
|
||||||
// avoid using the iterator
|
// avoid using the iterator
|
||||||
|
@ -1629,7 +1589,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
||||||
debugGrid(s.logger, grid, s.orderExecutor.ActiveMakerOrders())
|
debugGrid(s.logger, grid, s.orderExecutor.ActiveMakerOrders())
|
||||||
|
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user