private void PublishPositionReport() { var pud = new PositionUpdatesDto(); pud.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; } _analyticsPublisher.Publish(pud).Wait(TimeSpan.FromSeconds(10)); }
public async Task Publish(PositionUpdatesDto positionUpdatesDto) { var context = _contextHolder.AnalyticsHubClients; if (context == null) return; try { await context.Group(ServiceConstants.Server.AnalyticsGroup).OnNewAnalytics(positionUpdatesDto); } catch (Exception ex) { } }