private async Task OnServerMonitorNotificationAsync(Socket.Messages.Message message) { try { var serverMonitorNotifications = JsonConvert.DeserializeObject <List <Core.Server.ServerNotification> >(message.Data); if (serverMonitorNotifications.Any(smn => smn.Equals(Core.Server.ServerNotificationLevel.DisconnectClient))) { await DisposeSocketAsync().ConfigureAwait(false); } else { var serverMonitorNotification = serverMonitorNotifications.OrderByDescending(smn => smn.Timestamp).First(); var serverMonitor = JsonConvert.DeserializeObject <Core.Server.ServerMonitor>(serverMonitorNotification.Message); ServerMonitorHelper.UpdateServerMonitor(this, serverMonitor); OnNotification(); } } catch (Exception ex) { OnException(ex.Message, ex); } }
private async Task OnStrategyNotificationAsync(Socket.Messages.Message message) { try { var strategyNotifications = JsonConvert.DeserializeObject <List <TradeView.Core.TradeStrategy.StrategyNotification> >(message.Data); foreach (var notification in strategyNotifications) { NotificationsAdd(notification.GetMessage()); if (notification.NotificationLevel.Equals(TradeView.Core.TradeStrategy.NotificationLevel.DisconnectClient)) { await DisconnectSocketAsync().ConfigureAwait(false); } } } catch (Exception ex) { Logger.Log($"OnStrategyNotification {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High); NotificationsAdd(new Message { MessageType = MessageType.Error, Text = $"OnStrategyNotification - {ex.Message}", TextVerbose = ex.ToString() }); } }
private void OnAccountNotification(Socket.Messages.Message message) { try { var accountBalances = AccountViewModel.AccountBalancesViewModel.Account.AccountInfo.Balances.ToList(); } catch (Exception ex) { Logger.Log($"{message.MethodName} {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High); NotificationsAdd(new Message { MessageType = MessageType.Error, Text = $"OnAccountNotification - {ex.Message}", TextVerbose = ex.ToString() }); } }
private async Task OnOrderBookNotificationAsync(Socket.Messages.Message message) { try { var strategyNotifications = JsonConvert.DeserializeObject <List <TradeView.Core.TradeStrategy.StrategyNotification> >(message.Data); var orderedStrategyNotifications = strategyNotifications.OrderBy(n => n.Timestamp).ToList(); await StrategyDisplayViewModel.OrderNotificationsAsync(orderedStrategyNotifications).ConfigureAwait(false); } catch (Exception ex) { Logger.Log($"OnOrderBookNotification {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High); NotificationsAdd(new Message { MessageType = MessageType.Error, Text = $"OnOrderBookNotification - {ex.Message}", TextVerbose = ex.ToString() }); } }
private async Task OnParameterUpdateNotificationAsync(Socket.Messages.Message message) { try { var strategyNotifications = JsonConvert.DeserializeObject <List <TradeView.Core.TradeStrategy.StrategyNotification> >(message.Data); var latestStrategyNotification = strategyNotifications.OrderBy(n => n.Timestamp).Last(); Strategy.Parameters = latestStrategyNotification.Message; } catch (Exception ex) { Logger.Log($"OnParameterUpdateNotificationAsync {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High); NotificationsAdd(new Message { MessageType = MessageType.Error, Text = $"OnParameterUpdateNotificationAsync - {ex.Message}", TextVerbose = ex.ToString() }); } await Task.FromResult <object>(null).ConfigureAwait(false); }
private async Task DisconnectSocketAsync(bool writeNotification = true) { if (socketClient != null) { try { if (socketClient.State.Equals(WebSocketState.Open)) { var clientMessage = new Socket.Messages.Message { SenderConnectionId = strategyAssemblyManager.Id, Data = strategy.Name, MessageType = Socket.Messages.MessageType.UnsubscribeFromChannel }; await socketClient.SendMessageAsync(clientMessage).ConfigureAwait(true); NotificationsAdd(new Message { MessageType = MessageType.Info, Text = $"{strategy.Name} disconnected" }); } await DisposeSocketAsync(writeNotification).ConfigureAwait(true); } catch (Exception ex) { Logger.Log($"DisconnectSocketAsync {ex.Message}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High); if (writeNotification) { ViewModelContext.UiDispatcher.Invoke(() => { NotificationsAdd(new Message { MessageType = MessageType.Error, Text = $"Disconnect - {ex.Message}", TextVerbose = ex.ToString() }); }); } } } }