public static Message GetMessage(this StrategyNotification strategyNotification) { MessageType messageType; switch (strategyNotification.NotificationLevel) { case NotificationLevel.Error: messageType = MessageType.Error; break; case NotificationLevel.Warning: messageType = MessageType.Warn; break; default: messageType = MessageType.Info; break; } return(new Message { MessageType = messageType, Text = strategyNotification.Message, Timestamp = strategyNotification.Timestamp, TextVerbose = strategyNotification.ToString() }); }
public static StrategyNotification GetNotification(this TradeStrategy.Strategy strategy, NotificationLevel notificationLevel, int notificationEvent, string message) { if (strategy == null) { throw new ArgumentNullException(nameof(strategy)); } var strategyNotification = new StrategyNotification { Id = strategy.Id, Name = strategy.Name, Status = strategy.Status, TargetAssembly = strategy.TargetAssembly, TargetType = strategy.TargetType, Parameters = strategy.Parameters, Machine = Environment.MachineName, NotificationEvent = notificationEvent, NotificationLevel = notificationLevel, Message = message }; strategyNotification.StrategySubscriptions.AddRange(strategy.StrategySubscriptions); return(strategyNotification); }
public override void SubscribeTrades(TradeEventArgs tradeEventArgs) { if (Strategy == null) { return; } var strategyNotification = new StrategyNotification { Name = Strategy.Name, NotificationLevel = NotificationLevel.Trade }; string message; try { var previousLastTrade = tradeCache.GetLastTrade(); ITrade[] trades; MovingAverageTrade[] movingAverageTrades; if (previousLastTrade == null) { trades = (from t in tradeEventArgs.Trades orderby t.Time, t.Id select t).ToArray(); movingAverageTrades = tradeCache.AddRange(trades); } else { trades = (from t in tradeEventArgs.Trades where t.Time > previousLastTrade.Time && t.Id > previousLastTrade.Id orderby t.Time, t.Id select t).ToArray(); movingAverageTrades = tradeCache.AddRange(trades); } var lastTrade = tradeCache.GetLastTrade(); if (!suspend) { PlaceOrder(lastTrade); } message = JsonConvert.SerializeObject(movingAverageTrades); } catch (Exception ex) { message = JsonConvert.SerializeObject(ex); } strategyNotification.Message = message; StrategyTradeNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public static Message GetMessage(this StrategyNotification strategyNotification) { if (strategyNotification == null) { throw new ArgumentNullException(nameof(strategyNotification)); } MessageType messageType = strategyNotification.NotificationLevel switch { NotificationLevel.Error => MessageType.Error, NotificationLevel.Warning => MessageType.Warn, _ => MessageType.Info }; return(new Message { MessageType = messageType, Text = strategyNotification.Message, Timestamp = strategyNotification.Timestamp, TextVerbose = strategyNotification.ToString() }); } }