Skip to content

Commit 2a8b22b

Browse files
committed
📝 feat(position): fee conversion from quote to USD, add callback function
1 parent 897dcc9 commit 2a8b22b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

‎pkg/types/position.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ func (p *Position) AddTrades(trades []Trade) (fixedpoint.Value, fixedpoint.Value
574574
}
575575

576576
func (p *Position) calculateFeeInQuote(td Trade) fixedpoint.Value {
577+
// assume the fee is not charged either in base currency or quote currency
577578
var quoteQuantity = td.QuoteQuantity
578579

579580
if cost, ok := p.FeeAverageCosts[td.FeeCurrency]; ok {
@@ -758,3 +759,11 @@ func (p *Position) updateMetrics() {
758759
positionBaseQuantityMetrics.With(labels).Set(p.Base.Float64())
759760
positionQuoteQuantityMetrics.With(labels).Set(p.Quote.Float64())
760761
}
762+
763+
func (p *Position) UpdateQuteUsdPrice(kline KLine) {
764+
p.Lock()
765+
defer p.Unlock()
766+
767+
cost := fixedpoint.One.Div(kline.Close)
768+
p.FeeAverageCosts["USD"] = cost
769+
}

0 commit comments

Comments
 (0)