public AnalyticsEngine() { _currentPositionUpdatesDto = new PositionUpdatesDto(); _updates = new BehaviorSubject <PositionUpdatesDto>(_currentPositionUpdatesDto); _eventLoopScheduler.SchedulePeriodic(TimeSpan.FromSeconds(10), PublishPositionReport); }
public AnalyticsEngine() { _currentPositionUpdatesDto = new PositionUpdatesDto(); _updates = new BehaviorSubject<PositionUpdatesDto>(_currentPositionUpdatesDto); _eventLoopScheduler.SchedulePeriodic(TimeSpan.FromSeconds(10), PublishPositionReport); }
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) { } }
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(); 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; } // todo need to do something different here, I think. _analyticsPublisher.Publish(pud).Wait(TimeSpan.FromSeconds(10)); }
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); }