예제 #1
0
        private async Task GetSymbols()
        {
            try
            {
                if (symbolsCache == null)
                {
                    symbolsCache = symbolsCacheFactory.GetSymbolsCache(AccountPreferences.Exchange);
                    symbolsCache.OnSymbolsCacheException += SymbolsCacheException;
                }

                var results = await symbolsCache.GetSymbols(AccountPreferences.Preferences.FavouriteSymbols);

                Symbols = new List <Symbol>(results);

                SetPreferences();
            }
            catch (Exception ex)
            {
                OnException("SymbolsViewModel.GetSymbols", ex);
            }
            finally
            {
                IsLoadingSymbols = false;
            }
        }
예제 #2
0
        public async Task GetSymbols(Strategy arg)
        {
            IsLoadingSymbols = true;

            try
            {
                Strategy = arg;

                if (symbolsCache == null)
                {
                    symbolsCache = symbolsCacheFactory.GetSymbolsCache(Strategy.StrategySubscriptions.First().Exchange);

                    symbolsCache.OnSymbolsCacheException += SymbolsCacheException;
                }

                var strategySymbols = Strategy.StrategySubscriptions.Select(s => s.Symbol);

                var results = await symbolsCache.GetSymbols(strategySymbols);

                Symbols = new List <Symbol>(results.Where(r => strategySymbols.Contains($"{r.ExchangeSymbol}")));

                SymbolsNotification();
            }
            catch (Exception ex)
            {
                OnException($"SymbolsViewModel.GetSymbols {ex.Message}", ex);
            }

            IsLoadingSymbols = false;
        }
예제 #3
0
        public SymbolsViewModel(IWpfExchangeService exchangeService, ISymbolsCache symbolsCache, ILoggerFacade logger)
            : base(exchangeService, logger)
        {
            this.symbolsCache = symbolsCache;

            GetSymbols().FireAndForget();
        }
예제 #4
0
        private async Task GetSymbols()
        {
            try
            {
                if (symbolsCache == null)
                {
                    symbolsCache = symbolsCacheFactory.GetSymbolsCache(AccountPreferences.Exchange);
                    symbolsCache.OnSymbolsCacheException += SymbolsCacheException;
                }

                var results = await symbolsCache.GetSymbols(AccountPreferences.Preferences.FavouriteSymbols).ConfigureAwait(true);

                results.ForEach(Symbols.Add);

                OnLoadedSymbols(Symbols.ToList());

                SetPreferences();
            }
            catch (Exception ex)
            {
                OnException($"{nameof(SymbolsViewModel)} - {ex.Message}", ex);
            }
            finally
            {
                IsLoadingSymbols = false;
            }
        }
예제 #5
0
        public AccountViewModel(IWpfExchangeService exchangeService, ISymbolsCache symbolsCache, ILoggerFacade logger)
            : base(exchangeService, logger)
        {
            accountCancellationTokenSource = new CancellationTokenSource();

            LoginCommand = new ViewModelCommand(Login);

            this.symbolsCache = symbolsCache;
        }
예제 #6
0
        public async Task Login(Account account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            try
            {
                if (string.IsNullOrWhiteSpace(account.AccountInfo.User.ApiKey) ||
                    string.IsNullOrWhiteSpace(account.AccountInfo.User.ApiSecret))
                {
                    return;
                }

                IsLoggingIn = true;

                Account = await ExchangeService.GetAccountInfoAsync(account.AccountInfo.User.Exchange, account.AccountInfo.User, accountCancellationTokenSource.Token).ConfigureAwait(true);

                OnAccountLoggedIn();

                await ExchangeService.SubscribeAccountInfo(Account.AccountInfo.User.Exchange, Account.AccountInfo.User, e => AccountInfoUpdate(e.AccountInfo), SubscribeAccountInfoException, accountCancellationTokenSource.Token).ConfigureAwait(true);

                symbolsCache = symbolsCacheFactory.GetSymbolsCache(Account.AccountInfo.User.Exchange);

                dispatcherTimer          = new DispatcherTimer();
                dispatcherTimer.Tick    += new EventHandler(DispatcherTimerTick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
                dispatcherTimer.Start();

                DispatcherTimerTick(this, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                OnException(ex.Message, ex);
            }
            finally
            {
                IsLoggingIn = false;
            }
        }