public async virtual Task <Strategy> RunAsync(CancellationToken cancellationToken) { if (Strategy == null) { throw new NullReferenceException(typeof(Strategy).Name); } this.CancellationToken = cancellationToken; await TryUpdateStrategyAsync(Strategy.Parameters).ConfigureAwait(false); while (Run) { if (this.CancellationToken.IsCancellationRequested) { Run = false; } else { await Task.Delay(500).ConfigureAwait(false); } } var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = $"Stopping {Strategy.Name}", NotificationLevel = NotificationLevel.DisconnectClient }; StrategyNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); return(Strategy); }
public virtual void SubscribeAccountInfo(AccountInfoEventArgs accountInfoEventArgs) { if (accountInfoEventArgs == null) { throw new ArgumentNullException(nameof(accountInfoEventArgs)); } lock (AccountLock) { AccountInfo = accountInfoEventArgs.AccountInfo.Clone(); PlacingOrder = false; if (Strategy == null) { return; } var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = $"Update {Strategy.Name} performance.", NotificationLevel = NotificationLevel.Account }; StrategyAccountInfoNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); } }
public virtual void SubscribeStatisticsException(Exception exception) { var message = JsonConvert.SerializeObject(exception); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.StatisticsError }; StrategyStatisticsNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public void SubscribeOrderBookException(Exception exception) { var message = JsonConvert.SerializeObject(exception); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.OrderBookError }; StrategyOrderBookNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public virtual void SubscribeStatistics(StatisticsEventArgs statisticsEventArgs) { if (statisticsEventArgs == null) { throw new ArgumentNullException(nameof(statisticsEventArgs)); } var message = JsonConvert.SerializeObject(statisticsEventArgs.Statistics); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.Statistics }; StrategyStatisticsNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public virtual void SubscribeCandlesticks(CandlestickEventArgs candlestickEventArgs) { if (candlestickEventArgs == null) { throw new ArgumentNullException(nameof(candlestickEventArgs)); } var message = JsonConvert.SerializeObject(candlestickEventArgs.Candlesticks); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.Candlesticks }; StrategyCandlesticksNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public void SubscribeOrderBook(OrderBookEventArgs orderBookEventArgs) { if (orderBookEventArgs == null) { throw new ArgumentNullException(nameof(orderBookEventArgs)); } var message = JsonConvert.SerializeObject(orderBookEventArgs.OrderBook); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.OrderBook }; StrategyOrderBookNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
public virtual void SubscribeTrades(TradeEventArgs tradeEventArgs) { if (tradeEventArgs == null) { throw new ArgumentNullException(nameof(tradeEventArgs)); } var message = JsonConvert.SerializeObject(tradeEventArgs.Trades); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.Trade }; StrategyTradeNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }