Skip to content

Commit

Permalink
fix: start price subscription for new position
Browse files Browse the repository at this point in the history
  • Loading branch information
mpisanko committed Aug 29, 2024
1 parent a029820 commit 12c635c
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ 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;
});


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?.();
Expand All @@ -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 = [];
Expand Down

0 comments on commit 12c635c

Please sign in to comment.