Пример #1
0
        public async void Start(TradingViewTiker tiker, TikerValues tikerValues, ShellVm vm, int startDelayMs)
        {
            await Task.Delay(startDelayMs);

            _vm                   = vm;
            _tikerValues          = tikerValues;
            _tradingViewExtractor = new TradingViewExtractor(tiker);
            _tradingViewExtractor.CrossRateFetched += TradingViewExtractorCrossRateFetched;

            _tradingViewExtractor.ConnectWebSocketAndRequestSession().Wait();
            _tradingViewExtractor.RequestData().Wait();

            while (true)
            {
                var result = _tradingViewExtractor.ReceiveData().Result;
                if (result)
                {
                    Thread.Sleep(10);
                }
                else
                {
                    Thread.Sleep(100);
                    _tradingViewExtractor = new TradingViewExtractor(tiker);
                    _tradingViewExtractor.CrossRateFetched += TradingViewExtractorCrossRateFetched;
                    _tradingViewExtractor.ConnectWebSocketAndRequestSession().Wait();
                    _tradingViewExtractor.RequestData().Wait();
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
Пример #2
0
        public async void Start(ShellVm vm)
        {
            var extractor = new Banki24Extractor();

            while (true)
            {
                var stock = await extractor.GetStockAsync();

                if (stock != null)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        if (stock.TradingState == BelStockState.TerminatedAlready &&
                            vm.BelStockViewModel.BelStock.TradingState != BelStockState.TerminatedAlready)
                        {
                            vm.ForecastVm.Initialize(stock.GetTomorrow());
                        }
                        vm.BelStockViewModel.BelStock = stock;
                    });
                }

                await Task.Delay(7000);
            }
            // ReSharper disable once FunctionNeverReturns
        }
Пример #3
0
        public ShellViewModel(IniFile iniFile, IMyLog logFile, IWindowManager windowManager, ShellVm shellVm, ChangesViewModel changesViewModel)
        {
            _windowManager    = windowManager;
            _changesViewModel = changesViewModel;
            Model             = shellVm;

            StartNbRbPoller();
            Task.Delay(3000).Wait();
            StartBelStockPoller();
            StartTradingViewPollers();

            StartKomBankPollers(iniFile, logFile);
        }
Пример #4
0
        public async void Start(ShellVm vm)
        {
            while (true)
            {
                if (vm.NbRbViewModel.NbRbVm.Today == null || vm.NbRbViewModel.NbRbVm.Today.Date.Date != DateTime.Today)
                {
                    while (true) // can't step farther till Today is not initialized
                    {
                        var today = await NbRbRatesExtractor.GetNbDayAsync(DateTime.Today);

                        if (today != null)
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                vm.NbRbViewModel.NbRbVm.PreviousTradeDay =
                                    today; // force to (re)read Previous day if Today changed
                                vm.NbRbViewModel.NbRbVm.Today     = today;
                                vm.BelStockViewModel.TodayNbRates = today;
                                vm.ForecastVm.Initialize(today);
                            });
                            break;
                        }

                        await Task.Delay(60000);
                    }
                }

                while (vm.NbRbViewModel.NbRbVm.PreviousTradeDay.Equals(vm.NbRbViewModel.NbRbVm.Today))
                {
                    var previousTradeDay = await NbRbRatesExtractor.GetNbDayAsync(vm.NbRbViewModel.NbRbVm.PreviousTradeDay.Date.AddDays(-1));

                    if (previousTradeDay != null)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            vm.NbRbViewModel.NbRbVm.PreviousTradeDay     = previousTradeDay;
                            vm.BelStockViewModel.PreviousTradeDayNbRates = previousTradeDay;
                        });
                    }
                    else
                    {
                        await Task.Delay(60000);
                    }
                }

                // ReSharper disable once PossibleNullReferenceException
                if ((vm.NbRbViewModel.NbRbVm.Tomorrow == null || vm.NbRbViewModel.NbRbVm.Tomorrow.Date.Date != DateTime.Today.AddDays(1)) &&
                    DateTime.Now.Hour >= 13)
                {
                    var tomorrow = await NbRbRatesExtractor.GetNbDayAsync(DateTime.Today.AddDays(1));

                    if (tomorrow != null)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            vm.NbRbViewModel.NbRbVm.Tomorrow = tomorrow;
                            vm.ForecastVm.Initialize(tomorrow);
                        });
                    }
                }

                await Task.Delay(60000);
            }
            // ReSharper disable once FunctionNeverReturns
        }