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