Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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
                });
            }
        }
Esempio n. 3
0
        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
            });
        }
Esempio n. 4
0
        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
            });
        }
Esempio n. 5
0
        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
            });
        }
Esempio n. 6
0
        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
            });
        }
Esempio n. 7
0
        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
            });
        }
Esempio n. 8
0
        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
            });
        }