Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/strategy/common/profit_fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (f *ProfitFixer) Fix(
if err != nil {
return err
}
if len(allTrades) == 0 {
log.Warnf("[%s] no trades found between %s and %s, skip profit fixing", symbol, since.String(), until.String())
return nil
}

return f.FixFromTrades(allTrades, stats, position)
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/types/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ func (p *Position) SlackAttachment() slack.Attachment {
footer := templateutil.Render("Last updated time: {{ . }}",
time.Now().Format(time.RFC822))

if !p.OpenedAt.IsZero() {
footer += " opened at: " + p.OpenedAt.String()
}

if len(p.Strategy) > 0 {
footer += " strategy: " + p.Strategy
}
Expand All @@ -501,12 +505,13 @@ func (p *Position) SlackAttachment() slack.Attachment {

func (p *Position) PlainText() (msg string) {
posType := p.Type()
msg = fmt.Sprintf("%s Position %s: average cost = %v, base = %v, quote = %v",
msg = fmt.Sprintf("%s Position %s: average cost = %v, base = %v, quote = %v, opened at %s",
posType,
p.Symbol,
p.AverageCost,
p.Base,
p.Quote,
p.OpenedAt,
)

if p.TotalFee != nil {
Expand All @@ -519,11 +524,12 @@ func (p *Position) PlainText() (msg string) {
}

func (p *Position) String() string {
return fmt.Sprintf("POSITION %s: average cost = %v, base = %v, quote = %v",
return fmt.Sprintf("POSITION %s: average cost = %v, base = %v, quote = %v, opened at %s",
p.Symbol,
p.AverageCost,
p.Base,
p.Quote,
p.OpenedAt,
)
}

Expand Down Expand Up @@ -601,6 +607,10 @@ func (p *Position) AddTrade(td Trade) (profit fixedpoint.Value, netProfit fixedp
quoteQuantity := td.QuoteQuantity
fee := td.Fee

if quantity.IsZero() {
return fixedpoint.Zero, fixedpoint.Zero, false
}

// calculated fee in quote (some exchange accounts may enable platform currency fee discount, like BNB)
// convert platform fee token into USD values
var feeInQuote = fixedpoint.Zero
Expand Down
Loading