This commit is contained in:
2026-02-25 11:04:03 +08:00
parent 24fe2a97cf
commit 13cb1ed479
8 changed files with 118 additions and 92 deletions

View File

@@ -19,13 +19,44 @@ func main() {
impl.NewImpl()
fmt.Println("")
run()
ClosedTable()
UnclosedTable()
fmt.Println("")
}
func run() {
func ClosedTable() {
tw := table.NewWriter()
tw.SetStyle(table.StyleLight)
tw.SetTitle("已清仓列表")
tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "CloseDate", "ClosePrice", "PNL/Per", "PNLRate(%)"})
var data []models.MockPosition
impl.DBService.Where("status=?", 1).Find(&data)
var tPNL, tPNLR, cost, sell float64
for _, item := range data {
var stock models.StockBasic
impl.DBService.Where("ts_code=?", item.Code).First(&stock)
pnl := utils.FloatRound(item.ClosePrice-item.OpenPrice, 2)
pnlRate := utils.FloatRound(pnl/item.OpenPrice*100, 2)
tPNL = tPNL + pnl
cost = cost + item.OpenPrice
sell = sell + item.ClosePrice
tw.AppendRow(table.Row{item.ID, item.Code, stock.Name, item.CreatedAt.Format("2006-01-02"), item.OpenPrice, item.UpdatedAt.Format("2006-01-02"), item.ClosePrice, pnl, pnlRate})
}
tPNLR = utils.FloatRound(((sell-cost)/cost)*100, 2)
tw.AppendFooter(table.Row{"", "", "", "TOTAL", utils.FloatRound(cost, 2), utils.FloatRound(sell, 2), utils.FloatRound(tPNL, 2), tPNLR})
fmt.Println(tw.Render())
}
func UnclosedTable() {
tw := table.NewWriter()
tw.SetStyle(table.StyleLight)
tw.SetTitle("未平仓列表")
tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "TodayPrice", "PNL/Per", "PNLRate(%)"})
var data []models.MockPosition
impl.DBService.Where("status=?", 0).Find(&data)