fix: 买入后持仓数量和均价正确保存到数据库
This commit is contained in:
parent
71aa7211d6
commit
79105c339d
@ -601,10 +601,13 @@ public class PortfolioService : IPortfolioService
|
||||
var newTotalCost = (position.Shares * position.AvgPrice) + ((decimal)request.Amount * (decimal)request.Price);
|
||||
position.AvgPrice = newTotalCost / newTotalShares;
|
||||
position.Shares = newTotalShares;
|
||||
position.UpdatedAt = DateTime.Now;
|
||||
_db.Updateable(position).ExecuteCommand();
|
||||
}
|
||||
else if (request.Type == "sell")
|
||||
{
|
||||
position.Shares -= (decimal)request.Amount;
|
||||
position.UpdatedAt = DateTime.Now;
|
||||
if (position.Shares <= 0)
|
||||
{
|
||||
_db.Deleteable(position).ExecuteCommand();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user