private void PublishPositionReport() { var pud = new PositionUpdatesDto { CurrentPositions = _ccyPairTracker .Values .Where(ccp => ccp.TradeCount > 0) .Select(ccp => new CurrencyPairPositionDto { Symbol = ccp.CurrencyPair, BasePnl = ccp.CurrentPosition.BasePnl, BaseTradedAmount = ccp.CurrentPosition.BaseTradedAmount, CounterTradedAmount = ccp.CurrentPosition.CounterTradedAmount, }) .ToArray() }; var usdPnl = _ccyPairTracker.Values .Where(ccp => ccp.TradeCount > 0) .Sum(ccp => ccp.CurrentPosition.UsdPnl); var now = DateTimeOffset.UtcNow; var window = now.AddMinutes(-15); pud.History = _currentPositionUpdatesDto.History .Where(hpu => hpu.Timestamp >= window) .Concat(new[] { new HistoricPositionDto { Timestamp = now, UsdPnl = usdPnl } }) .ToArray(); lock (_currentPositionLock) { _currentPositionUpdatesDto = pud; } Log.Information(pud.ToString()); _updates.OnNext(pud); }
private void PublishPositionReport() { var pud = new PositionUpdatesDto { CurrentPositions = _ccyPairTracker .Values .Where(ccp => ccp.TradeCount > 0) .Select(ccp => new CurrencyPairPositionDto { Symbol = ccp.CurrencyPair, BasePnl = ccp.CurrentPosition.BasePnl, BaseTradedAmount = ccp.CurrentPosition.BaseTradedAmount }) .ToArray() }; var usdPnl = _ccyPairTracker.Values .Where(ccp => ccp.TradeCount > 0) .Sum(ccp => ccp.CurrentPosition.UsdPnl); var now = DateTimeOffset.UtcNow; var window = now.AddMinutes(-15); pud.History = _currentPositionUpdatesDto.History .Where(hpu => hpu.Timestamp >= window) .Concat(new[] {new HistoricPositionDto {Timestamp = now, UsdPnl = usdPnl}}) .ToArray(); lock (_currentPositionLock) { _currentPositionUpdatesDto = pud; } Log.Information(pud.ToString()); _updates.OnNext(pud); }