mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
types: add fee cost settter to the position
This commit is contained in:
parent
9136877207
commit
e2d68f2a86
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user