diff --git a/pkg/types/position.go b/pkg/types/position.go index 60b938eab..10ff98e7e 100644 --- a/pkg/types/position.go +++ b/pkg/types/position.go @@ -54,6 +54,10 @@ type Position struct { // TotalFee stores the fee currency -> total fee quantity TotalFee map[string]fixedpoint.Value `json:"totalFee" db:"-"` + // FeeAverageCosts stores the fee currency -> average cost of the fee + // e.g. BNB -> 341.0 + FeeAverageCosts map[string]fixedpoint.Value `json:"feeAverageCosts" db:"-"` + OpenedAt time.Time `json:"openedAt,omitempty" db:"-"` ChangedAt time.Time `json:"changedAt,omitempty" db:"changed_at"` @@ -307,7 +311,10 @@ func NewPositionFromMarket(market Market) *Position { BaseCurrency: market.BaseCurrency, QuoteCurrency: market.QuoteCurrency, Market: market, - TotalFee: make(map[string]fixedpoint.Value), + + FeeAverageCosts: make(map[string]fixedpoint.Value), + TotalFee: make(map[string]fixedpoint.Value), + ExchangeFeeRates: make(map[ExchangeName]ExchangeFee), } } @@ -316,7 +323,10 @@ func NewPosition(symbol, base, quote string) *Position { Symbol: symbol, BaseCurrency: base, QuoteCurrency: quote, - TotalFee: make(map[string]fixedpoint.Value), + + TotalFee: make(map[string]fixedpoint.Value), + FeeAverageCosts: make(map[string]fixedpoint.Value), + ExchangeFeeRates: make(map[ExchangeName]ExchangeFee), } } @@ -346,6 +356,10 @@ func (p *Position) SetExchangeFeeRate(ex ExchangeName, exchangeFee ExchangeFee) p.ExchangeFeeRates[ex] = exchangeFee } +func (p *Position) SetFeeAverageCost(currency string, cost fixedpoint.Value) { + p.FeeAverageCosts[currency] = cost +} + func (p *Position) IsShort() bool { return p.Base.Sign() < 0 } @@ -640,6 +654,7 @@ func (p *Position) AddTrade(td Trade) (profit fixedpoint.Value, netProfit fixedp } func (p *Position) updateMetrics() { + // update the position metrics only if the position defines the strategy ID if p.StrategyInstanceID == "" || p.Strategy == "" { return } diff --git a/pkg/types/position_metrics.go b/pkg/types/position_metrics.go index 7384ae0fe..e3523f895 100644 --- a/pkg/types/position_metrics.go +++ b/pkg/types/position_metrics.go @@ -16,8 +16,8 @@ var positionBaseQuantityMetrics = prometheus.NewGaugeVec( var positionQuoteQuantityMetrics = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Name: "bbgo_position_base_qty", - Help: "bbgo position base quantity metrics", + Name: "bbgo_position_quote_qty", + Help: "bbgo position quote quantity metrics", }, []string{"strategy_id", "strategy_type", "symbol"}) func init() {