Skip to content

Commit

Permalink
Fix display of futures contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
gotasty committed May 12, 2018
1 parent 951fd78 commit 89cdc78
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tastypl.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,25 @@ func (p *portfolio) PrintPositions() {
net = fmt.Sprintf(" (adj. cost basis %s)",
open.value.Add(open.rpl).Neg().Div(open.quantity).StringFixed(2))
}
fmt.Printf(" %s %s shares @ %s%s\n", long, open.qtyOpen, open.avgPrice.Abs().StringFixed(2), net)
var kind string
var openPrice decimal.Decimal
if open.instrument == "Future" {
kind = "contract"
// Parse the open price from the description :-/
p := open.description[strings.IndexByte(open.description, '@')+2:]
var err error
openPrice, err = decimal.NewFromString(p)
if err != nil {
glog.Fatal("Can't parse opening price of futures transaction %s: %s", open, err)
}
} else {
kind = "share"
openPrice = open.avgPrice.Abs()
}
if open.qtyOpen.GreaterThan(decimal.New(1, 0)) {
kind += "s"
}
fmt.Printf(" %s %s %s @ %s%s\n", long, open.qtyOpen, kind, openPrice.StringFixed(2), net)
continue
}
var expFmt string
Expand Down

0 comments on commit 89cdc78

Please sign in to comment.