public Task GetPriceUpdates(IRequestContext context, IMessage message) { using (LogContext.PushProperty("InstanceId", InstanceId)) { Log.Debug("{host} Received GetPriceUpdates from [{user}] for replyTo {replyTo}", this, context.Username ?? "Unknown User", context.ReplyTo); var spotStreamRequest = JsonConvert.DeserializeObject <GetSpotStreamRequestDto>(Encoding.UTF8.GetString(message.Payload)); var replyTo = context.ReplyTo; var endpoint = _broker.GetPrivateEndPoint <SpotPriceDto>(replyTo, context.CorrelationId); var disposable = _service.GetPriceUpdates(context, spotStreamRequest) .TakeUntil(endpoint.TerminationSignal) .Finally(() => Log.Debug("Tidying up subscription from {replyTo}.", replyTo)) .Subscribe(endpoint); _cleanup.Add(disposable); return(Task.CompletedTask); } }
private async Task GetTradesStream(IRequestContext context, IMessage message) { Log.Debug("Received GetTradesStream from {username}", context.UserSession.Username ?? "<UNKNOWN USER>"); var replyTo = message.ReplyTo; var endPoint = await _broker.GetPrivateEndPoint <TradesDto>(replyTo); _subscription = _service.GetTradesStream() .Select(x => { if (x.IsStateOfTheWorld && x.Trades.Count > MaxSotwTrades) { return(new TradesDto(new List <TradeDto>(x.Trades.Skip(x.Trades.Count - MaxSotwTrades)), true, false)); } return(x); }) .Do(o => { Log.Debug( $"Sending trades update to {replyTo}. Count: {o.Trades.Count}. IsStateOfTheWorld: {o.IsStateOfTheWorld}. IsStale: {o.IsStale}"); }) .TakeUntil(endPoint.TerminationSignal) .Finally(() => Log.Debug("Tidying up subscription from {replyTo}.", replyTo)) .Subscribe(endPoint); }
private Task GetTradesStream(IRequestContext context, IMessage message) { using (LogContext.PushProperty("InstanceId", InstanceId)) { Log.Debug("Received GetTradesStream from {username}", context.Username ?? "<UNKNOWN USER>"); var replyTo = context.ReplyTo; var endPoint = _broker.GetPrivateEndPoint <TradesDto>(context.ReplyTo, context.CorrelationId); _subscription = _service.GetTradesStream() .Select(x => { if (x.IsStateOfTheWorld && x.Trades.Count > MaxSotwTrades) { return(new TradesDto(new List <TradeDto>(x.Trades.Skip(x.Trades.Count - MaxSotwTrades)), true, false)); } return(x); }) .Do(o => { Log.Debug( $"Sending trades update to {replyTo}. Count: {o.Trades.Count}. IsStateOfTheWorld: {o.IsStateOfTheWorld}. IsStale: {o.IsStale}"); }) .TakeUntil(endPoint.TerminationSignal) .Finally(() => Log.Debug("Tidying up subscription from {replyTo}.", replyTo)) .Subscribe(endPoint); return(Task.CompletedTask); } }
private Task GetCurrencyPairUpdatesStream(IRequestContext context, IMessage message) { using (LogContext.PushProperty("InstanceId", InstanceId)) { Log.Debug("Received GetCurrencyPairUpdatesStream from {}", context.Username ?? "<UNKNOWN USER>"); var payload = JsonConvert.DeserializeObject <NothingDto>(Encoding.UTF8.GetString(message.Payload)); var replyTo = context.ReplyTo; var endPoint = _broker.GetPrivateEndPoint <CurrencyPairUpdatesDto>(replyTo, context.CorrelationId); Interlocked.Increment(ref _clients); _subscription = _service.GetCurrencyPairUpdatesStream(context, payload) .Do( o => { Log.Debug( $"Sending currency pair update to {replyTo}. Count: {o.Updates.Count}. IsStateOfTheWorld: {o.IsStateOfTheWorld}. IsStale: {o.IsStale}"); }) .TakeUntil(endPoint.TerminationSignal).Finally(() => Interlocked.Decrement(ref _clients)) .Finally(() => { Log.Debug("Tidying up subscription from {replyTo}.", replyTo); }) .Subscribe(endPoint); return(Task.CompletedTask); } }
private async Task GetAnalyticsStream(IRequestContext context, IMessage message) { Log.Debug("Received GetAnalyticsStream from {username}", context.UserSession.Username); var endPoint = await _broker.GetPrivateEndPoint <PositionUpdatesDto>(message.ReplyTo); _subscriptions.Add(_service.GetAnalyticsStream() .TakeUntil(endPoint.TerminationSignal) .Subscribe(endPoint)); }
private Task GetAnalyticsStream(IRequestContext context, IMessage message) { using (LogContext.PushProperty("InstanceId", InstanceId)) { Log.Debug("Received GetAnalyticsStream from {username}", context.Username); var endPoint = _broker.GetPrivateEndPoint <PositionUpdatesDto>(context.ReplyTo, context.CorrelationId); _subscriptions.Add(_service.GetAnalyticsStream() .TakeUntil(endPoint.TerminationSignal) .Subscribe(endPoint)); return(Task.CompletedTask); } }
private async Task GetTradesStream(IRequestContext context, IMessage message) { Log.DebugFormat("Received GetTradesStream from {0}", context.UserSession.Username ?? "<UNKNOWN USER>"); var replyTo = message.ReplyTo; var endPoint = await _broker.GetPrivateEndPoint <TradesDto>(replyTo); _subscription = _service.GetTradesStream() .Do( o => { Log.Debug( $"Sending trades update to {replyTo}. Count: {o.Trades.Count}. IsStateOfTheWorld: {o.IsStateOfTheWorld}. IsStale: {o.IsStale}"); }) .TakeUntil(endPoint.TerminationSignal) .Finally(() => { Log.DebugFormat("Tidying up subscripting.", replyTo); }) .Subscribe(endPoint); }
public async Task GetPriceUpdates(IRequestContext context, IMessage message) { Log.DebugFormat("{1} Received GetPriceUpdates from [{0}]", context.UserSession.Username ?? "Unknown User", this); var spotStreamRequest = JsonConvert.DeserializeObject <GetSpotStreamRequestDto>(Encoding.UTF8.GetString(message.Payload)); var replyTo = message.ReplyTo; var endpoint = await _broker.GetPrivateEndPoint <SpotPriceDto>(replyTo); var disposable = _service.GetPriceUpdates(context, spotStreamRequest) .TakeUntil(endpoint.TerminationSignal) .Subscribe(endpoint); _cleanup.Add(disposable); }
private async Task GetCurrencyPairUpdatesStream(IRequestContext context, IMessage message) { Log.DebugFormat("Received GetCurrencyPairUpdatesStream from {0}", context.UserSession.Username ?? "<UNKNOWN USER>"); var payload = JsonConvert.DeserializeObject <NothingDto>(Encoding.UTF8.GetString(message.Payload)); var replyTo = message.ReplyTo; var endPoint = await _broker.GetPrivateEndPoint <CurrencyPairUpdatesDto>(replyTo); Interlocked.Increment(ref _clients); _subscription = _service.GetCurrencyPairUpdatesStream(context, payload) .Do( o => { Log.Debug( $"Sending currency pair update to {replyTo}. Count: {o.Updates.Count}. IsStateOfTheWorld: {o.IsStateOfTheWorld}. IsStale: {o.IsStale}"); }) .TakeUntil(endPoint.TerminationSignal).Finally(() => Interlocked.Decrement(ref _clients)) .Finally(() => { Log.DebugFormat("Tidying up subscripting.", replyTo); }) .Subscribe(endPoint); }