fix: 买入后持仓数量和均价正确保存到数据库

This commit is contained in:
OpenClaw Agent 2026-03-16 09:08:47 +00:00
parent 71aa7211d6
commit 79105c339d

View File

@ -601,10 +601,13 @@ public class PortfolioService : IPortfolioService
var newTotalCost = (position.Shares * position.AvgPrice) + ((decimal)request.Amount * (decimal)request.Price); var newTotalCost = (position.Shares * position.AvgPrice) + ((decimal)request.Amount * (decimal)request.Price);
position.AvgPrice = newTotalCost / newTotalShares; position.AvgPrice = newTotalCost / newTotalShares;
position.Shares = newTotalShares; position.Shares = newTotalShares;
position.UpdatedAt = DateTime.Now;
_db.Updateable(position).ExecuteCommand();
} }
else if (request.Type == "sell") else if (request.Type == "sell")
{ {
position.Shares -= (decimal)request.Amount; position.Shares -= (decimal)request.Amount;
position.UpdatedAt = DateTime.Now;
if (position.Shares <= 0) if (position.Shares <= 0)
{ {
_db.Deleteable(position).ExecuteCommand(); _db.Deleteable(position).ExecuteCommand();