From 12c635c2623c3c9646aeb423595892d5e3308d9d Mon Sep 17 00:00:00 2001 From: Michal Pisanko Date: Thu, 29 Aug 2024 17:29:47 +0200 Subject: [PATCH] fix: start price subscription for new position --- .../position-blotter.component.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web-front-end/angular/main/app/trade/position-blotter/position-blotter.component.ts b/web-front-end/angular/main/app/trade/position-blotter/position-blotter.component.ts index a0cd755a..38177ddf 100644 --- a/web-front-end/angular/main/app/trade/position-blotter/position-blotter.component.ts +++ b/web-front-end/angular/main/app/trade/position-blotter/position-blotter.component.ts @@ -52,12 +52,10 @@ export class PositionBlotterComponent implements OnChanges, OnDestroy { this.isPending = true; this.tradeService.getPositions(accountId).subscribe((positions: Position[]) => { + console.log('Position blotter tradeService feed...', positions); this.positions = positions; this.processPendingPositions(); - const securities = this.positions.map((position: Position) => position.security); - console.log('Done processing positions for stocks', securities); - // signal what securities' market price updates should be sent. - this.tradeFeed.emit('/prices', securities); + this.subscribeToMarketValue(positions.map((p: Position) => p.security)); }, () => { this.isPending = false; }); @@ -65,8 +63,11 @@ export class PositionBlotterComponent implements OnChanges, OnDestroy { this.socketUnSubscribeFn?.(); this.socketUnSubscribeFn = this.tradeFeed.subscribe(`/accounts/${accountId}/positions`, (data: any) => { - console.log('Position blotter feed...', data); + console.log('Position blotter websocket feed...', data); this.updatePosition(data); + const securities = this.positions.map((p: Position) => p.security); + securities.push(data.security); + this.subscribeToMarketValue(securities); }); this.marketValueUnSubscribeFn?.(); @@ -77,6 +78,12 @@ export class PositionBlotterComponent implements OnChanges, OnDestroy { } } + // signal what securities' market price updates should be sent. + subscribeToMarketValue(securities: String[]) { + console.log('Will subscribe to prices for stocks', securities); + this.tradeFeed.emit('/prices', securities); + } + processPendingPositions() { this.pendingPosition.forEach((position) => this.update(position)); this.pendingPosition = [];