This commit is contained in:
yanweidong
2026-02-11 01:34:34 +08:00
parent f35e7d5e9a
commit ce79a75497

View File

@@ -26,9 +26,10 @@ func main() {
func run() {
tw := table.NewWriter()
tw.SetStyle(table.StyleLight)
tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "TodayPrice", "PNL", "PNLRate"})
tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "TodayPrice", "PNL/Per", "PNLRate(%)"})
var data []models.MockPosition
impl.DBService.Where("status=?", 0).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)
@@ -36,11 +37,20 @@ func run() {
var daily models.StockDaily
impl.DBService.Model(&models.StockDaily{}).Where("ts_code=?", item.Code).Order("id desc").Limit(1).First(&daily)
pnl := utils.FloatRound(daily.High-item.OpenPrice, 2)
high := utils.FloatRound(daily.High*0.997, 2)
pnl := utils.FloatRound(high-item.OpenPrice, 2)
pnlRate := utils.FloatRound(pnl/item.OpenPrice*100, 2)
tw.AppendRow(table.Row{item.ID, item.Code, stock.Name, item.CreatedAt.Format("2006-01-02"), item.OpenPrice, daily.High, pnl, pnlRate})
tPNL = tPNL + pnl
cost = cost + item.OpenPrice
sell = sell + high
tw.AppendRow(table.Row{item.ID, item.Code, stock.Name, item.CreatedAt.Format("2006-01-02"), item.OpenPrice, high, 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())
}