@@ -841,7 +841,7 @@ func (ct *Cointop) PrintHoldingsTable(options *TablePrintOptions) error {
841841 records := make ([][]string , len (holdings ))
842842 symbol := ct .CurrencySymbol ()
843843
844- headers := []string {"name" , "symbol" , "price" , "holdings" , "balance" , "24h%" , "%holdings" , "buy_price " , "buy_currency " , "pnl" , "pnl_percent" }
844+ headers := []string {"name" , "symbol" , "price" , "holdings" , "balance" , "24h%" , "%holdings" , "cost_price " , "cost " , "pnl" , "pnl_percent" }
845845 if len (filterCols ) > 0 {
846846 for _ , col := range filterCols {
847847 valid := false
@@ -938,6 +938,70 @@ func (ct *Cointop) PrintHoldingsTable(options *TablePrintOptions) error {
938938 if hideBalances {
939939 item [i ] = HiddenBalanceChars
940940 }
941+ case "cost_price" :
942+ if entry .BuyPrice > 0 && entry .BuyCurrency != "" {
943+ if humanReadable {
944+ item [i ] = fmt .Sprintf ("%s %s" , entry .BuyCurrency , ct .FormatPrice (entry .BuyPrice ))
945+ } else {
946+ item [i ] = fmt .Sprintf ("%s %s" , entry .BuyCurrency , strconv .FormatFloat (entry .BuyPrice , 'f' , - 1 , 64 ))
947+ }
948+ }
949+ if hideBalances {
950+ item [i ] = HiddenBalanceChars
951+ }
952+ case "cost" :
953+ if entry .BuyPrice > 0 && entry .BuyCurrency != "" {
954+ costPrice , err := ct .Convert (entry .BuyCurrency , ct .State .currencyConversion , entry .BuyPrice )
955+ if err == nil {
956+ cost := costPrice * entry .Holdings
957+ if humanReadable {
958+ item [i ] = fmt .Sprintf ("%s%s" , symbol , humanize .FixedMonetaryf (cost , 2 ))
959+ } else {
960+ item [i ] = strconv .FormatFloat (cost , 'f' , - 1 , 64 )
961+ }
962+ } else {
963+ item [i ] = "?" // error
964+ }
965+ }
966+ if hideBalances {
967+ item [i ] = HiddenBalanceChars
968+ }
969+ case "pnl" :
970+ if entry .BuyPrice > 0 && entry .BuyCurrency != "" {
971+ costPrice , err := ct .Convert (entry .BuyCurrency , ct .State .currencyConversion , entry .BuyPrice )
972+ if err == nil {
973+ profit := (entry .Price - costPrice ) * entry .Holdings
974+ if humanReadable {
975+ // TODO: if <0 "£-3.71" should be "-£3.71"?
976+ item [i ] = fmt .Sprintf ("%s%s" , symbol , humanize .FixedMonetaryf (profit , 2 ))
977+ } else {
978+ item [i ] = strconv .FormatFloat (profit , 'f' , - 1 , 64 )
979+ }
980+ } else {
981+ item [i ] = "?" // error
982+ }
983+ }
984+ if hideBalances {
985+ item [i ] = HiddenBalanceChars
986+ }
987+ case "pnl_percent" :
988+ if entry .BuyPrice > 0 && entry .BuyCurrency != "" {
989+ costPrice , err := ct .Convert (entry .BuyCurrency , ct .State .currencyConversion , entry .BuyPrice )
990+ if err == nil {
991+ profitPercent := 100 * (entry .Price / costPrice - 1 )
992+ if humanReadable {
993+ item [i ] = fmt .Sprintf ("%s%%" , humanize .Numericf (profitPercent , 2 ))
994+ } else {
995+ item [i ] = fmt .Sprintf ("%.2f" , profitPercent )
996+ }
997+
998+ } else {
999+ item [i ] = "?" // error
1000+ }
1001+ }
1002+ if hideBalances {
1003+ item [i ] = HiddenBalanceChars
1004+ }
9411005 }
9421006 }
9431007 records [i ] = item
0 commit comments