Loading src/chat/chat.service.ts +12 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ type PortfolioSummary = { quantity: number; averagePrice: number; currentPrice: number | null; buyFees: number; sellFees: number; profitOrLossIfSold: number; }>; }; Loading Loading @@ -155,15 +158,24 @@ export class ChatService { quantity: 0, averagePrice: 0, currentPrice, buyFees: 0, sellFees: 0, profitOrLossIfSold: 0, }; } const existing = summary.position[ticker]; const totalCost = existing.averagePrice * existing.quantity + unitPrice * quantity; const totalQty = existing.quantity + quantity; const buyFees = existing.buyFees + this.toNumber(position.buyFees) + this.toNumber(position.buyTaxes); const sellFees = currentPrice !== null ? totalQty * currentPrice * 0.0065 : 0; // estimated sell fees and taxes const profitOrLossIfSold = currentPrice !== null ? (currentPrice - existing.averagePrice) * totalQty - buyFees - sellFees : 0; existing.quantity = totalQty; existing.averagePrice = totalQty > 0 ? totalCost / totalQty : 0; existing.currentPrice = currentPrice; existing.buyFees = buyFees; existing.sellFees = sellFees; existing.profitOrLossIfSold = profitOrLossIfSold; } return summary; Loading Loading
src/chat/chat.service.ts +12 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ type PortfolioSummary = { quantity: number; averagePrice: number; currentPrice: number | null; buyFees: number; sellFees: number; profitOrLossIfSold: number; }>; }; Loading Loading @@ -155,15 +158,24 @@ export class ChatService { quantity: 0, averagePrice: 0, currentPrice, buyFees: 0, sellFees: 0, profitOrLossIfSold: 0, }; } const existing = summary.position[ticker]; const totalCost = existing.averagePrice * existing.quantity + unitPrice * quantity; const totalQty = existing.quantity + quantity; const buyFees = existing.buyFees + this.toNumber(position.buyFees) + this.toNumber(position.buyTaxes); const sellFees = currentPrice !== null ? totalQty * currentPrice * 0.0065 : 0; // estimated sell fees and taxes const profitOrLossIfSold = currentPrice !== null ? (currentPrice - existing.averagePrice) * totalQty - buyFees - sellFees : 0; existing.quantity = totalQty; existing.averagePrice = totalQty > 0 ? totalCost / totalQty : 0; existing.currentPrice = currentPrice; existing.buyFees = buyFees; existing.sellFees = sellFees; existing.profitOrLossIfSold = profitOrLossIfSold; } return summary; Loading